diff --git a/lua/golua_c_lua51.go b/lua/golua_c_lua51.go index 1b08dff..27b97ef 100644 --- a/lua/golua_c_lua51.go +++ b/lua/golua_c_lua51.go @@ -124,21 +124,37 @@ func lualLoadFile(s *C.lua_State, filename *C.char) C.int { } // lua_equal +/* + * [-0, +0, e] + * 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. + */ func (L *State) Equal(index1, index2 int) bool { return C.lua_equal(L.s, C.int(index1), C.int(index2)) == 1 } // lua_getfenv +/* + * [-0, +1, -] + * Pushes onto the stack the environment table of the value at the given index. + */ func (L *State) GetfEnv(index int) { C.lua_getfenv(L.s, C.int(index)) } // lua_lessthan +/* + * [-0, +0, e] + * 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. + */ func (L *State) LessThan(index1, index2 int) bool { return C.lua_lessthan(L.s, C.int(index1), C.int(index2)) == 1 } // lua_setfenv +/* + * [-1, +0, -] + * 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. + */ func (L *State) SetfEnv(index int) { C.lua_setfenv(L.s, C.int(index)) } @@ -148,16 +164,28 @@ func (L *State) ObjLen(index int) uint { } // lua_tointeger +/* + * [-0, +0, -] + * 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. + */ func (L *State) ToInteger(index int) int { return int(C.lua_tointeger(L.s, C.int(index))) } // lua_tonumber +/* + * [-0, +0, -] + * 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. + */ func (L *State) ToNumber(index int) float64 { return float64(C.lua_tonumber(L.s, C.int(index))) } // lua_yield +/* + * [-?, +?, -] + * Yields a coroutine. + */ func (L *State) Yield(nresults int) int { return int(C.lua_yield(L.s, C.int(nresults))) } @@ -170,11 +198,19 @@ func (L *State) pcall(nargs, nresults, errfunc int) int { func (L *State) GetGlobal(name string) { L.GetField(LUA_GLOBALSINDEX, name) } // lua_resume +/* + * [-?, +?, -] + * Starts and resumes a coroutine in a given thread. + */ func (L *State) Resume(narg int) int { return int(C.lua_resume(L.s, C.int(narg))) } // lua_setglobal +/* + * [-1, +0, e] + * Pops a value from the stack and sets it as the new value of global name. It is defined as a macro: + */ func (L *State) SetGlobal(name string) { Cname := C.CString(name) defer C.free(unsafe.Pointer(Cname)) @@ -182,29 +218,53 @@ func (L *State) SetGlobal(name string) { } // lua_insert +/* + * [-1, +1, -] + * 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. + */ func (L *State) Insert(index int) { C.lua_insert(L.s, C.int(index)) } // lua_remove +/* + * [-1, +0, -] + * 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. + */ func (L *State) Remove(index int) { C.lua_remove(L.s, C.int(index)) } // lua_replace +/* + * [-1, +0, -] + * Moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position). + */ func (L *State) Replace(index int) { C.lua_replace(L.s, C.int(index)) } // lua_rawgeti +/* + * [-0, +1, -] + * 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. + */ func (L *State) RawGeti(index int, n int) { C.lua_rawgeti(L.s, C.int(index), C.int(n)) } // lua_rawseti +/* + * [-1, +0, m] + * 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. + */ func (L *State) RawSeti(index int, n int) { C.lua_rawseti(L.s, C.int(index), C.int(n)) } // lua_gc +/* + * [-0, +0, e] + * Controls the garbage collector. + */ func (L *State) GC(what, data int) int { return int(C.lua_gc(L.s, C.int(what), C.int(data))) } diff --git a/lua/golua_c_lua52.go b/lua/golua_c_lua52.go index ec891f8..17b93b2 100644 --- a/lua/golua_c_lua52.go +++ b/lua/golua_c_lua52.go @@ -150,16 +150,28 @@ func (L *State) ObjLen(index int) uint { } // lua_tointeger +/* + * [-0, +0, –] + * Equivalent to lua_tointegerx with isnum equal to NULL. + */ func (L *State) ToInteger(index int) int { return int(C.lua_tointegerx(L.s, C.int(index), nil)) } // lua_tonumber +/* + * [-0, +0, –] + * Equivalent to lua_tonumberx with isnum equal to NULL. + */ func (L *State) ToNumber(index int) float64 { return float64(C.lua_tonumberx(L.s, C.int(index), nil)) } // lua_yield +/* + * [-?, +?, –] + * 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. + */ func (L *State) Yield(nresults int) int { return int(C.lua_yieldk(L.s, C.int(nresults), 0, nil)) } @@ -176,11 +188,19 @@ func (L *State) GetGlobal(name string) { } // lua_resume +/* + * [-?, +?, –] + * Starts and resumes a coroutine in a given thread. + */ func (L *State) Resume(narg int) int { return int(C.lua_resume(L.s, nil, C.int(narg))) } // lua_setglobal +/* + * [-1, +0, e] + * Pops a value from the stack and sets it as the new value of global name. + */ func (L *State) SetGlobal(name string) { Cname := C.CString(name) defer C.free(unsafe.Pointer(Cname)) @@ -203,29 +223,53 @@ func (L *State) OpenCoroutine() { } // lua_insert +/* + * [-1, +1, –] + * 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. + */ func (L *State) Insert(index int) { C.lua_insert(L.s, C.int(index)) } // lua_remove +/* + * [-1, +0, –] + * 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. + */ func (L *State) Remove(index int) { C.lua_remove(L.s, C.int(index)) } // lua_replace +/* + * [-1, +0, –] + * 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. + */ func (L *State) Replace(index int) { C.lua_replace(L.s, C.int(index)) } // lua_rawgeti +/* + * [-0, +1, –] + * 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. + */ func (L *State) RawGeti(index int, n int) { C.lua_rawgeti(L.s, C.int(index), C.int(n)) } // lua_rawseti +/* + * [-1, +0, e] + * 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. + */ func (L *State) RawSeti(index int, n int) { C.lua_rawseti(L.s, C.int(index), C.int(n)) } // lua_gc +/* + * [-0, +0, e] + * Controls the garbage collector. + */ func (L *State) GC(what, data int) int { return int(C.lua_gc(L.s, C.int(what), C.int(data))) } diff --git a/lua/golua_c_lua53.go b/lua/golua_c_lua53.go index 5a11aec..993f97d 100644 --- a/lua/golua_c_lua53.go +++ b/lua/golua_c_lua53.go @@ -150,16 +150,28 @@ func (L *State) ObjLen(index int) uint { } // lua_tointeger +/* + * [-0, +0, –] + * Equivalent to lua_tointegerx with isnum equal to NULL. + */ func (L *State) ToInteger(index int) int { return int(C.lua_tointegerx(L.s, C.int(index), nil)) } // lua_tonumber +/* + * [-0, +0, –] + * Equivalent to lua_tonumberx with isnum equal to NULL. + */ func (L *State) ToNumber(index int) float64 { return float64(C.lua_tonumberx(L.s, C.int(index), nil)) } // lua_yield +/* + * [-?, +?, e] + * 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. + */ func (L *State) Yield(nresults int) int { return int(C.lua_yieldk(L.s, C.int(nresults), 0, nil)) } @@ -176,11 +188,19 @@ func (L *State) GetGlobal(name string) { } // lua_resume +/* + * [-?, +?, –] + * Starts and resumes a coroutine in the given thread L. + */ func (L *State) Resume(narg int) int { return int(C.lua_resume(L.s, nil, C.int(narg))) } // lua_setglobal +/* + * [-1, +0, e] + * Pops a value from the stack and sets it as the new value of global name. + */ func (L *State) SetGlobal(name string) { Cname := C.CString(name) defer C.free(unsafe.Pointer(Cname)) @@ -203,31 +223,55 @@ func (L *State) OpenCoroutine() { } // lua_insert +/* + * [-1, +1, –] + * 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. + */ func (L *State) Insert(index int) { C.lua_rotate(L.s, C.int(index), 1) } // lua_remove +/* + * [-1, +0, –] + * 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. + */ func (L *State) Remove(index int) { C.lua_rotate(L.s, C.int(index), -1) C.lua_settop(L.s, C.int(-2)) } // lua_replace +/* + * [-1, +0, –] + * 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. + */ func (L *State) Replace(index int) { C.lua_copy(L.s, -1, C.int(index)) C.lua_settop(L.s, -2) } // lua_rawgeti +/* + * [-0, +1, –] + * 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. + */ func (L *State) RawGeti(index int, n int) { C.lua_rawgeti(L.s, C.int(index), C.longlong(n)) } // lua_rawseti +/* + * [-1, +0, m] + * 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. + */ func (L *State) RawSeti(index int, n int) { C.lua_rawseti(L.s, C.int(index), C.longlong(n)) } // lua_gc +/* + * [-0, +0, m] + * Controls the garbage collector. + */ func (L *State) GC(what, data int) int { return int(C.lua_gc(L.s, C.int(what), C.int(data))) } diff --git a/lua/golua_c_lua54.go b/lua/golua_c_lua54.go index e27e4df..10f4fec 100644 --- a/lua/golua_c_lua54.go +++ b/lua/golua_c_lua54.go @@ -152,16 +152,28 @@ func (L *State) ObjLen(index int) uint { } // lua_tointeger +/* + * [-0, +0, –] + * Equivalent to lua_tointegerx with isnum equal to NULL. + */ func (L *State) ToInteger(index int) int { return int(C.lua_tointegerx(L.s, C.int(index), nil)) } // lua_tonumber +/* + * [-0, +0, –] + * Equivalent to lua_tonumberx with isnum equal to NULL. + */ func (L *State) ToNumber(index int) float64 { return float64(C.lua_tonumberx(L.s, C.int(index), nil)) } // lua_yield +/* + * [-?, +?, v] + * This function is equivalent to lua_yieldk, but it has no continuation (see §4.5). Therefore, when the thread resumes, it continues the function that called the function calling lua_yield. To avoid surprises, this function should be called only in a tail call. + */ func (L *State) Yield(nresults int) int { return int(C.lua_yieldk(L.s, C.int(nresults), 0, nil)) } @@ -178,11 +190,19 @@ func (L *State) GetGlobal(name string) { } // lua_resume +/* + * [-?, +?, –] + * Starts and resumes a coroutine in the given thread L. + */ func (L *State) Resume(narg int) int { return int(C.lua_resume(L.s, nil, C.int(narg), nil)) } // lua_setglobal +/* + * [-1, +0, e] + * Pops a value from the stack and sets it as the new value of global name. + */ func (L *State) SetGlobal(name string) { Cname := C.CString(name) defer C.free(unsafe.Pointer(Cname)) @@ -200,31 +220,55 @@ func (L *State) OpenCoroutine() { } // lua_insert +/* + * [-1, +1, –] + * 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. + */ func (L *State) Insert(index int) { C.lua_rotate(L.s, C.int(index), 1) } // lua_remove +/* + * [-1, +0, –] + * 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. + */ func (L *State) Remove(index int) { C.lua_rotate(L.s, C.int(index), -1) C.lua_settop(L.s, C.int(-2)) } // lua_replace +/* + * [-1, +0, –] + * 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. + */ func (L *State) Replace(index int) { C.lua_copy(L.s, -1, C.int(index)) C.lua_settop(L.s, -2) } // lua_rawgeti +/* + * [-0, +1, –] + * 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 use the __index metavalue. + */ func (L *State) RawGeti(index int, n int) { C.lua_rawgeti(L.s, C.int(index), C.longlong(n)) } // lua_rawseti +/* + * [-1, +0, m] + * Does the equivalent of t[i] = v, where t is the table at the given index and v is the value on the top of the stack. + */ func (L *State) RawSeti(index int, n int) { C.lua_rawseti(L.s, C.int(index), C.longlong(n)) } // lua_gc +/* + * [-0, +0, –] + * Controls the garbage collector. + */ func (L *State) GC(what, data int) int { return int(C.lua_gc_compat(L.s, C.int(what), C.int(data))) } diff --git a/lua/lua.go b/lua/lua.go index 9b479bd..dc273be 100644 --- a/lua/lua.go +++ b/lua/lua.go @@ -162,11 +162,19 @@ func (L *State) UpvalueIndex(n int) int { } // lua_setupvalue +/* + * [-(0|1), +0, -] + * Sets the value of a closure's upvalue. It assigns the value at the top of the stack to the upvalue and returns its name. It also pops the value from the stack. Parameters funcindex and n are as in the lua_getupvalue (see lua_getupvalue). + */ func (L *State) SetUpvalue(funcindex, n int) bool { return C.lua_setupvalue(L.s, C.int(funcindex), C.int(n)) != nil } // lua_getupvalue +/* + * [-0, +(0|1), -] + * Gets information about a closure's upvalue. (For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure.) lua_getupvalue gets the index n of an upvalue, pushes the upvalue's value onto the stack, and returns its name. funcindex points to the closure in the stack. (Upvalues have no particular order, as they are active through the whole function. So, they are numbered in an arbitrary order.) + */ func (L *State) GetUpvalue(funcindex, n int) { C.lua_getupvalue(L.s, C.int(funcindex), C.int(n)) } @@ -265,6 +273,10 @@ func (L *State) callEx(nargs, nresults int, catch bool) (err error) { } // lua_call +/* + * [-(nargs + 1), +nresults, e] + * Calls a function. + */ func (L *State) Call(nargs, nresults int) (err error) { return L.callEx(nargs, nresults, true) } @@ -275,27 +287,47 @@ func (L *State) MustCall(nargs, nresults int) { } // lua_checkstack +/* + * [-0, +0, m] + * Ensures that there are at least extra free stack slots in the stack. It returns false if it cannot grow the stack to that size. This function never shrinks the stack; if the stack is already larger than the new size, it is left unchanged. + */ func (L *State) CheckStack(extra int) bool { return C.lua_checkstack(L.s, C.int(extra)) != 0 } // lua_close +/* + * [-0, +0, -] + * Destroys all objects in the given Lua state (calling the corresponding garbage-collection metamethods, if any) and frees all dynamic memory used by this state. On several platforms, you may not need to call this function, because all resources are naturally released when the host program ends. On the other hand, long-running programs, such as a daemon or a web server, might need to release states as soon as they are not needed, to avoid growing too large. + */ func (L *State) Close() { C.lua_close(L.s) unregisterGoState(L) } // lua_concat +/* + * [-n, +1, e] + * Concatenates the n values at the top of the stack, pops them, and leaves the result at the top. If n is 1, the result is the single value on the stack (that is, the function does nothing); if n is 0, the result is the empty string. Concatenation is performed following the usual semantics of Lua (see §2.5.4). + */ func (L *State) Concat(n int) { C.lua_concat(L.s, C.int(n)) } // lua_createtable +/* + * [-0, +1, m] + * Creates a new empty table and pushes it onto the stack. The new table has space pre-allocated for narr array elements and nrec non-array elements. This pre-allocation is useful when you know exactly how many elements the table will have. Otherwise you can use the function lua_newtable. + */ func (L *State) CreateTable(narr int, nrec int) { C.lua_createtable(L.s, C.int(narr), C.int(nrec)) } // lua_getfield +/* + * [-0, +1, e] + * Pushes onto the stack the value t[k], where t is the value at the given valid index. As in Lua, this function may trigger a metamethod for the "index" event (see §2.8). + */ func (L *State) GetField(index int, k string) { Ck := C.CString(k) defer C.free(unsafe.Pointer(Ck)) @@ -303,14 +335,26 @@ func (L *State) GetField(index int, k string) { } // lua_getmetatable +/* + * [-0, +(0|1), -] + * Pushes onto the stack the metatable of the value at the given acceptable index. If the index is not valid, or if the value does not have a metatable, the function returns 0 and pushes nothing on the stack. + */ func (L *State) GetMetaTable(index int) bool { return C.lua_getmetatable(L.s, C.int(index)) != 0 } // lua_gettable +/* + * [-1, +1, e] + * Pushes onto the stack the value t[k], where t is the value at the given valid index and k is the value at the top of the stack. + */ func (L *State) GetTable(index int) { C.lua_gettable(L.s, C.int(index)) } // lua_gettop +/* + * [-0, +0, -] + * Returns the index of the top element in the stack. Because indices start at 1, this result is equal to the number of elements in the stack (and so 0 means an empty stack). + */ func (L *State) GetTop() int { return int(C.lua_gettop(L.s)) } // Returns true if lua_type == LUA_TBOOLEAN @@ -339,31 +383,63 @@ func (L *State) IsLightUserdata(index int) bool { } // lua_isnil +/* + * [-0, +0, -] + * Returns 1 if the value at the given acceptable index is nil, and 0 otherwise. + */ func (L *State) IsNil(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TNIL } // lua_isnone +/* + * [-0, +0, -] + * Returns 1 if the given acceptable index is not valid (that is, it refers to an element outside the current stack), and 0 otherwise. + */ func (L *State) IsNone(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TNONE } // lua_isnoneornil +/* + * [-0, +0, -] + * Returns 1 if the given acceptable index is not valid (that is, it refers to an element outside the current stack) or if the value at this index is nil, and 0 otherwise. + */ func (L *State) IsNoneOrNil(index int) bool { return int(C.lua_type(L.s, C.int(index))) <= 0 } // lua_isnumber +/* + * [-0, +0, -] + * Returns 1 if the value at the given acceptable index is a number or a string convertible to a number, and 0 otherwise. + */ func (L *State) IsNumber(index int) bool { return C.lua_isnumber(L.s, C.int(index)) == 1 } // lua_isstring +/* + * [-0, +0, -] + * Returns 1 if the value at the given acceptable index is a string or a number (which is always convertible to a string), and 0 otherwise. + */ func (L *State) IsString(index int) bool { return C.lua_isstring(L.s, C.int(index)) == 1 } // lua_istable +/* + * [-0, +0, -] + * Returns 1 if the value at the given acceptable index is a table, and 0 otherwise. + */ func (L *State) IsTable(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TTABLE } // lua_isthread +/* + * [-0, +0, -] + * Returns 1 if the value at the given acceptable index is a thread, and 0 otherwise. + */ func (L *State) IsThread(index int) bool { return LuaValType(C.lua_type(L.s, C.int(index))) == LUA_TTHREAD } // lua_isuserdata +/* + * [-0, +0, -] + * Returns 1 if the value at the given acceptable index is a userdata (either full or light), and 0 otherwise. + */ func (L *State) IsUserdata(index int) bool { return C.lua_isuserdata(L.s, C.int(index)) == 1 } // Creates a new lua interpreter state with the given allocation function @@ -375,11 +451,19 @@ func NewStateAlloc(f Alloc) *State { } // lua_newtable +/* + * [-0, +1, m] + * Creates a new empty table and pushes it onto the stack. It is equivalent to lua_createtable(L, 0, 0). + */ func (L *State) NewTable() { C.lua_createtable(L.s, 0, 0) } // lua_newthread +/* + * [-0, +1, m] + * Creates a new thread, pushes it on the stack, and returns a pointer to a lua_State that represents this new thread. The new state returned by this function shares with the original state all global objects (such as tables), but has an independent execution stack. + */ func (L *State) NewThread() *State { // TODO: call newState with result from C.lua_newthread and return it // TODO: should have same lists as parent @@ -389,12 +473,24 @@ func (L *State) NewThread() *State { } // lua_next +/* + * [-1, +(2|0), e] + * Pops a key from the stack, and pushes a key-value pair from the table at the given index (the "next" pair after the given key). If there are no more elements in the table, then lua_next returns 0 (and pushes nothing). + */ func (L *State) Next(index int) int { return int(C.lua_next(L.s, C.int(index))) } // lua_objlen +/* + * [-0, +0, -] + * Returns the "length" of the value at the given acceptable index: for strings, this is the string length; for tables, this is the result of the length operator ('#'); for userdata, this is the size of the block of memory allocated for the userdata; for other values, it is 0. + */ // lua_pop +/* + * [-n, +0, -] + * Pops n elements from the stack. + */ func (L *State) Pop(n int) { // Why is this implemented this way? I don't get it... // C.lua_pop(L.s, C.int(n)); @@ -402,6 +498,10 @@ func (L *State) Pop(n int) { } // lua_pushboolean +/* + * [-0, +1, -] + * Pushes a boolean value with value b onto the stack. + */ func (L *State) PushBoolean(b bool) { var bint int if b { @@ -413,6 +513,10 @@ func (L *State) PushBoolean(b bool) { } // lua_pushstring +/* + * [-0, +1, m] + * Pushes the zero-terminated string pointed to by s onto the stack. Lua makes (or reuses) an internal copy of the given string, so the memory at s can be freed or reused immediately after the function returns. The string cannot contain embedded zeros; it is assumed to end at the first zero. + */ func (L *State) PushString(str string) { Cstr := C.CString(str) defer C.free(unsafe.Pointer(Cstr)) @@ -424,41 +528,73 @@ func (L *State) PushBytes(b []byte) { } // lua_pushinteger +/* + * [-0, +1, -] + * Pushes a number with value n onto the stack. + */ func (L *State) PushInteger(n int64) { C.lua_pushinteger(L.s, C.lua_Integer(n)) } // lua_pushnil +/* + * [-0, +1, -] + * Pushes a nil value onto the stack. + */ func (L *State) PushNil() { C.lua_pushnil(L.s) } // lua_pushnumber +/* + * [-0, +1, -] + * Pushes a number with value n onto the stack. + */ func (L *State) PushNumber(n float64) { C.lua_pushnumber(L.s, C.lua_Number(n)) } // lua_pushthread +/* + * [-0, +1, -] + * Pushes the thread represented by L onto the stack. Returns 1 if this thread is the main thread of its state. + */ func (L *State) PushThread() (isMain bool) { return C.lua_pushthread(L.s) != 0 } // lua_pushvalue +/* + * [-0, +1, -] + * Pushes a copy of the element at the given valid index onto the stack. + */ func (L *State) PushValue(index int) { C.lua_pushvalue(L.s, C.int(index)) } // lua_rawequal +/* + * [-0, +0, -] + * Returns 1 if the two values in acceptable indices index1 and index2 are primitively equal (that is, without calling metamethods). Otherwise returns 0. Also returns 0 if any of the indices are non valid. + */ func (L *State) RawEqual(index1 int, index2 int) bool { return C.lua_rawequal(L.s, C.int(index1), C.int(index2)) != 0 } // lua_rawget +/* + * [-1, +1, -] + * Similar to lua_gettable, but does a raw access (i.e., without metamethods). + */ func (L *State) RawGet(index int) { C.lua_rawget(L.s, C.int(index)) } // lua_rawset +/* + * [-2, +0, m] + * Similar to lua_settable, but does a raw assignment (i.e., without metamethods). + */ func (L *State) RawSet(index int) { C.lua_rawset(L.s, C.int(index)) } @@ -493,12 +629,20 @@ func (L *State) RegisterLibrary(name string, funcs map[string]LuaGoFunction) { } // lua_setallocf +/* + * [-0, +0, -] + * Changes the allocator function of a given state to f with user data ud. + */ func (L *State) SetAllocf(f Alloc) { L.allocfn = &f C.clua_setallocf(L.s, unsafe.Pointer(L.allocfn)) } // lua_setfield +/* + * [-1, +0, e] + * Does the equivalent to t[k] = v, where t is the value at the given valid index and v is the value at the top of the stack. + */ func (L *State) SetField(index int, k string) { Ck := C.CString(k) defer C.free(unsafe.Pointer(Ck)) @@ -506,26 +650,46 @@ func (L *State) SetField(index int, k string) { } // lua_setmetatable +/* + * [-1, +0, -] + * Pops a table from the stack and sets it as the new metatable for the value at the given acceptable index. + */ func (L *State) SetMetaTable(index int) { C.lua_setmetatable(L.s, C.int(index)) } // lua_settable +/* + * [-2, +0, e] + * Does the equivalent to t[k] = v, where t is the value at the given valid index, v is the value at the top of the stack, and k is the value just below the top. + */ func (L *State) SetTable(index int) { C.lua_settable(L.s, C.int(index)) } // lua_settop +/* + * [-?, +?, -] + * Accepts any acceptable index, or 0, and sets the stack top to this index. If the new top is larger than the old one, then the new elements are filled with nil. If index is 0, then all stack elements are removed. + */ func (L *State) SetTop(index int) { C.lua_settop(L.s, C.int(index)) } // lua_status +/* + * [-0, +0, -] + * Returns the status of the thread L. + */ func (L *State) Status() int { return int(C.lua_status(L.s)) } // lua_toboolean +/* + * [-0, +0, -] + * Converts the Lua value at the given acceptable index to a C boolean value (0 or 1). Like all tests in Lua, lua_toboolean returns 1 for any Lua value different from false and nil; otherwise it returns 0. It also returns 0 when called with a non-valid index. (If you want to accept only actual boolean values, use lua_isboolean to test the value's type.) + */ func (L *State) ToBoolean(index int) bool { return C.lua_toboolean(L.s, C.int(index)) != 0 } @@ -555,6 +719,10 @@ func (L *State) ToGoStruct(index int) (f interface{}) { } // lua_tostring +/* + * [-0, +0, m] + * Equivalent to lua_tolstring with len equal to NULL. + */ func (L *State) ToString(index int) string { var size C.size_t r := C.lua_tolstring(L.s, C.int(index), &size) @@ -568,32 +736,56 @@ func (L *State) ToBytes(index int) []byte { } // lua_topointer +/* + * [-0, +0, -] + * Converts the value at the given acceptable index to a generic C pointer (void*). The value can be a userdata, a table, a thread, or a function; otherwise, lua_topointer returns NULL. Different objects will give different pointers. There is no way to convert the pointer back to its original value. + */ func (L *State) ToPointer(index int) uintptr { return uintptr(C.lua_topointer(L.s, C.int(index))) } // lua_tothread +/* + * [-0, +0, -] + * Converts the value at the given acceptable index to a Lua thread (represented as lua_State*). This value must be a thread; otherwise, the function returns NULL. + */ func (L *State) ToThread(index int) *State { // TODO: find a way to link lua_State* to existing *State, return that return &State{} } // lua_touserdata +/* + * [-0, +0, -] + * If the value at the given acceptable index is a full userdata, returns its block address. If the value is a light userdata, returns its pointer. Otherwise, returns NULL. + */ func (L *State) ToUserdata(index int) unsafe.Pointer { return unsafe.Pointer(C.lua_touserdata(L.s, C.int(index))) } // lua_type +/* + * [-0, +0, -] + * Returns the type of the value in the given acceptable index, or LUA_TNONE for a non-valid index (that is, an index to an "empty" stack position). The types returned by lua_type are coded by the following constants defined in lua.h: LUA_TNIL, LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, and LUA_TLIGHTUSERDATA. + */ func (L *State) Type(index int) LuaValType { return LuaValType(C.lua_type(L.s, C.int(index))) } // lua_typename +/* + * [-0, +0, -] + * Returns the name of the type encoded by the value tp, which must be one the values returned by lua_type. + */ func (L *State) Typename(tp int) string { return C.GoString(C.lua_typename(L.s, C.int(tp))) } // lua_xmove +/* + * [-?, +?, -] + * Exchange values between different threads of the same global state. + */ func XMove(from *State, to *State, n int) { C.lua_xmove(from.s, to.s, C.int(n)) }