Documentation
¶
Overview ¶
luarunner — a package for interacting with LuaJIT.
Index ¶
- type LuaRunner
- func (lua *LuaRunner) AddPackageCPath(pattern string)
- func (lua *LuaRunner) AddPackagePath(pattern string)
- func (lua *LuaRunner) Call(in, out int) error
- func (lua *LuaRunner) CheckFunction(funcName string) bool
- func (lua *LuaRunner) Close()
- func (lua *LuaRunner) Get(i int) (any, error)
- func (lua *LuaRunner) GetGlobal(name string)
- func (lua *LuaRunner) GetStackSize() int
- func (lua *LuaRunner) Load(code string) error
- func (lua *LuaRunner) LoadFile(name string) error
- func (lua *LuaRunner) Pop() (any, error)
- func (lua *LuaRunner) Push(valueAny any)
- func (lua *LuaRunner) Run() error
- func (lua *LuaRunner) SetGlobal(name string)
- func (lua *LuaRunner) StrictRead()
- func (lua *LuaRunner) StrictWrite()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LuaRunner ¶
LuaRunner represents Lua VM
func (*LuaRunner) AddPackageCPath ¶
AddPackageCPath adds a pattern to the file search path for require (package.cpath)
func (*LuaRunner) AddPackagePath ¶
AddPackagePath adds a pattern to the file search path for require (package.path)
func (*LuaRunner) Call ¶
Call calls the function at the top of the stack To set the function, use GetGlobal in - number of input parameters out - number of return values, -1 for a variable number
func (*LuaRunner) CheckFunction ¶
CheckFunction checks for the existence of a global function in the current Lua VM
func (*LuaRunner) Close ¶
func (lua *LuaRunner) Close()
Close releases all resources associated with the Lua VM
func (*LuaRunner) GetGlobal ¶
GetGlobal pushes the value of the global variable with the name 'name' onto the stack
func (*LuaRunner) GetStackSize ¶
GetStackSize returns the current depth of the Lua VM stack It is used to determine the number of return values after a function call and for debugging memory leaks
func (*LuaRunner) Load ¶
Load loads a Lua script and pushes the code onto the top of the stack. To execute it, you need to call Run(). code - Lua code
func (*LuaRunner) LoadFile ¶
Load loads a Lua script from a file and pushes the code onto the top of the stack. To execute it, you need to call Run(). name - path to the file
func (*LuaRunner) Push ¶
Push pushes a value onto the Lua VM stack.
string and []byte are converted to a string (LUA_TSTRING); int, int32, int64, float32, float64 are converted to a number (LUA_TNUMBER), beware of truncating int64 to 53 bits; bool is converted to a boolean (LUA_TBOOLEAN); uintptr is converted to LUA_TLIGHTUSERDATA; nil is converted to LUA_TLIGHTUSERDATA(NULL) if it is a table value, otherwise to nil (LUA_TNIL).
map[string]any is converted to a table (LUA_TTABLE), and it's the only map type that is efficiently passed to Lua. Other map types will use reflection. On one hand, this allows using arbitrary key and value types supported by Lua; on the other hand, reflection is less efficient. Another limitation is that this package does not allow retrieving a Lua table with key types other than string or number.
Using reflection: pointers are dereferenced; slices and arrays are passed as tables with integer keys; structs and maps with arbitrary key/value types are passed as tables.
If an unsupported data type is encountered, nil or LUA_TLIGHTUSERDATA(NULL) is pushed onto the stack, depending on whether it's a simple scalar or a table element.
func (*LuaRunner) Run ¶
Run calls the function at the top of the stack with no parameters and a variable number of return values To execute the script after Load and LoadFile
func (*LuaRunner) SetGlobal ¶
SetGlobal pops a value from the stack and sets it as the global variable with the name 'name'
func (*LuaRunner) StrictRead ¶
func (lua *LuaRunner) StrictRead()
StrictRead prevents reading uninitialized variables, protecting against typos.
func (*LuaRunner) StrictWrite ¶
func (lua *LuaRunner) StrictWrite()
StrictWrite prevents writing to undeclared global variables; It is useful to call it after initializing the script.