Documentation ¶
Index ¶
- Constants
- type Engine
- func (e *Engine) ArgumentError(n int, msg string)
- func (e *Engine) Call(name string, retCount int, params ...interface{}) ([]*Value, error)
- func (e *Engine) Close()
- func (e *Engine) DoFile(fn string) error
- func (e *Engine) DoString(src string) error
- func (e *Engine) False() *Value
- func (e *Engine) Get(n int) *Value
- func (e *Engine) GetEnviron() *Value
- func (e *Engine) GetGlobal(name string) *Value
- func (e *Engine) GetGlobals() *Value
- func (e *Engine) GetRegistry() *Value
- func (e *Engine) LoadFile(fpath string) (*Value, error)
- func (e *Engine) LoadString(src string) (*Value, error)
- func (e *Engine) NewTable() *Value
- func (e *Engine) NewUserData(val interface{}, mt interface{}) *Value
- func (e *Engine) Nil() *Value
- func (e *Engine) OpenBase() int
- func (e *Engine) OpenChannel() int
- func (e *Engine) OpenCoroutine() int
- func (e *Engine) OpenDebug() int
- func (e *Engine) OpenIO() int
- func (e *Engine) OpenLibs()
- func (e *Engine) OpenMath() int
- func (e *Engine) OpenOS() int
- func (e *Engine) OpenPackage() int
- func (e *Engine) OpenString() int
- func (e *Engine) OpenTable() int
- func (e *Engine) PopBool() bool
- func (e *Engine) PopFloat() float64
- func (e *Engine) PopFunction() *Value
- func (e *Engine) PopInt() int
- func (e *Engine) PopInt64() int64
- func (e *Engine) PopInterface() interface{}
- func (e *Engine) PopNumber() *Value
- func (e *Engine) PopString() string
- func (e *Engine) PopTable() *Value
- func (e *Engine) PopValue() *Value
- func (e *Engine) PushValue(val interface{})
- func (e *Engine) RaiseError(err string, args ...interface{})
- func (e *Engine) RegisterClass(name string, val interface{})
- func (e *Engine) RegisterClassWithCtor(name string, typ interface{}, cons interface{})
- func (e *Engine) RegisterFunc(name string, fn interface{})
- func (e *Engine) RegisterModule(name string, fields map[string]interface{}) *Value
- func (e *Engine) RegisterType(name string, val interface{})
- func (e *Engine) SecureRequire(validPaths []string)
- func (e *Engine) SetField(tbl *Value, key string, val interface{})
- func (e *Engine) SetGlobal(name string, val interface{})
- func (e *Engine) StackSize() int
- func (e *Engine) TableFromMap(i interface{}) *Value
- func (e *Engine) TableFromSlice(i interface{}) *Value
- func (e *Engine) True() *Value
- func (e *Engine) ValueFor(val interface{}) *Value
- type EngineMutator
- type EngineOptions
- type EnginePool
- type Inspecter
- type NamingConvention
- type PooledEngine
- type REPL
- type REPLConfig
- type ScriptFunction
- type ScriptableObject
- type TableMap
- type Value
- func (v *Value) Append(value interface{})
- func (v *Value) AsBool() bool
- func (v *Value) AsFloat() float64
- func (v *Value) AsMapStringInterface() map[string]interface{}
- func (v *Value) AsNumber() float64
- func (v *Value) AsRaw() interface{}
- func (v *Value) AsSliceInterface() []interface{}
- func (v *Value) AsString() string
- func (v *Value) Call(retCount int, argList ...interface{}) ([]*Value, error)
- func (v *Value) Equals(o interface{}) bool
- func (v *Value) ForEach(cb func(*Value, *Value))
- func (v *Value) FuncLocalName(regno, pc int) (string, bool)
- func (v *Value) Get(key interface{}) *Value
- func (v *Value) Insert(i int, value interface{})
- func (v *Value) Inspect(indent string) string
- func (v *Value) Interface() interface{}
- func (v *Value) Invoke(key interface{}, retCount int, argList ...interface{}) ([]*Value, error)
- func (v *Value) IsBool() bool
- func (v *Value) IsFalse() bool
- func (v *Value) IsFunction() bool
- func (v *Value) IsMaybeList() bool
- func (v *Value) IsNil() bool
- func (v *Value) IsNumber() bool
- func (v *Value) IsString() bool
- func (v *Value) IsTable() bool
- func (v *Value) IsTrue() bool
- func (v *Value) Len() int
- func (v *Value) MaxN() int
- func (v *Value) Next(key interface{}) (*Value, *Value)
- func (v *Value) RawGet(goKey interface{}) *Value
- func (v *Value) RawSet(goKey interface{}, val interface{})
- func (v *Value) RawSetInt(i int, val interface{})
- func (v *Value) Remove(pos int) *Value
- func (v *Value) Set(goKey interface{}, val interface{})
- func (v *Value) String() string
Constants ¶
const EnginePoolMetaKey = "engine pool"
EnginePoolMetaKey is a string value for associating the pool with an engine
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct { Meta map[string]interface{} // contains filtered or unexported fields }
Engine struct stores a pointer to a gluaLState providing a simplified API.
func NewEngine ¶
func NewEngine(opts ...EngineOptions) *Engine
NewEngine creates a new engine containing a new lua.LState.
func (*Engine) ArgumentError ¶
ArgumentError raises an error associated with an invalid argument.
func (*Engine) Call ¶
Call allows for calling a method by name. The second parameter is the number of return values the function being called should return. These values will be returned in a slice of Value pointers.
func (*Engine) GetEnviron ¶
GetEnviron returns the Environment core table from Lua.
func (*Engine) GetGlobals ¶
GetGlobals returns the global core table from Lua.
func (*Engine) GetRegistry ¶
GetRegistry retursn the Registry core table from Lua.
func (*Engine) LoadFile ¶
LoadFile attempts to read the file from the file system and then load it into the engine, returning a function that executes the contents of the file.
func (*Engine) LoadString ¶
LoadString runs the given string through the Lua interpreter, wrapping it in a function that is then returned and it can be executed by calling the returned function.
func (*Engine) NewUserData ¶
NewUserData creates a Lua User Data object from teh given value and metatable value.
func (*Engine) OpenBase ¶
OpenBase allows the Lua engine to open the base library up for use in scripts.
func (*Engine) OpenChannel ¶
OpenChannel allows the Lua module for Go channel support to be accessible to scripts.
func (*Engine) OpenCoroutine ¶
OpenCoroutine allows the Lua module for goroutine suppor tto be accessible to scripts.
func (*Engine) OpenDebug ¶
OpenDebug allows the Lua module support debug features to be accissible in scripts.
func (*Engine) OpenLibs ¶
func (e *Engine) OpenLibs()
OpenLibs seeds the engine with some basic library access. This should only be used if security isn't necessarily a major concern.
func (*Engine) OpenPackage ¶
OpenPackage allows the Lua module for packages to be used in scripts. TODO: Find out what this does/means.
func (*Engine) OpenString ¶
OpenString allows the Lua module for string operations to be used in scripts.
func (*Engine) OpenTable ¶
OpenTable allows the Lua module for table operations to be used in scripts.
func (*Engine) PopFunction ¶
PopFunction is an alias for PopArg, provided for readability when specifying the desired value from the top of the stack.
func (*Engine) PopInterface ¶
func (e *Engine) PopInterface() interface{}
PopInterface returns the top of the stack as an actual Go interface.
func (*Engine) PopNumber ¶
PopNumber is an alias for PopArg, provided for readability when specifying the desired value from the top of the stack.
func (*Engine) PopTable ¶
PopTable is an alias for PopArg, provided for readability when specifying the desired value from the top of the stack.
func (*Engine) PopValue ¶
PopValue returns the top value on the Lua stack. This method is used to get arguments given to a Go function from a Lua script. This method will return a Value pointer that can then be converted into an appropriate type.
func (*Engine) PushValue ¶
func (e *Engine) PushValue(val interface{})
PushValue pushes the given Value onto the Lua stack. Use this method when 'returning' values from a Go function called from a Lua script.
func (*Engine) RaiseError ¶
RaiseError will throw an error in the Lua engine.
func (*Engine) RegisterClass ¶
RegisterClass assigns a new type, but instead of creating it via "TypeName()" it provides a more OO way of creating the object "TypeName.new()" otherwise it's functionally equivalent to RegisterType.
func (*Engine) RegisterClassWithCtor ¶
RegisterClassWithCtor does the same thing as RegisterClass excep the new function is mapped to the constructor passed in.
func (*Engine) RegisterFunc ¶
RegisterFunc registers a Go function with the script. Using this method makes Go functions accessible through Lua scripts.
func (*Engine) RegisterModule ¶
RegisterModule takes the values given, maps them to a LuaTable and then preloads the module with the given name to be consumed in Lua code.
func (*Engine) RegisterType ¶
RegisterType creates a construtor with the given name that will generate the given type.
func (*Engine) SecureRequire ¶
SecureRequire will set a require function that limits the files that can be loaded into the engine.
func (*Engine) SetField ¶
SetField applies the value to the given table associated with the given key.
func (*Engine) TableFromMap ¶
TableFromMap takes a map of go values and generates a Lua table representing the value.
func (*Engine) TableFromSlice ¶
TableFromSlice converts the given slice into a table ready for use in Lua.
type EngineMutator ¶
type EngineMutator func(*Engine)
EngineMutator will modify an Engine before it goes into the pool. This can run any number of scripts as necessary such as registring libraries, executing code, etc...
type EngineOptions ¶
type EngineOptions struct { OpenLibs bool FieldNaming NamingConvention MethodNaming NamingConvention }
EngineOptions allows for customization of a lua.Engine such as altering the names of fields and methods as well as whether or not to open all libraries.
type EnginePool ¶
type EnginePool struct { MaxPoolSize uint8 Mutator EngineMutator // contains filtered or unexported fields }
EnginePool represents a grouping of predefined/preloaded engines that can be grabbed for use when Lua scripts need to run.
func NewEnginePool ¶
func NewEnginePool(poolSize uint8, mutator EngineMutator) *EnginePool
NewEnginePool constructs a new pool with the specific maximum size and the engine mutator. It will seed the pool with one engine.
func (*EnginePool) EachEngine ¶
func (ep *EnginePool) EachEngine(fn func(*Engine))
EachEngine will call the provided handler with each engine. IN NO WAY SHOULD THIS BE USED TO UNDERMINE GET, THIS IS FOR MAINTENANCE.
func (*EnginePool) Get ¶
func (ep *EnginePool) Get() *PooledEngine
Get will fetch the next available engine from the EnginePool. If no engines are available and the maximum number of active engines in the pool have been created yet then the spawner will be invoked to spawn a new engine and return that.
func (*EnginePool) Len ¶
func (ep *EnginePool) Len() int
Len will return the number of engines that have been spawned during the execution fo the pool.
func (*EnginePool) Shutdown ¶
func (ep *EnginePool) Shutdown()
Shutdown will empty the channel, close all generated engines and mark the pool closed.
type Inspecter ¶
type Inspecter interface {
Inspect() string
}
Inspecter defines an type that can respond to the Inspect function. This is similar to fmt.Stringer in that it's a method that returns a string, but the goal with Inspecter over fmt.Stringer is to provide debug information in the string output rather than (potentially) user facing output.
type NamingConvention ¶
type NamingConvention int8
NamingConvention defines how Go names should be converted into the Lua.
const ( // SnakeCaseExportedNames converts all Go names to both their snake_case // and Exported styles (ex for 'HelloWorld' you get 'hello_world' and // 'HelloWorld') SnakeCaseExportedNames NamingConvention = iota // SnakeCaseNames converts Go names into snake_case only. SnakeCaseNames // ExportedNames converts Go names into Go-exported type case normally // (essentially meaning the exported name is unchanged when transitioning // to Lua) ExportedNames )
type PooledEngine ¶
type PooledEngine struct { *Engine // contains filtered or unexported fields }
PooledEngine wraps a Lua engine. It's purpose is provide a means with which to return the engine to the EnginePool when it's not longer being used.
func (*PooledEngine) Release ¶
func (pe *PooledEngine) Release()
Release will push the engine back into the queue for available engines for the current PooledEngine as well as nil out the reference to the engine to prevent continued usage of the engine.
type REPL ¶
type REPL struct {
// contains filtered or unexported fields
}
REPL represent a Read-Eval-Print-Loop
func NewREPL ¶
NewREPL creates a REPL struct and seeds it with the necessary values to prepare it for use. Uses the default .repl-history file.
func NewREPLWithConfig ¶
func NewREPLWithConfig(config REPLConfig) *REPL
NewREPLWithConfig creates a REPL from the provided configuration.
func (*REPL) Execute ¶
Execute will take a source string and attempt to execute it in the given engine context.
func (*REPL) NumberPrompt ¶
NumberPrompt returns a formatted prompt to use as the Readline prompt.
func (*REPL) Run ¶
Run begins the execution fo the read-eval-print-loop. Executing the REPL only ends when an input line matches `.exit` or if an error is encountered.
func (*REPL) StarPrompt ¶
StarPrompt generates a similar prompt to the font with the line number in it, but instead of the line number it uses a * character.
type REPLConfig ¶
REPLConfig provides a mean for configuring a lua.REPL value. -- HistoryFilePath is the path to the history file for storing the written
history of the REPL session (optional)
-- Prompt is a fmt string to print as the prompt for each REPL input line.
There is a special format value {n} here where you want the line number to go, or {name} as a place to inject the name provided (if any).
-- Name is a name given, really only useful when no prompt is given as this
value is injected into the prompt.
type ScriptFunction ¶
ScriptFunction is a type alias for a function that receives an Engine and returns an int.
type ScriptableObject ¶
type ScriptableObject interface {
ScriptObject() interface{}
}
ScriptableObject defines an interface that returns an object to represent it in a script. For example, in game scripts should not have access to a full Player reference, but instead will receive a "scriptable player" reference that controls what can be done to a player. Most objects returned would be small wrapper objects.
type TableMap ¶
type TableMap map[string]interface{}
TableMap interface to speed along the creation of table defining maps when creating Go modueles for use in Lua.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is a utility wrapper for lua.LValue that provies conveinient methods for casting.
func (*Value) AsBool ¶
AsBool returns the Lua boolean representation for an object (this works for non bool Values)
func (*Value) AsFloat ¶
AsFloat returns the LValue as a Go float64. This method will try to convert the Lua value to a number if possible, if not then LuaNumber(0) is returned.
func (*Value) AsMapStringInterface ¶
AsMapStringInterface will work on a Lua Table to convert it into a go map[string]interface. This method is not safe for cyclic objects! You have been warned.
func (*Value) AsRaw ¶
func (v *Value) AsRaw() interface{}
AsRaw returns the best associated Go type, ingoring functions and any other odd types. Only concerns itself with string, bool, nil, number and user data types. Tables are again, ignored.
func (*Value) AsSliceInterface ¶
func (v *Value) AsSliceInterface() []interface{}
AsSliceInterface will convert the Lua table value to a []interface{}, extracting Go values were possible and preserving references to tables.
func (*Value) Call ¶
Call invokes the LuaValue as a function (if it is one) with similar behavior to engine.Call. If you're looking to invoke a function on table, then see Value.Invoke
func (*Value) Equals ¶
Equals will determine if the *Value is equal to the other value. This also verifies they are from the same *lua.Engine as well.
func (*Value) FuncLocalName ¶
FuncLocalName is a function that returns the local name of a LFunction type if this Value objects holds an LFunction.
func (*Value) Get ¶
Get returns the value associated with the key given if the LuaValue wraps a table.
func (*Value) Inspect ¶
Inspect is similar to AsString except that it's designed to display values for debug purposes.
func (*Value) Interface ¶
func (v *Value) Interface() interface{}
Interface returns the value of the LUserData
func (*Value) Invoke ¶
Invoke will fetch a funtion value on the table (if we're working with a table, and then attempt to invoke it if it's a function.
func (*Value) IsFalse ¶
IsFalse is similar to AsBool except it returns if the Lua value would be considered false in Lua.
func (*Value) IsFunction ¶
IsFunction returns true if the stored value is a function.
func (*Value) IsMaybeList ¶
IsMaybeList will try and determine if the table _might_ be used as a list. This basically checks the first index (looking for something at 1) so it's not 100% accurate, hence 'Maybe.' Also a list that starts with 'nil' will report as not a list.
func (*Value) RawSet ¶
func (v *Value) RawSet(goKey interface{}, val interface{})
RawSet bypasses any checks for key existence and sets the value onto the table with the given key.