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 AddCloseHandlerDefault(L *State) int
- func GetVersionNumber() string
- func GetVersionNumberWithoutDot() string
- func LuaErrorTrans(pan interface{}, prefix string, suffix string) error
- func XMove(from *State, to *State, n int)
- type Alloc
- type Interrupt
- type LuaError
- type LuaGoErrHandler
- type LuaGoFunction
- type LuaStackEntry
- type LuaValType
- type State
- func (L *State) AddCloseHandler(callback LuaGoFunction)
- 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) CallHandle(nargs, nresults int, errHandler LuaGoErrHandler) (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) ClearGoRef()
- 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) DoStringHandle(str string, errHandler LuaGoErrHandler) error
- func (L *State) Dump() int
- func (L *State) DumpEx() error
- 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) GetData(key string) interface{}
- func (L *State) GetDoCloseStdout() bool
- func (L *State) GetField(index int, k string)
- func (L *State) GetGlobal(name string)
- func (L *State) GetGoRef(ref int) interface{}
- func (L *State) GetMetaField(obj int, e string) bool
- func (L *State) GetMetaTable(index int) bool
- func (L *State) GetStdout() io.Writer
- func (L *State) GetTable(index int)
- func (L *State) GetTableByName(table string, createIfNil bool) (exist bool, err error)
- func (L *State) GetTop() 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) KeepGoRef(obj interface{}) int
- 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) LoadBuffer(chunk []byte, name string, mode string) error
- func (L *State) LoadFile(filename string) int
- func (L *State) LoadFileEx(filename string) error
- func (L *State) LoadString(s string) int
- func (L *State) MustCall(nargs, nresults int) error
- 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) OpenBit32()
- func (L *State) OpenCoroutine()
- func (L *State) OpenDebug()
- 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) 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(err interface{})
- 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) SetData(key string, val interface{})
- func (L *State) SetDoCloseStdout(doCloseStdout bool)
- 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) SetStdout(stdout io.Writer)
- func (L *State) SetTable(index int)
- func (L *State) SetTop(index int)
- func (L *State) StackToString() string
- func (L *State) StackTrace() []LuaStackEntry
- func (L *State) Status() int
- func (L *State) String() string
- func (L *State) TableGetAndRef(tableIndex int, key string, throwNil bool, ...) (int, error)
- func (L *State) TableGetBoolean(tableIndex int, key string, def bool, throwNil bool) (bool, error)
- func (L *State) TableGetInteger(tableIndex int, key string, def int, throwNil bool) (int, error)
- func (L *State) TableGetNumber(tableIndex int, key string, def float64, throwNil bool) (float64, error)
- func (L *State) TableGetString(tableIndex int, key string, def string, throwNil bool) (string, error)
- func (L *State) TableGetValue(tableIndex int, key string, def interface{}, throwNil bool) (interface{}, error)
- func (L *State) TableRegister(table string, name string, val interface{}) error
- func (L *State) TableRegisters(table string, funcs map[string]interface{}) error
- func (L *State) TableSetValue(tableIndex int, key string, val interface{}) (err error)
- 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) ToInterface(idx int, retptr bool) interface{}
- 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) TypeString(idx int) string
- 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_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_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 ¶
func AddCloseHandlerDefault ¶
func GetVersionNumber ¶
func GetVersionNumber() string
func GetVersionNumberWithoutDot ¶
func GetVersionNumberWithoutDot() string
func LuaErrorTrans ¶
Types ¶
type LuaError ¶
type LuaError struct {
// contains filtered or unexported fields
}
func (*LuaError) StackTrace ¶
func (err *LuaError) StackTrace() []LuaStackEntry
func (*LuaError) StackTraceToError ¶
type LuaGoErrHandler ¶
type LuaGoErrHandler func(L *State, pan interface{})
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 Name string Path string Index uintptr ErrHandler LuaGoErrHandler Notice *Interrupt StdoutLineChanger string // 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) AddCloseHandler ¶
func (L *State) AddCloseHandler(callback LuaGoFunction)
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) CallHandle ¶
func (L *State) CallHandle(nargs, nresults int, errHandler LuaGoErrHandler) (err error)
func (*State) CheckUdata ¶
luaL_checkudata
func (*State) ClearGoRef ¶
func (L *State) ClearGoRef()
func (*State) DoString ¶
Executes the string, returns nil for no errors or the lua error string on failure
func (*State) DoStringHandle ¶
func (L *State) DoStringHandle(str string, errHandler LuaGoErrHandler) error
func (*State) GetDoCloseStdout ¶
func (*State) GetTableByName ¶
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) LoadFileEx ¶
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 (L *State) RaiseError(err interface{})
func (*State) Register ¶
func (L *State) Register(name string, f LuaGoFunction)
Registers a Go function as a global variable
func (*State) SetDoCloseStdout ¶
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) StackToString ¶
func (*State) StackTrace ¶
func (L *State) StackTrace() []LuaStackEntry
Returns the current stack trace
func (*State) TableGetAndRef ¶
func (*State) TableGetBoolean ¶
func (*State) TableGetInteger ¶
func (*State) TableGetNumber ¶
func (*State) TableGetString ¶
func (*State) TableGetValue ¶
func (*State) TableRegister ¶
func (*State) TableRegisters ¶
func (*State) TableSetValue ¶
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) ToInterface ¶
func (*State) TypeString ¶
Notes ¶
Bugs ¶
not implemented
passing nil causes serious problems