Skip to content

Commit 25c9791

Browse files
TimVoschaarzilli
authored andcommitted
docs: add documentation to methods
1 parent c0240bb commit 25c9791

File tree

5 files changed

+384
-0
lines changed

5 files changed

+384
-0
lines changed

lua/golua_c_lua51.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,37 @@ func lualLoadFile(s *C.lua_State, filename *C.char) C.int {
124124
}
125125

126126
// lua_equal
127+
/*
128+
* [-0, +0, e]
129+
* Returns 1 if the two values in acceptable indices index1 and index2 are equal, following the semantics of the Lua == operator (that is, may call metamethods). Otherwise returns 0. Also returns 0 if any of the indices is non valid.
130+
*/
127131
func (L *State) Equal(index1, index2 int) bool {
128132
return C.lua_equal(L.s, C.int(index1), C.int(index2)) == 1
129133
}
130134

131135
// lua_getfenv
136+
/*
137+
* [-0, +1, -]
138+
* Pushes onto the stack the environment table of the value at the given index.
139+
*/
132140
func (L *State) GetfEnv(index int) {
133141
C.lua_getfenv(L.s, C.int(index))
134142
}
135143

136144
// lua_lessthan
145+
/*
146+
* [-0, +0, e]
147+
* Returns 1 if the value at acceptable index index1 is smaller than the value at acceptable index index2, following the semantics of the Lua < operator (that is, may call metamethods). Otherwise returns 0. Also returns 0 if any of the indices is non valid.
148+
*/
137149
func (L *State) LessThan(index1, index2 int) bool {
138150
return C.lua_lessthan(L.s, C.int(index1), C.int(index2)) == 1
139151
}
140152

141153
// lua_setfenv
154+
/*
155+
* [-1, +0, -]
156+
* Pops a table from the stack and sets it as the new environment for the value at the given index. If the value at the given index is neither a function nor a thread nor a userdata, lua_setfenv returns 0. Otherwise it returns 1.
157+
*/
142158
func (L *State) SetfEnv(index int) {
143159
C.lua_setfenv(L.s, C.int(index))
144160
}
@@ -148,16 +164,28 @@ func (L *State) ObjLen(index int) uint {
148164
}
149165

150166
// lua_tointeger
167+
/*
168+
* [-0, +0, -]
169+
* Converts the Lua value at the given acceptable index to the signed integral type lua_Integer. The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tointeger returns 0.
170+
*/
151171
func (L *State) ToInteger(index int) int {
152172
return int(C.lua_tointeger(L.s, C.int(index)))
153173
}
154174

155175
// lua_tonumber
176+
/*
177+
* [-0, +0, -]
178+
* Converts the Lua value at the given acceptable index to the C type lua_Number (see lua_Number). The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tonumber returns 0.
179+
*/
156180
func (L *State) ToNumber(index int) float64 {
157181
return float64(C.lua_tonumber(L.s, C.int(index)))
158182
}
159183

160184
// lua_yield
185+
/*
186+
* [-?, +?, -]
187+
* Yields a coroutine.
188+
*/
161189
func (L *State) Yield(nresults int) int {
162190
return int(C.lua_yield(L.s, C.int(nresults)))
163191
}
@@ -170,41 +198,73 @@ func (L *State) pcall(nargs, nresults, errfunc int) int {
170198
func (L *State) GetGlobal(name string) { L.GetField(LUA_GLOBALSINDEX, name) }
171199

172200
// lua_resume
201+
/*
202+
* [-?, +?, -]
203+
* Starts and resumes a coroutine in a given thread.
204+
*/
173205
func (L *State) Resume(narg int) int {
174206
return int(C.lua_resume(L.s, C.int(narg)))
175207
}
176208

177209
// lua_setglobal
210+
/*
211+
* [-1, +0, e]
212+
* Pops a value from the stack and sets it as the new value of global name. It is defined as a macro:
213+
*/
178214
func (L *State) SetGlobal(name string) {
179215
Cname := C.CString(name)
180216
defer C.free(unsafe.Pointer(Cname))
181217
C.lua_setfield(L.s, C.int(LUA_GLOBALSINDEX), Cname)
182218
}
183219

184220
// lua_insert
221+
/*
222+
* [-1, +1, -]
223+
* Moves the top element into the given valid index, shifting up the elements above this index to open space. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
224+
*/
185225
func (L *State) Insert(index int) { C.lua_insert(L.s, C.int(index)) }
186226

187227
// lua_remove
228+
/*
229+
* [-1, +0, -]
230+
* Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
231+
*/
188232
func (L *State) Remove(index int) {
189233
C.lua_remove(L.s, C.int(index))
190234
}
191235

192236
// lua_replace
237+
/*
238+
* [-1, +0, -]
239+
* Moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position).
240+
*/
193241
func (L *State) Replace(index int) {
194242
C.lua_replace(L.s, C.int(index))
195243
}
196244

197245
// lua_rawgeti
246+
/*
247+
* [-0, +1, -]
248+
* Pushes onto the stack the value t[n], where t is the value at the given valid index. The access is raw; that is, it does not invoke metamethods.
249+
*/
198250
func (L *State) RawGeti(index int, n int) {
199251
C.lua_rawgeti(L.s, C.int(index), C.int(n))
200252
}
201253

202254
// lua_rawseti
255+
/*
256+
* [-1, +0, m]
257+
* Does the equivalent of t[n] = v, where t is the value at the given valid index and v is the value at the top of the stack.
258+
*/
203259
func (L *State) RawSeti(index int, n int) {
204260
C.lua_rawseti(L.s, C.int(index), C.int(n))
205261
}
206262

207263
// lua_gc
264+
/*
265+
* [-0, +0, e]
266+
* Controls the garbage collector.
267+
*/
208268
func (L *State) GC(what, data int) int {
209269
return int(C.lua_gc(L.s, C.int(what), C.int(data)))
210270
}

lua/golua_c_lua52.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,28 @@ func (L *State) ObjLen(index int) uint {
150150
}
151151

152152
// lua_tointeger
153+
/*
154+
* [-0, +0, –]
155+
* Equivalent to lua_tointegerx with isnum equal to NULL.
156+
*/
153157
func (L *State) ToInteger(index int) int {
154158
return int(C.lua_tointegerx(L.s, C.int(index), nil))
155159
}
156160

157161
// lua_tonumber
162+
/*
163+
* [-0, +0, –]
164+
* Equivalent to lua_tonumberx with isnum equal to NULL.
165+
*/
158166
func (L *State) ToNumber(index int) float64 {
159167
return float64(C.lua_tonumberx(L.s, C.int(index), nil))
160168
}
161169

162170
// lua_yield
171+
/*
172+
* [-?, +?, –]
173+
* This function is equivalent to lua_yieldk, but it has no continuation (see §4.7). Therefore, when the thread resumes, it returns to the function that called the function calling lua_yield.
174+
*/
163175
func (L *State) Yield(nresults int) int {
164176
return int(C.lua_yieldk(L.s, C.int(nresults), 0, nil))
165177
}
@@ -176,11 +188,19 @@ func (L *State) GetGlobal(name string) {
176188
}
177189

178190
// lua_resume
191+
/*
192+
* [-?, +?, –]
193+
* Starts and resumes a coroutine in a given thread.
194+
*/
179195
func (L *State) Resume(narg int) int {
180196
return int(C.lua_resume(L.s, nil, C.int(narg)))
181197
}
182198

183199
// lua_setglobal
200+
/*
201+
* [-1, +0, e]
202+
* Pops a value from the stack and sets it as the new value of global name.
203+
*/
184204
func (L *State) SetGlobal(name string) {
185205
Cname := C.CString(name)
186206
defer C.free(unsafe.Pointer(Cname))
@@ -203,29 +223,53 @@ func (L *State) OpenCoroutine() {
203223
}
204224

205225
// lua_insert
226+
/*
227+
* [-1, +1, –]
228+
* Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
229+
*/
206230
func (L *State) Insert(index int) { C.lua_insert(L.s, C.int(index)) }
207231

208232
// lua_remove
233+
/*
234+
* [-1, +0, –]
235+
* Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
236+
*/
209237
func (L *State) Remove(index int) {
210238
C.lua_remove(L.s, C.int(index))
211239
}
212240

213241
// lua_replace
242+
/*
243+
* [-1, +0, –]
244+
* Moves the top element into the given valid index without shifting any element (therefore replacing the value at the given index), and then pops the top element.
245+
*/
214246
func (L *State) Replace(index int) {
215247
C.lua_replace(L.s, C.int(index))
216248
}
217249

218250
// lua_rawgeti
251+
/*
252+
* [-0, +1, –]
253+
* Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw; that is, it does not invoke metamethods.
254+
*/
219255
func (L *State) RawGeti(index int, n int) {
220256
C.lua_rawgeti(L.s, C.int(index), C.int(n))
221257
}
222258

223259
// lua_rawseti
260+
/*
261+
* [-1, +0, e]
262+
* Does the equivalent of t[n] = v, where t is the table at the given index and v is the value at the top of the stack.
263+
*/
224264
func (L *State) RawSeti(index int, n int) {
225265
C.lua_rawseti(L.s, C.int(index), C.int(n))
226266
}
227267

228268
// lua_gc
269+
/*
270+
* [-0, +0, e]
271+
* Controls the garbage collector.
272+
*/
229273
func (L *State) GC(what, data int) int {
230274
return int(C.lua_gc(L.s, C.int(what), C.int(data)))
231275
}

lua/golua_c_lua53.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,28 @@ func (L *State) ObjLen(index int) uint {
150150
}
151151

152152
// lua_tointeger
153+
/*
154+
* [-0, +0, –]
155+
* Equivalent to lua_tointegerx with isnum equal to NULL.
156+
*/
153157
func (L *State) ToInteger(index int) int {
154158
return int(C.lua_tointegerx(L.s, C.int(index), nil))
155159
}
156160

157161
// lua_tonumber
162+
/*
163+
* [-0, +0, –]
164+
* Equivalent to lua_tonumberx with isnum equal to NULL.
165+
*/
158166
func (L *State) ToNumber(index int) float64 {
159167
return float64(C.lua_tonumberx(L.s, C.int(index), nil))
160168
}
161169

162170
// lua_yield
171+
/*
172+
* [-?, +?, e]
173+
* This function is equivalent to lua_yieldk, but it has no continuation (see §4.7). Therefore, when the thread resumes, it continues the function that called the function calling lua_yield.
174+
*/
163175
func (L *State) Yield(nresults int) int {
164176
return int(C.lua_yieldk(L.s, C.int(nresults), 0, nil))
165177
}
@@ -176,11 +188,19 @@ func (L *State) GetGlobal(name string) {
176188
}
177189

178190
// lua_resume
191+
/*
192+
* [-?, +?, –]
193+
* Starts and resumes a coroutine in the given thread L.
194+
*/
179195
func (L *State) Resume(narg int) int {
180196
return int(C.lua_resume(L.s, nil, C.int(narg)))
181197
}
182198

183199
// lua_setglobal
200+
/*
201+
* [-1, +0, e]
202+
* Pops a value from the stack and sets it as the new value of global name.
203+
*/
184204
func (L *State) SetGlobal(name string) {
185205
Cname := C.CString(name)
186206
defer C.free(unsafe.Pointer(Cname))
@@ -203,31 +223,55 @@ func (L *State) OpenCoroutine() {
203223
}
204224

205225
// lua_insert
226+
/*
227+
* [-1, +1, –]
228+
* Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
229+
*/
206230
func (L *State) Insert(index int) { C.lua_rotate(L.s, C.int(index), 1) }
207231

208232
// lua_remove
233+
/*
234+
* [-1, +0, –]
235+
* Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
236+
*/
209237
func (L *State) Remove(index int) {
210238
C.lua_rotate(L.s, C.int(index), -1)
211239
C.lua_settop(L.s, C.int(-2))
212240
}
213241

214242
// lua_replace
243+
/*
244+
* [-1, +0, –]
245+
* Moves the top element into the given valid index without shifting any element (therefore replacing the value at that given index), and then pops the top element.
246+
*/
215247
func (L *State) Replace(index int) {
216248
C.lua_copy(L.s, -1, C.int(index))
217249
C.lua_settop(L.s, -2)
218250
}
219251

220252
// lua_rawgeti
253+
/*
254+
* [-0, +1, –]
255+
* Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw, that is, it does not invoke the __index metamethod.
256+
*/
221257
func (L *State) RawGeti(index int, n int) {
222258
C.lua_rawgeti(L.s, C.int(index), C.longlong(n))
223259
}
224260

225261
// lua_rawseti
262+
/*
263+
* [-1, +0, m]
264+
* Does the equivalent of t[i] = v, where t is the table at the given index and v is the value at the top of the stack.
265+
*/
226266
func (L *State) RawSeti(index int, n int) {
227267
C.lua_rawseti(L.s, C.int(index), C.longlong(n))
228268
}
229269

230270
// lua_gc
271+
/*
272+
* [-0, +0, m]
273+
* Controls the garbage collector.
274+
*/
231275
func (L *State) GC(what, data int) int {
232276
return int(C.lua_gc(L.s, C.int(what), C.int(data)))
233277
}

0 commit comments

Comments
 (0)