lua

package
v0.0.0-...-cd31ab2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2024 License: MIT Imports: 6 Imported by: 66

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

View Source
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)
)
View Source
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
)
View Source
const ExecutionQuantumExceeded = "Lua execution quantum exceeded"

The errorstring used by State.SetExecutionLimit

Variables

This section is empty.

Functions

func XMove

func XMove(from *State, to *State, n int)

lua_xmove -> [-?, +?, -]

Exchange values between different threads of the same global state.

Types

type Alloc

type Alloc func(ptr unsafe.Pointer, osize uint, nsize uint) unsafe.Pointer

Type of allocation functions to use with NewStateAlloc

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) Code

func (err *LuaError) Code() int

func (*LuaError) Error

func (err *LuaError) Error() string

func (*LuaError) StackTrace

func (err *LuaError) StackTrace() []LuaStackEntry

type LuaGoFunction

type LuaGoFunction func(L *State) int

This is the type of go function that can be registered as lua functions

type LuaStackEntry

type LuaStackEntry struct {
	Name        string
	Source      string
	ShortSource string
	CurrentLine int
}

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

func NewStateAlloc(f Alloc) *State

Creates a new lua interpreter state with the given allocation function

func NewStateWithContext

func NewStateWithContext(ctx context.Context) *State

func (*State) ArgError

func (L *State) ArgError(narg int, extramsg string) int

luaL_argerror -> [-0, +0, v]

Raises an error with the following message, where func is retrieved from the call stack:

func (*State) Argcheck

func (L *State) Argcheck(cond bool, narg int, extramsg string)

[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) Call

func (L *State) Call(nargs, nresults int) (err error)

lua_call -> [-(nargs + 1), +nresults, e]

Calls a function.

func (*State) CallMeta

func (L *State) CallMeta(obj int, e string) int

luaL_callmeta -> [-0, +(0|1), e]

Calls a metamethod.

func (*State) CheckAny

func (L *State) CheckAny(narg int)

luaL_checkany -> [-0, +0, v]

Checks whether the function has an argument of any type (including nil) at position narg.

func (*State) CheckInteger

func (L *State) CheckInteger(narg int) int

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

func (L *State) CheckNumber(narg int) float64

luaL_checknumber -> [-0, +0, v]

Checks whether the function argument narg is a number and returns this number.

func (*State) CheckOption

func (L *State) CheckOption(narg int, def string, lst []string) int

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

func (L *State) CheckStack(extra int) bool

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

func (L *State) CheckString(narg int) string

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

func (L *State) CheckUdata(narg int, tname string) unsafe.Pointer

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

func (L *State) Concat(n int)

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) Context

func (L *State) Context() context.Context

func (*State) CreateTable

func (L *State) CreateTable(narr int, nrec int)

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) DoFile

func (L *State) DoFile(filename string) error

Executes file, returns nil for no errors or the lua error string on failure

func (*State) DoString

func (L *State) DoString(str string) error

Executes the string, returns nil for no errors or the lua error string on failure

func (*State) Dump

func (L *State) Dump() int

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

func (L *State) Equal(index1, index2 int) bool

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) GC

func (L *State) GC(what, data int) int

lua_gc -> [-0, +0, e]

Controls the garbage collector.

func (*State) GSub

func (L *State) GSub(s string, p string, r string) string

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

func (L *State) GetField(index int, k string)

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) GetGlobal

func (L *State) GetGlobal(name string)

Pushes on the stack the value of a global variable (lua_getglobal)

func (*State) GetMetaField

func (L *State) GetMetaField(obj int, e string) bool

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

func (L *State) GetMetaTable(index int) bool

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) GetState

func (L *State) GetState() *C.lua_State

func (*State) GetTable

func (L *State) GetTable(index int)

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

func (L *State) GetTop() int

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

func (L *State) GetUpvalue(funcindex, n int)

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

func (L *State) GetfEnv(index int)

lua_getfenv -> [-0, +1, -]

Pushes onto the stack the environment table of the value at the given index.

func (*State) Insert

func (L *State) Insert(index int)

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) IsBoolean

func (L *State) IsBoolean(index int) bool

Returns true if lua_type == LUA_TBOOLEAN

func (*State) IsFunction

func (L *State) IsFunction(index int) bool

Returns true if the value at index is user data pushed with PushGoFunction

func (*State) IsGoFunction

func (L *State) IsGoFunction(index int) bool

Returns true if the value at index is a LuaGoFunction

func (*State) IsGoStruct

func (L *State) IsGoStruct(index int) bool

Returns true if the value at index is user data pushed with PushGoStruct

func (*State) IsLightUserdata

func (L *State) IsLightUserdata(index int) bool

Returns true if the value at index is light user data

func (*State) IsNil

func (L *State) IsNil(index int) bool

lua_isnil -> [-0, +0, -]

Returns 1 if the value at the given acceptable index is nil, and 0 otherwise.

func (*State) IsNone

func (L *State) IsNone(index int) bool

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

func (L *State) IsNoneOrNil(index int) bool

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

func (L *State) IsNumber(index int) bool

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

func (L *State) IsString(index int) bool

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

func (L *State) IsTable(index int) bool

lua_istable -> [-0, +0, -]

Returns 1 if the value at the given acceptable index is a table, and 0 otherwise.

func (*State) IsThread

func (L *State) IsThread(index int) bool

lua_isthread -> [-0, +0, -]

Returns 1 if the value at the given acceptable index is a thread, and 0 otherwise.

func (*State) IsUserdata

func (L *State) IsUserdata(index int) bool

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

func (L *State) LGetMetaTable(tname string)

luaL_getmetatable -> [-0, +1, -]

Pushes onto the stack the metatable associated with name tname in the registry (see luaL_newmetatable).

func (*State) LTypename

func (L *State) LTypename(index int) string

luaL_typename -> [-0, +0, -]

Returns the name of the type of the value at the given index.

func (*State) LessThan

func (L *State) LessThan(index1, index2 int) bool

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

func (L *State) Load(bs []byte, name string) int

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

func (L *State) LoadFile(filename string) int

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

func (L *State) LoadString(s string) int

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) MustCall

func (L *State) MustCall(nargs, nresults int)

Like lua_call but panics on errors

func (*State) MustDoString

func (L *State) MustDoString(str string)

Like DoString but panics on error

func (*State) NewError

func (L *State) NewError(msg string) *LuaError

func (*State) NewMetaTable

func (L *State) NewMetaTable(tname string) bool

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

func (L *State) NewThread() *State

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

func (L *State) NewUserdata(size uintptr) unsafe.Pointer

Creates a new user data object of specified size and returns it

func (*State) Next

func (L *State) Next(index int) int

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) ObjLen

func (L *State) ObjLen(index int) uint

func (*State) OpenBase

func (L *State) OpenBase()

Calls luaopen_base

func (*State) OpenIO

func (L *State) OpenIO()

Calls luaopen_io

func (*State) OpenLibs

func (L *State) OpenLibs()

luaL_openlibs -> [-0, +0, m]

Opens all standard Lua libraries into the given state.

func (*State) OpenMath

func (L *State) OpenMath()

Calls luaopen_math

func (*State) OpenOS

func (L *State) OpenOS()

Calls luaopen_os

func (*State) OpenPackage

func (L *State) OpenPackage()

Calls luaopen_package

func (*State) OpenString

func (L *State) OpenString()

Calls luaopen_string

func (*State) OpenTable

func (L *State) OpenTable()

Calls luaopen_table

func (*State) OptInteger

func (L *State) OptInteger(narg int, d int) int

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

func (L *State) OptNumber(narg int, d float64) float64

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

func (L *State) OptString(narg int, d string) string

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

func (L *State) Pop(n int)

[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

func (L *State) PushBoolean(b bool)

lua_pushboolean -> [-0, +1, -]

Pushes a boolean value with value b onto the stack.

func (*State) PushBytes

func (L *State) PushBytes(b []byte)

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

func (L *State) PushInteger(n int64)

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

func (L *State) PushNumber(n float64)

lua_pushnumber -> [-0, +1, -]

Pushes a number with value n onto the stack.

func (*State) PushString

func (L *State) PushString(str string)

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

func (L *State) PushThread() (isMain bool)

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

func (L *State) PushValue(index int)

lua_pushvalue -> [-0, +1, -]

Pushes a copy of the element at the given valid index onto the stack.

func (*State) RaiseError

func (L *State) RaiseError(msg string)

func (*State) RawEqual

func (L *State) RawEqual(index1 int, index2 int) bool

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

func (L *State) RawGet(index int)

lua_rawget -> [-1, +1, -]

Similar to lua_gettable, but does a raw access (i.e., without metamethods).

func (*State) RawGeti

func (L *State) RawGeti(index int, n int)

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

func (L *State) RawSet(index int)

lua_rawset -> [-2, +0, m]

Similar to lua_settable, but does a raw assignment (i.e., without metamethods).

func (*State) RawSeti

func (L *State) RawSeti(index int, n int)

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

func (L *State) Ref(t int) int

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

func (L *State) Remove(index int)

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

func (L *State) Replace(index int)

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) Resume

func (L *State) Resume(narg int) int

lua_resume -> [-?, +?, -]

Starts and resumes a coroutine in a given thread.

func (*State) SetAllocf

func (L *State) SetAllocf(f Alloc)

lua_setallocf -> [-0, +0, -]

Changes the allocator function of a given state to f with user data ud.

func (*State) SetExecutionLimit

func (L *State) SetExecutionLimit(instrNumber int)

Sets the maximum number of operations to execute at instrNumber, after this the execution ends This and SetHook are mutual exclusive

func (*State) SetField

func (L *State) SetField(index int, k string)

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

func (L *State) SetGlobal(name string)

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

func (L *State) SetMetaTable(index int)

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

func (L *State) SetTable(index int)

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

func (L *State) SetTop(index int)

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

func (L *State) SetUpvalue(funcindex, n int) bool

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

func (L *State) SetfEnv(index int)

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) Status

func (L *State) Status() int

lua_status -> [-0, +0, -]

Returns the status of the thread L.

func (*State) ToBoolean

func (L *State) ToBoolean(index int) bool

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) ToBytes

func (L *State) ToBytes(index int) []byte

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

func (L *State) ToGoStruct(index int) (f interface{})

Returns the value at index as a Go Struct (it must be something pushed with PushGoStruct)

func (*State) ToInteger

func (L *State) ToInteger(index int) int

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

func (L *State) ToNumber(index int) float64

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

func (L *State) ToPointer(index int) uintptr

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

func (L *State) ToString(index int) string

lua_tostring -> [-0, +0, m]

Equivalent to lua_tolstring with len equal to NULL.

func (*State) ToThread

func (L *State) ToThread(index int) *State

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

func (L *State) ToUserdata(index int) unsafe.Pointer

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

func (L *State) Typename(tp int) string

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

func (L *State) Unref(t int, ref int)

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) UpvalueIndex

func (L *State) UpvalueIndex(n int) int

lua_upvalueindex

func (*State) Where

func (L *State) Where(lvl int)

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:

func (*State) Yield

func (L *State) Yield(nresults int) int

lua_yield -> [-?, +?, -]

Yields a coroutine.

Notes

Bugs

  • not implemented

  • passing nil causes serious problems

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL