Skip to content

Commit cf9918f

Browse files
committed
update comments
1 parent d4d6245 commit cf9918f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

runevm.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func NewRuneVM() *RuneVM {
5858
return vm
5959
}
6060

61+
// Executes the Rune source code from the provided source string. Filepath is used for error reporting.
6162
func (r *RuneVM) Run(source string, filepath string) {
6263
r.filepath = filepath
6364
r.source = source
@@ -79,34 +80,42 @@ func (r *RuneVM) get(name string) interface{} {
7980
return r.env.get(name, nil)
8081
}
8182

83+
// Defines a function in the Rune environment.
8284
func (r *RuneVM) SetFun(name string, value func(...interface{}) interface{}) {
8385
r.set(name, value)
8486
}
8587

88+
// Defines a boolean variable in the Rune environment.
8689
func (r *RuneVM) SetBool(name string, value bool) {
8790
r.set(name, value)
8891
}
8992

93+
// Defines an integer variable in the Rune environment.
9094
func (r *RuneVM) SetInt(name string, value int) {
9195
r.set(name, value)
9296
}
9397

98+
// Defines a float variable in the Rune environment.
9499
func (r *RuneVM) SetFloat(name string, value float64) {
95100
r.set(name, value)
96101
}
97102

103+
// Defines a string variable in the Rune environment.
98104
func (r *RuneVM) SetString(name string, value string) {
99105
r.set(name, value)
100106
}
101107

108+
// Defines an array variable in the Rune environment.
102109
func (r *RuneVM) SetArray(name string, value []interface{}) {
103110
r.set(name, value)
104111
}
105112

113+
// Defines a table (map) variable in the Rune environment.
106114
func (r *RuneVM) SetTable(name string, value map[string]interface{}) {
107115
r.set(name, value)
108116
}
109117

118+
// Retrieves a boolean variable from the Rune environment.
110119
func (r *RuneVM) GetBool(name string) (bool, error) {
111120
value := r.get(name)
112121
if b, ok := value.(bool); ok {
@@ -115,6 +124,7 @@ func (r *RuneVM) GetBool(name string) (bool, error) {
115124
return false, fmt.Errorf("'%s' is not a bool", name)
116125
}
117126

127+
// Retrieves a string variable from the Rune environment.
118128
func (r *RuneVM) GetString(name string) (string, error) {
119129
value := r.get(name)
120130
if s, ok := value.(string); ok {
@@ -123,6 +133,7 @@ func (r *RuneVM) GetString(name string) (string, error) {
123133
return "", fmt.Errorf("'%s' is not a string", name)
124134
}
125135

136+
// GetInt retrieves an integer variable from the Rune environment.
126137
func (r *RuneVM) GetInt(name string) (int, error) {
127138
value := r.get(name)
128139
switch v := value.(type) {
@@ -138,6 +149,7 @@ func (r *RuneVM) GetInt(name string) (int, error) {
138149
return 0, fmt.Errorf("'%s' is not an int", name)
139150
}
140151

152+
// Retrieves a float variable from the Rune environment.
141153
func (r *RuneVM) GetFloat(name string) (float64, error) {
142154
value := r.get(name)
143155
switch v := value.(type) {
@@ -153,6 +165,7 @@ func (r *RuneVM) GetFloat(name string) (float64, error) {
153165
return 0, fmt.Errorf("'%s' is not a float", name)
154166
}
155167

168+
// Retrieves an array variable from the Rune environment.
156169
func (r *RuneVM) GetArray(name string) ([]interface{}, error) {
157170
val := r.get(name)
158171
if arr, ok := val.([]interface{}); ok {
@@ -161,6 +174,7 @@ func (r *RuneVM) GetArray(name string) ([]interface{}, error) {
161174
return nil, fmt.Errorf("variable '%s' is not an array", name)
162175
}
163176

177+
// Retrieves a table (map) variable from the Rune environment.
164178
func (r *RuneVM) GetTable(name string) (map[string]interface{}, error) {
165179
val := r.get(name)
166180
if arr, ok := val.(map[string]interface{}); ok {
@@ -169,6 +183,7 @@ func (r *RuneVM) GetTable(name string) (map[string]interface{}, error) {
169183
return nil, fmt.Errorf("variable '%s' is not a table", name)
170184
}
171185

186+
// Retrieves a function from the Rune environment.
172187
func (r *RuneVM) GetFun(name string) (func(...interface{}) interface{}, error) {
173188
fn, ok := r.get(name).(func(...interface{}) interface{})
174189
if !ok {
@@ -177,6 +192,7 @@ func (r *RuneVM) GetFun(name string) (func(...interface{}) interface{}, error) {
177192
return fn, nil
178193
}
179194

195+
// Retrieves a function from a table (map) in the Rune environment.
180196
func (r *RuneVM) GetTableFun(tableName string, funName string) (map[string]interface{}, func(...interface{}) interface{}, error) {
181197
table, err := r.GetTable(tableName)
182198
if err != nil {

0 commit comments

Comments
 (0)