Documentation
¶
Overview ¶
This package provides access to the excellent lua language interpreter from go code.
Access to most of the functions in lua.h and lauxlib.h is provided as well as additional convenience functions to publish Go objects and functions to lua code.
The documentation of this package is no substitute for the official lua documentation and in many instances methods are described only with the name of their C equivalent
Index ¶
- Constants
- func XMove(from *State, to *State, n int)
- type Alloc
- type HookFunction
- type LuaError
- type LuaGoFunction
- type LuaStackEntry
- type LuaValType
- type State
- func (L *State) ArgError(narg int, extramsg string) int
- func (L *State) Argcheck(cond bool, narg int, extramsg string)
- func (L *State) AtPanic(panicf LuaGoFunction) (oldpanicf LuaGoFunction)
- func (L *State) Call(nargs, nresults int) (err error)
- func (L *State) CallMeta(obj int, e string) int
- func (L *State) CheckAny(narg int)
- func (L *State) CheckInteger(narg int) int
- func (L *State) CheckNumber(narg int) float64
- func (L *State) CheckOption(narg int, def string, lst []string) int
- func (L *State) CheckStack(extra int) bool
- func (L *State) CheckString(narg int) string
- func (L *State) CheckType(narg int, t LuaValType)
- func (L *State) CheckUdata(narg int, tname string) unsafe.Pointer
- func (L *State) Close()
- func (L *State) Concat(n int)
- func (L *State) Context() context.Context
- func (L *State) CreateTable(narr int, nrec int)
- func (L *State) DoFile(filename string) error
- func (L *State) DoString(str string) error
- func (L *State) Dump() int
- func (L *State) Equal(index1, index2 int) bool
- func (L *State) GC(what, data int) int
- func (L *State) GSub(s string, p string, r string) string
- func (L *State) GetField(index int, k string)
- func (L *State) GetGlobal(name string)
- func (L *State) GetMetaField(obj int, e string) bool
- func (L *State) GetMetaTable(index int) bool
- func (L *State) GetState() *C.lua_State
- func (L *State) GetTable(index int)
- func (L *State) GetTop() int
- func (L *State) GetUpvalue(funcindex, n int)
- func (L *State) GetfEnv(index int)
- func (L *State) Insert(index int)
- func (L *State) IsBoolean(index int) bool
- func (L *State) IsFunction(index int) bool
- func (L *State) IsGoFunction(index int) bool
- func (L *State) IsGoStruct(index int) bool
- func (L *State) IsLightUserdata(index int) bool
- func (L *State) IsNil(index int) bool
- func (L *State) IsNone(index int) bool
- func (L *State) IsNoneOrNil(index int) bool
- func (L *State) IsNumber(index int) bool
- func (L *State) IsString(index int) bool
- func (L *State) IsTable(index int) bool
- func (L *State) IsThread(index int) bool
- func (L *State) IsUserdata(index int) bool
- func (L *State) LGetMetaTable(tname string)
- func (L *State) LTypename(index int) string
- func (L *State) LessThan(index1, index2 int) bool
- func (L *State) Load(bs []byte, name string) int
- func (L *State) LoadFile(filename string) int
- func (L *State) LoadString(s string) int
- func (L *State) MustCall(nargs, nresults int)
- func (L *State) MustDoString(str string)
- func (L *State) NewError(msg string) *LuaError
- func (L *State) NewMetaTable(tname string) bool
- func (L *State) NewTable()
- func (L *State) NewThread() *State
- func (L *State) NewUserdata(size uintptr) unsafe.Pointer
- func (L *State) Next(index int) int
- func (L *State) ObjLen(index int) uint
- func (L *State) OpenBase()
- func (L *State) OpenIO()
- func (L *State) OpenLibs()
- func (L *State) OpenMath()
- func (L *State) OpenOS()
- func (L *State) OpenPackage()
- func (L *State) OpenString()
- func (L *State) OpenTable()
- func (L *State) OptInteger(narg int, d int) int
- func (L *State) OptNumber(narg int, d float64) float64
- func (L *State) OptString(narg int, d string) string
- func (L *State) Pop(n int)
- func (L *State) PushBoolean(b bool)
- func (L *State) PushBytes(b []byte)
- func (L *State) PushGoClosure(f LuaGoFunction)
- func (L *State) PushGoClosureWithUpvalues(f LuaGoFunction, nup uint)
- func (L *State) PushGoFunction(f LuaGoFunction)
- func (L *State) PushGoStruct(iface interface{})
- func (L *State) PushInteger(n int64)
- func (L *State) PushLightUserdata(ud *interface{})
- func (L *State) PushNil()
- func (L *State) PushNumber(n float64)
- func (L *State) PushString(str string)
- func (L *State) PushThread() (isMain bool)
- func (L *State) PushValue(index int)
- func (L *State) RaiseError(msg string)
- func (L *State) RawEqual(index1 int, index2 int) bool
- func (L *State) RawGet(index int)
- func (L *State) RawGeti(index int, n int)
- func (L *State) RawSet(index int)
- func (L *State) RawSeti(index int, n int)
- func (L *State) Ref(t int) int
- func (L *State) Register(name string, f LuaGoFunction)
- func (L *State) RegisterLibrary(name string, funcs map[string]LuaGoFunction)
- func (L *State) Remove(index int)
- func (L *State) Replace(index int)
- func (L *State) Resume(narg int) int
- func (L *State) SetAllocf(f Alloc)
- func (L *State) SetExecutionLimit(instrNumber int)
- func (L *State) SetField(index int, k string)
- func (L *State) SetGlobal(name string)
- func (L *State) SetHook(f HookFunction, instrNumber int)
- func (L *State) SetMetaMethod(methodName string, f LuaGoFunction)
- func (L *State) SetMetaTable(index int)
- func (L *State) SetTable(index int)
- func (L *State) SetTop(index int)
- func (L *State) SetUpvalue(funcindex, n int) bool
- func (L *State) SetfEnv(index int)
- func (L *State) StackTrace() []LuaStackEntry
- func (L *State) Status() int
- func (L *State) ToBoolean(index int) bool
- func (L *State) ToBytes(index int) []byte
- func (L *State) ToGoFunction(index int) (f LuaGoFunction)
- func (L *State) ToGoStruct(index int) (f interface{})
- func (L *State) ToInteger(index int) int
- func (L *State) ToNumber(index int) float64
- func (L *State) ToPointer(index int) uintptr
- func (L *State) ToString(index int) string
- func (L *State) ToThread(index int) *State
- func (L *State) ToUserdata(index int) unsafe.Pointer
- func (L *State) Type(index int) LuaValType
- func (L *State) Typename(tp int) string
- func (L *State) Unref(t int, ref int)
- func (L *State) UpvalueIndex(n int) int
- func (L *State) Where(lvl int)
- func (L *State) Yield(nresults int) int
- Bugs
Constants ¶
const ( LUA_TNIL = LuaValType(C.LUA_TNIL) LUA_TNUMBER = LuaValType(C.LUA_TNUMBER) LUA_TBOOLEAN = LuaValType(C.LUA_TBOOLEAN) LUA_TSTRING = LuaValType(C.LUA_TSTRING) LUA_TTABLE = LuaValType(C.LUA_TTABLE) LUA_TFUNCTION = LuaValType(C.LUA_TFUNCTION) LUA_TUSERDATA = LuaValType(C.LUA_TUSERDATA) LUA_TTHREAD = LuaValType(C.LUA_TTHREAD) LUA_TLIGHTUSERDATA = LuaValType(C.LUA_TLIGHTUSERDATA) )
const ( LUA_VERSION = C.LUA_VERSION LUA_RELEASE = C.LUA_RELEASE LUA_VERSION_NUM = C.LUA_VERSION_NUM LUA_COPYRIGHT = C.LUA_COPYRIGHT LUA_AUTHORS = C.LUA_AUTHORS LUA_MULTRET = C.LUA_MULTRET LUA_REGISTRYINDEX = C.LUA_REGISTRYINDEX LUA_ENVIRONINDEX = C.LUA_ENVIRONINDEX LUA_GLOBALSINDEX = C.LUA_GLOBALSINDEX LUA_YIELD = C.LUA_YIELD LUA_ERRRUN = C.LUA_ERRRUN LUA_ERRSYNTAX = C.LUA_ERRSYNTAX LUA_ERRMEM = C.LUA_ERRMEM LUA_ERRERR = C.LUA_ERRERR LUA_TNONE = C.LUA_TNONE LUA_MINSTACK = C.LUA_MINSTACK LUA_GCSTOP = C.LUA_GCSTOP LUA_GCRESTART = C.LUA_GCRESTART LUA_GCCOLLECT = C.LUA_GCCOLLECT LUA_GCCOUNT = C.LUA_GCCOUNT LUA_GCCOUNTB = C.LUA_GCCOUNTB LUA_GCSTEP = C.LUA_GCSTEP LUA_GCSETPAUSE = C.LUA_GCSETPAUSE LUA_GCSETSTEPMUL = C.LUA_GCSETSTEPMUL LUA_HOOKCALL = C.LUA_HOOKCALL LUA_HOOKRET = C.LUA_HOOKRET LUA_HOOKLINE = C.LUA_HOOKLINE LUA_HOOKCOUNT = C.LUA_HOOKCOUNT LUA_HOOKTAILRET = C.LUA_HOOKTAILRET LUA_MASKCALL = C.LUA_MASKCALL LUA_MASKRET = C.LUA_MASKRET LUA_MASKLINE = C.LUA_MASKLINE LUA_MASKCOUNT = C.LUA_MASKCOUNT LUA_ERRFILE = C.LUA_ERRFILE LUA_NOREF = C.LUA_NOREF LUA_REFNIL = C.LUA_REFNIL LUA_FILEHANDLE = C.LUA_FILEHANDLE LUA_COLIBNAME = C.LUA_COLIBNAME LUA_TABLIBNAME = C.LUA_TABLIBNAME LUA_IOLIBNAME = C.LUA_IOLIBNAME LUA_OSLIBNAME = C.LUA_OSLIBNAME LUA_STRLIBNAME = C.LUA_STRLIBNAME LUA_MATHLIBNAME = C.LUA_MATHLIBNAME LUA_DBLIBNAME = C.LUA_DBLIBNAME LUA_LOADLIBNAME = C.LUA_LOADLIBNAME )
const ExecutionQuantumExceeded = "Lua execution quantum exceeded"
The errorstring used by State.SetExecutionLimit
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HookFunction ¶
type HookFunction func(L *State)
This is the type of a go function that can be used as a lua_Hook
type LuaError ¶
type LuaError struct {
// contains filtered or unexported fields
}
func (*LuaError) StackTrace ¶
func (err *LuaError) StackTrace() []LuaStackEntry
type LuaGoFunction ¶
This is the type of go function that can be registered as lua functions
type LuaStackEntry ¶
type LuaValType ¶
type LuaValType int
type State ¶
type State struct { // index of this object inside the goStates array Index uintptr // contains filtered or unexported fields }
Wrapper to keep cgo from complaining about incomplete ptr type
func NewState ¶
func NewState() *State
luaL_newstate -> [-0, +0, -]
Creates a new Lua state. It calls lua_newstate with an allocator based on the standard C realloc function and then sets a panic function (see lua_atpanic) that prints an error message to the standard error output in case of fatal errors.
func NewStateAlloc ¶
Creates a new lua interpreter state with the given allocation function
func NewStateWithContext ¶
func (*State) ArgError ¶
luaL_argerror -> [-0, +0, v]
Raises an error with the following message, where func is retrieved from the call stack:
func (*State) Argcheck ¶
[luaL_argcheck] -> [-0, +0, v]
Checks whether cond is true. If not, raises an error with the following message, where func is retrieved from the call stack:
[luaL_argcheck]: https://www.lua.org/manual/5.1/manual.html#lual_argcheck WARNING: before b30b2c62c6712c6683a9d22ff0abfa54c8267863 the function ArgCheck had the opposite behaviour
func (*State) AtPanic ¶
func (L *State) AtPanic(panicf LuaGoFunction) (oldpanicf LuaGoFunction)
Sets the AtPanic function, returns the old one
BUG(everyone_involved): passing nil causes serious problems
func (*State) CheckAny ¶
luaL_checkany -> [-0, +0, v]
Checks whether the function has an argument of any type (including nil) at position narg.
func (*State) CheckInteger ¶
luaL_checkinteger -> [-0, +0, v]
Checks whether the function argument narg is a number and returns this number cast to a lua_Integer.
func (*State) CheckNumber ¶
luaL_checknumber -> [-0, +0, v]
Checks whether the function argument narg is a number and returns this number.
func (*State) CheckOption ¶
luaL_checkoption -> [-0, +0, v]
Checks whether the function argument narg is a string and searches for this string in the array lst (which must be NULL-terminated). Returns the index in the array where the string was found. Raises an error if the argument is not a string or if the string cannot be found.
BUG(everyone_involved): not implemented
func (*State) CheckStack ¶
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 (*State) CheckString ¶
luaL_checkstring -> [-0, +0, v]
Checks whether the function argument narg is a string and returns this string.
func (*State) CheckType ¶
func (L *State) CheckType(narg int, t LuaValType)
luaL_checktype -> [-0, +0, v]
Checks whether the function argument narg has type t. See lua_type for the encoding of types for t.
func (*State) CheckUdata ¶
luaL_checkudata -> [-0, +0, v]
Checks whether the function argument narg is a userdata of the type tname (see luaL_newmetatable).
func (*State) Close ¶
func (L *State) Close()
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 (*State) Concat ¶
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 (*State) CreateTable ¶
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 (*State) DoString ¶
Executes the string, returns nil for no errors or the lua error string on failure
func (*State) Dump ¶
lua_dump -> [-0, +0, m]
Dumps a function as a binary chunk. Receives a Lua function on the top of the stack and produces a binary chunk that, if loaded again, results in a function equivalent to the one dumped. As it produces parts of the chunk, lua_dump calls function writer (see lua_Writer) with the given data to write them.
func (*State) Equal ¶
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 (*State) GSub ¶
luaL_gsub -> [-0, +1, m]
Creates a copy of string s by replacing any occurrence of the string p with the string r. Pushes the resulting string on the stack and returns it.
func (*State) GetField ¶
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 (*State) GetMetaField ¶
luaL_getmetafield -> [-0, +(0|1), m]
Pushes onto the stack the field e from the metatable of the object at index obj. If the object does not have a metatable, or if the metatable does not have this field, returns 0 and pushes nothing.
func (*State) GetMetaTable ¶
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 (*State) GetTable ¶
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 (*State) GetTop ¶
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 (*State) GetUpvalue ¶
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 (*State) GetfEnv ¶
lua_getfenv -> [-0, +1, -]
Pushes onto the stack the environment table of the value at the given index.
func (*State) Insert ¶
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 (*State) IsFunction ¶
Returns true if the value at index is user data pushed with PushGoFunction
func (*State) IsGoFunction ¶
Returns true if the value at index is a LuaGoFunction
func (*State) IsGoStruct ¶
Returns true if the value at index is user data pushed with PushGoStruct
func (*State) IsLightUserdata ¶
Returns true if the value at index is light user data
func (*State) IsNil ¶
lua_isnil -> [-0, +0, -]
Returns 1 if the value at the given acceptable index is nil, and 0 otherwise.
func (*State) IsNone ¶
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 (*State) IsNoneOrNil ¶
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 (*State) IsNumber ¶
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 (*State) IsString ¶
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 (*State) IsTable ¶
lua_istable -> [-0, +0, -]
Returns 1 if the value at the given acceptable index is a table, and 0 otherwise.
func (*State) IsThread ¶
lua_isthread -> [-0, +0, -]
Returns 1 if the value at the given acceptable index is a thread, and 0 otherwise.
func (*State) IsUserdata ¶
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 (*State) LGetMetaTable ¶
luaL_getmetatable -> [-0, +1, -]
Pushes onto the stack the metatable associated with name tname in the registry (see luaL_newmetatable).
func (*State) LTypename ¶
luaL_typename -> [-0, +0, -]
Returns the name of the type of the value at the given index.
func (*State) LessThan ¶
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 (*State) Load ¶
lua_load -> [-0, +1, -]
Loads a Lua chunk. If there are no errors, lua_load pushes the compiled chunk as a Lua function on top of the stack. Otherwise, it pushes an error message. The return values of lua_load are:
func (*State) LoadFile ¶
luaL_loadfile -> [-0, +1, m]
Loads a file as a Lua chunk. This function uses lua_load to load the chunk in the file named filename. If filename is NULL, then it loads from the standard input. The first line in the file is ignored if it starts with a #.
func (*State) LoadString ¶
luaL_loadstring -> [-0, +1, m]
Loads a string as a Lua chunk. This function uses lua_load to load the chunk in the zero-terminated string s.
func (*State) MustDoString ¶
Like DoString but panics on error
func (*State) NewMetaTable ¶
luaL_newmetatable -> [-0, +1, m]
If the registry already has the key tname, returns 0. Otherwise, creates a new table to be used as a metatable for userdata, adds it to the registry with key tname, and returns 1.
func (*State) NewTable ¶
func (L *State) NewTable()
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 (*State) NewThread ¶
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 (*State) NewUserdata ¶
Creates a new user data object of specified size and returns it
func (*State) Next ¶
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 (*State) OpenLibs ¶
func (L *State) OpenLibs()
luaL_openlibs -> [-0, +0, m]
Opens all standard Lua libraries into the given state.
func (*State) OptInteger ¶
luaL_optinteger -> [-0, +0, v]
If the function argument narg is a number, returns this number cast to a lua_Integer. If this argument is absent or is nil, returns d. Otherwise, raises an error.
func (*State) OptNumber ¶
luaL_optnumber -> [-0, +0, v]
If the function argument narg is a number, returns this number. If this argument is absent or is nil, returns d. Otherwise, raises an error.
func (*State) OptString ¶
luaL_optstring -> [-0, +0, v]
If the function argument narg is a string, returns this string. If this argument is absent or is nil, returns d. Otherwise, raises an error.
func (*State) Pop ¶
[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_objlen]: https://www.lua.org/manual/5.1/manual.html#lua_objlen lua_pop -> [-n, +0, -]
Pops n elements from the stack.
func (*State) PushBoolean ¶
lua_pushboolean -> [-0, +1, -]
Pushes a boolean value with value b onto the stack.
func (*State) PushGoClosure ¶
func (L *State) PushGoClosure(f LuaGoFunction)
PushGoClosure pushes a lua.LuaGoFunction to the stack wrapped in a Closure. this permits the go function to reflect lua type 'function' when checking with type() this implements behaviour akin to lua_pushcfunction() in lua C API.
func (*State) PushGoClosureWithUpvalues ¶
func (L *State) PushGoClosureWithUpvalues(f LuaGoFunction, nup uint)
PushGoClosureWithUpvalues pushes a GoClosure and provides 'nup' upvalues starting at index 2, because index 1 is to store the GoFunction in the Lua Closure
func (*State) PushGoFunction ¶
func (L *State) PushGoFunction(f LuaGoFunction)
Like lua_pushcfunction pushes onto the stack a go function as user data
func (*State) PushGoStruct ¶
func (L *State) PushGoStruct(iface interface{})
Pushes a Go struct onto the stack as user data.
The user data will be rigged so that lua code can access and change to public members of simple types directly
func (*State) PushInteger ¶
lua_pushinteger -> [-0, +1, -]
Pushes a number with value n onto the stack.
func (*State) PushLightUserdata ¶
func (L *State) PushLightUserdata(ud *interface{})
Push a pointer onto the stack as user data.
This function doesn't save a reference to the interface, it is the responsibility of the caller of this function to insure that the interface outlasts the lifetime of the lua object that this function creates.
func (*State) PushNil ¶
func (L *State) PushNil()
lua_pushnil -> [-0, +1, -]
Pushes a nil value onto the stack.
func (*State) PushNumber ¶
lua_pushnumber -> [-0, +1, -]
Pushes a number with value n onto the stack.
func (*State) PushString ¶
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 (*State) PushThread ¶
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 (*State) PushValue ¶
lua_pushvalue -> [-0, +1, -]
Pushes a copy of the element at the given valid index onto the stack.
func (*State) RaiseError ¶
func (*State) RawEqual ¶
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 (*State) RawGet ¶
lua_rawget -> [-1, +1, -]
Similar to lua_gettable, but does a raw access (i.e., without metamethods).
func (*State) RawGeti ¶
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 (*State) RawSet ¶
lua_rawset -> [-2, +0, m]
Similar to lua_settable, but does a raw assignment (i.e., without metamethods).
func (*State) RawSeti ¶
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 (*State) Ref ¶
luaL_ref -> [-1, +0, m]
Creates and returns a reference, in the table at index t, for the object at the top of the stack (and pops the object).
func (*State) Register ¶
func (L *State) Register(name string, f LuaGoFunction)
Registers a Go function as a global variable
func (*State) RegisterLibrary ¶
func (L *State) RegisterLibrary(name string, funcs map[string]LuaGoFunction)
Registers a map of go functions as a library that can be accessed using "require("name")"
func (*State) Remove ¶
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 (*State) Replace ¶
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 (*State) SetAllocf ¶
lua_setallocf -> [-0, +0, -]
Changes the allocator function of a given state to f with user data ud.
func (*State) SetExecutionLimit ¶
Sets the maximum number of operations to execute at instrNumber, after this the execution ends This and SetHook are mutual exclusive
func (*State) SetField ¶
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 (*State) SetGlobal ¶
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 (*State) SetHook ¶
func (L *State) SetHook(f HookFunction, instrNumber int)
Sets the lua hook (lua_sethook). This and SetExecutionLimit are mutual exclusive
func (*State) SetMetaMethod ¶
func (L *State) SetMetaMethod(methodName string, f LuaGoFunction)
Sets a metamethod to execute a go function
The code:
L.LGetMetaTable(tableName) L.SetMetaMethod(methodName, function)
is the logical equivalent of:
L.LGetMetaTable(tableName) L.PushGoFunction(function) L.SetField(-2, methodName)
except this wouldn't work because pushing a go function results in user data not a cfunction
func (*State) SetMetaTable ¶
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 (*State) SetTable ¶
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 (*State) SetTop ¶
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 (*State) SetUpvalue ¶
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 (*State) SetfEnv ¶
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 (*State) StackTrace ¶
func (L *State) StackTrace() []LuaStackEntry
Returns the current stack trace
func (*State) ToBoolean ¶
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 (*State) ToGoFunction ¶
func (L *State) ToGoFunction(index int) (f LuaGoFunction)
Returns the value at index as a Go function (it must be something pushed with PushGoFunction)
func (*State) ToGoStruct ¶
Returns the value at index as a Go Struct (it must be something pushed with PushGoStruct)
func (*State) ToInteger ¶
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 (*State) ToNumber ¶
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 (*State) ToPointer ¶
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 (*State) ToString ¶
lua_tostring -> [-0, +0, m]
Equivalent to lua_tolstring with len equal to NULL.
func (*State) ToThread ¶
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 (*State) ToUserdata ¶
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 (*State) Type ¶
func (L *State) Type(index int) LuaValType
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 (*State) Typename ¶
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 (*State) Unref ¶
luaL_unref -> [-0, +0, -]
Releases reference ref from the table at index t (see luaL_ref). The entry is removed from the table, so that the referred object can be collected. The reference ref is also freed to be used again.
func (*State) Where ¶
luaL_where -> [-0, +1, m]
Pushes onto the stack a string identifying the current position of the control at level lvl in the call stack. Typically this string has the following format:
Notes ¶
Bugs ¶
not implemented
passing nil causes serious problems