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 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) CreateTable(narr int, nrec int)
- func (L *State) DoFile(filename string) error
- func (L *State) DoString(str string) error
- func (L *State) Equal(index1, index2 int) bool
- func (L *State) FDump() string
- 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) GetTable(index int)
- func (L *State) GetTop() 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) LoadBuffer(buff string, size int, 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) Pcall(nargs, nresults, errfunc int) int
- func (L *State) Pop(n int)
- func (L *State) PushBoolean(b bool)
- func (L *State) PushGoClosure(f LuaGoFunction)
- 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) 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) 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) SetfEnv(index int)
- func (L *State) StackTrace() []LuaStackEntry
- func (L *State) Status() int
- func (L *State) ToBoolean(index int) bool
- 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) 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 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 NewStateAlloc ¶
Creates a new lua interpreter state with the given allocation function
func (*State) Argcheck ¶
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) CheckUdata ¶
luaL_checkudata
func (*State) DoString ¶
Executes the string, returns nil for no errors or the lua error string on failure
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) LoadBuffer ¶
luaL_loadbuffer
func (*State) MustDoString ¶
Like DoString but panics on error
func (*State) NewUserdata ¶
Creates a new user data object of specified size and returns it
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) 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) 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) RaiseError ¶
func (*State) Register ¶
func (L *State) Register(name string, f LuaGoFunction)
Registers a Go function as a global variable
func (*State) SetExecutionLimit ¶
Sets the maximum number of operations to execute at instrNumber, after this the execution ends
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) StackTrace ¶
func (L *State) StackTrace() []LuaStackEntry
Returns the current stack trace
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)
Notes ¶
Bugs ¶
not implemented
passing nil causes serious problems