lua

package
v0.0.0-...-b171bac Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 10 Imported by: 5

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_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 AddCloseHandlerDefault(L *State) int

func GetVersionNumber

func GetVersionNumber() string

func GetVersionNumberWithoutDot

func GetVersionNumberWithoutDot() string

func LuaErrorTrans

func LuaErrorTrans(pan interface{}, prefix string, suffix string) error

func XMove

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

lua_xmove

Types

type Alloc

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

Type of allocation functions to use with NewStateAlloc

type Interrupt

type Interrupt struct {
	Code int
	Msg  string
	Data interface{}
}

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

func (*LuaError) StackTraceToError

func (err *LuaError) StackTraceToError(prefix string, suffix string) error

func (*LuaError) StackTraceToString

func (err *LuaError) StackTraceToString(prefix string, suffix string) string

type LuaGoErrHandler

type LuaGoErrHandler func(L *State, pan interface{})

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
	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 NewState

func NewState() *State

luaL_newstate

func NewStateAlloc

func NewStateAlloc(f Alloc) *State

Creates a new lua interpreter state with the given allocation function

func (*State) AddCloseHandler

func (L *State) AddCloseHandler(callback LuaGoFunction)

func (*State) ArgError

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

luaL_argerror

func (*State) Argcheck

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

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

func (*State) CallHandle

func (L *State) CallHandle(nargs, nresults int, errHandler LuaGoErrHandler) (err error)

func (*State) CallMeta

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

luaL_callmeta

func (*State) CheckAny

func (L *State) CheckAny(narg int)

luaL_checkany

func (*State) CheckInteger

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

luaL_checkinteger

func (*State) CheckNumber

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

luaL_checknumber

func (*State) CheckOption

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

luaL_checkoption

BUG(everyone_involved): not implemented

func (*State) CheckStack

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

lua_checkstack

func (*State) CheckString

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

luaL_checkstring

func (*State) CheckType

func (L *State) CheckType(narg int, t LuaValType)

luaL_checktype

func (*State) CheckUdata

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

luaL_checkudata

func (*State) ClearGoRef

func (L *State) ClearGoRef()

func (*State) Close

func (L *State) Close()

lua_close

func (*State) Concat

func (L *State) Concat(n int)

lua_concat

func (*State) CreateTable

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

lua_createtable

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

func (L *State) DoStringHandle(str string, errHandler LuaGoErrHandler) error

func (*State) Dump

func (L *State) Dump() int

lua_dump

func (*State) DumpEx

func (L *State) DumpEx() error

func (*State) Equal

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

lua_equal

func (*State) GC

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

lua_gc

func (*State) GSub

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

luaL_gsub

func (*State) GetData

func (L *State) GetData(key string) interface{}

func (*State) GetDoCloseStdout

func (L *State) GetDoCloseStdout() bool

func (*State) GetField

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

lua_getfield

func (*State) GetGlobal

func (L *State) GetGlobal(name string)

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

func (*State) GetGoRef

func (L *State) GetGoRef(ref int) interface{}

func (*State) GetMetaField

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

luaL_getmetafield

func (*State) GetMetaTable

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

lua_getmetatable

func (*State) GetStdout

func (L *State) GetStdout() io.Writer

func (*State) GetTable

func (L *State) GetTable(index int)

lua_gettable

func (*State) GetTableByName

func (L *State) GetTableByName(table string, createIfNil bool) (exist bool, err error)

func (*State) GetTop

func (L *State) GetTop() int

lua_gettop

func (*State) Insert

func (L *State) Insert(index int)

lua_insert

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

func (*State) IsNone

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

lua_isnone

func (*State) IsNoneOrNil

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

lua_isnoneornil

func (*State) IsNumber

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

lua_isnumber

func (*State) IsString

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

lua_isstring

func (*State) IsTable

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

lua_istable

func (*State) IsThread

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

lua_isthread

func (*State) IsUserdata

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

lua_isuserdata

func (*State) KeepGoRef

func (L *State) KeepGoRef(obj interface{}) int

func (*State) LGetMetaTable

func (L *State) LGetMetaTable(tname string)

luaL_getmetatable

func (*State) LTypename

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

luaL_typename

func (*State) LessThan

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

lua_lessthan

func (*State) Load

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

lua_load

func (*State) LoadBuffer

func (L *State) LoadBuffer(chunk []byte, name string, mode string) error

func (*State) LoadFile

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

luaL_loadfile

func (*State) LoadFileEx

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

func (*State) LoadString

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

luaL_loadstring

func (*State) MustCall

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

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

func (*State) NewTable

func (L *State) NewTable()

lua_newtable

func (*State) NewThread

func (L *State) NewThread() *State

lua_newthread

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

func (*State) ObjLen

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

lua_objlen

func (*State) OpenBase

func (L *State) OpenBase()

Restricted library opens Calls luaopen_base

func (*State) OpenBit32

func (L *State) OpenBit32()

Calls luaopen_bit32

func (*State) OpenCoroutine

func (L *State) OpenCoroutine()

Calls luaopen_coroutine

func (*State) OpenDebug

func (L *State) OpenDebug()

Calls luaopen_debug

func (*State) OpenIO

func (L *State) OpenIO()

Calls luaopen_io

func (*State) OpenLibs

func (L *State) OpenLibs()

luaL_openlibs

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

func (*State) OptNumber

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

luaL_optnumber

func (*State) OptString

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

luaL_optstring

func (*State) Pop

func (L *State) Pop(n int)

lua_pop

func (*State) PushBoolean

func (L *State) PushBoolean(b bool)

lua_pushboolean

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

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

func (*State) PushNumber

func (L *State) PushNumber(n float64)

lua_pushnumber

func (*State) PushString

func (L *State) PushString(str string)

lua_pushstring

func (*State) PushThread

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

lua_pushthread

func (*State) PushValue

func (L *State) PushValue(index int)

lua_pushvalue

func (*State) RaiseError

func (L *State) RaiseError(err interface{})

func (*State) RawEqual

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

lua_rawequal

func (*State) RawGet

func (L *State) RawGet(index int)

lua_rawget

func (*State) RawGeti

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

lua_rawgeti

func (*State) RawSet

func (L *State) RawSet(index int)

lua_rawset

func (*State) RawSeti

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

lua_rawseti

func (*State) Ref

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

luaL_ref

func (*State) Register

func (L *State) Register(name string, f LuaGoFunction)

Registers a Go function as a global variable

func (*State) Remove

func (L *State) Remove(index int)

lua_remove

func (*State) Replace

func (L *State) Replace(index int)

lua_replace

func (*State) Resume

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

lua_resume

func (*State) SetAllocf

func (L *State) SetAllocf(f Alloc)

lua_setallocf

func (*State) SetData

func (L *State) SetData(key string, val interface{})

func (*State) SetDoCloseStdout

func (L *State) SetDoCloseStdout(doCloseStdout bool)

func (*State) SetExecutionLimit

func (L *State) SetExecutionLimit(instrNumber int)

Sets the maximum number of operations to execute at instrNumber, after this the execution ends

func (*State) SetField

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

lua_setfield

func (*State) SetGlobal

func (L *State) SetGlobal(name string)

lua_setglobal

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

func (*State) SetStdout

func (L *State) SetStdout(stdout io.Writer)

func (*State) SetTable

func (L *State) SetTable(index int)

lua_settable

func (*State) SetTop

func (L *State) SetTop(index int)

lua_settop

func (*State) StackToString

func (L *State) StackToString() string

func (*State) StackTrace

func (L *State) StackTrace() []LuaStackEntry

Returns the current stack trace

func (*State) Status

func (L *State) Status() int

lua_status

func (*State) String

func (L *State) String() string

func (*State) TableGetAndRef

func (L *State) TableGetAndRef(tableIndex int, key string, throwNil bool, judgement func(L *State, tableIndex int, key string) error) (int, error)

func (*State) TableGetBoolean

func (L *State) TableGetBoolean(tableIndex int, key string, def bool, throwNil bool) (bool, error)

func (*State) TableGetInteger

func (L *State) TableGetInteger(tableIndex int, key string, def int, throwNil bool) (int, error)

func (*State) TableGetNumber

func (L *State) TableGetNumber(tableIndex int, key string, def float64, throwNil bool) (float64, error)

func (*State) TableGetString

func (L *State) TableGetString(tableIndex int, key string, def string, throwNil bool) (string, error)

func (*State) TableGetValue

func (L *State) TableGetValue(tableIndex int, key string, def interface{}, throwNil bool) (interface{}, error)

func (*State) TableRegister

func (L *State) TableRegister(table string, name string, val interface{}) error

func (*State) TableRegisters

func (L *State) TableRegisters(table string, funcs map[string]interface{}) error

func (*State) TableSetValue

func (L *State) TableSetValue(tableIndex int, key string, val interface{}) (err error)

func (*State) ToBoolean

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

lua_toboolean

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

func (*State) ToInterface

func (L *State) ToInterface(idx int, retptr bool) interface{}

func (*State) ToNumber

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

lua_tonumber

func (*State) ToPointer

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

lua_topointer

func (*State) ToString

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

lua_tostring

func (*State) ToThread

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

lua_tothread

func (*State) ToUserdata

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

lua_touserdata

func (*State) Type

func (L *State) Type(index int) LuaValType

lua_type

func (*State) TypeString

func (L *State) TypeString(idx int) string

func (*State) Typename

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

lua_typename

func (*State) Unref

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

luaL_unref

func (*State) Where

func (L *State) Where(lvl int)

luaL_where

func (*State) Yield

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

lua_yield

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