Documentation ¶
Index ¶
- func AddCustomLog(keyval *CustomLogKeyValue) lua.LGFunction
- func CleanupLTable(table *lua.LTable)
- func CompileLua(filePath string) (*lua.FunctionProto, error)
- func ContextDelete(ctx *Context) lua.LGFunction
- func ContextGet(ctx *Context) lua.LGFunction
- func ContextSet(ctx *Context) lua.LGFunction
- func DoCompiledFile(L *lua.LState, proto *lua.FunctionProto) error
- func Loader(L *lua.LState) int
- func LuaTableToMap(table *lua.LTable) map[any]any
- func MapToLuaTable(L *lua.LState, table map[any]any) *lua.LTable
- func NewLStateWithDefaultLibraries() *lua.LState
- type Context
- type CustomLogKeyValue
- type Done
- type LStateProvider
- type LuaBaseStatePool
- type LuaStatePool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCustomLog ¶
func AddCustomLog(keyval *CustomLogKeyValue) lua.LGFunction
func CleanupLTable ¶
func CompileLua ¶
func CompileLua(filePath string) (*lua.FunctionProto, error)
CompileLua reads the passed lua file from disk and compiles it.
func ContextDelete ¶
func ContextDelete(ctx *Context) lua.LGFunction
ContextDelete is a wrapper function to Context.Delete(...). The argument ctx provides the Lua context for the underlying Lua function.
func ContextGet ¶
func ContextGet(ctx *Context) lua.LGFunction
ContextGet is a wrapper function to Context.Get(...). The argument ctx provides the Lua context for the underlying Lua function.
func ContextSet ¶
func ContextSet(ctx *Context) lua.LGFunction
ContextSet is a wrapper function to Context.Set(...). The argument ctx provides the Lua context for the underlying Lua function.
func DoCompiledFile ¶
func DoCompiledFile(L *lua.LState, proto *lua.FunctionProto) error
DoCompiledFile takes a FunctionProto, as returned by CompileLua, and runs it in the LState. It is equivalent to calling DoFile on the LState with the original source file.
func LuaTableToMap ¶
LuaTableToMap takes a lua.LTable as input and converts it into a map[any]any. The function iterates over each key-value pair in the table and converts the keys and values into their corresponding Go types. The converted key-value pairs are then added to a new map, which is returned as the result. If the input table is nil, the function returns nil.
func MapToLuaTable ¶
MapToLuaTable takes an *lua.LState and a map[any]any as input and converts it into a *lua.LTable. The function iterates over each key-value pair in the map and converts the keys and values into their corresponding lua.LValue types. The converted key-value pairs are then added to a new *lua.LTable, which is returned as the result. If the input map is nil, the function returns nil.
func NewLStateWithDefaultLibraries ¶
NewLStateWithDefaultLibraries initializes a new Lua state with default libraries. It creates a new instance of *lua.LState using lua.NewState(). It then loads the libraries using libs.Preload() and gluacrypto.Preload(). Finally, it returns the initialized Lua state. Usage: L := NewLStateWithDefaultLibraries() Note: The returned Lua state is not thread-safe. It is recommended to use a state pool for managing Lua states in a concurrent environment.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a system-wide Lua context designed to exchange Lua LValues between all Lua levels. Even it implements all methodes from Context, its use is limitted to data exchange. It can not be used to abort running threads. Usage of this context is thread safe.
func (*Context) Get ¶
Get returns the lua.LValue value aquired by key from the Lua Context. If no key was found, it returns nil.
type CustomLogKeyValue ¶
type CustomLogKeyValue []any
type LStateProvider ¶
LStateProvider is a function type that returns a pointer to a lua.LState. It represents a provider function that can be used to create new lua.LState instances.
type LuaBaseStatePool ¶
type LuaBaseStatePool interface { // Get retrieves a Lua state from the pool. Get() *lua.LState // Put returns a Lua state to the pool. Put(L *lua.LState) // Shutdown closes all the Lua states in the pool. Shutdown() // LogStatistics logs debugging information about the pool. LogStatistics(poolName string) }
LuaBaseStatePool is an interface for managing a pool of Lua state instances. If there are no available states in the pool, a new state is created.
func NewLuaStatePool ¶
func NewLuaStatePool() LuaBaseStatePool
NewLuaStatePool initializes a new Lua state pool. It creates a new instance of LuaStatePool with the New function set to NewLStateWithDefaultLibraries. It then calls InitializeStatePool to initialize the pool and return the initialized pool. Usage: luaPool := NewLuaStatePool()
type LuaStatePool ¶
type LuaStatePool struct { Mu sync.Mutex New LStateProvider MaxStates int // Maximum allowed states in the pool Cond sync.Cond // A condition variable to signal availability of Lua states in the pool // contains filtered or unexported fields }
LuaStatePool is a type for managing a pool of Lua state instances. The pool uses a sync.Mutex to ensure safe concurrent access. The saved field is a slice of *lua.LState, which holds the available Lua states in the pool. The New field is an LStateProvider function, which is used to create new Lua states when the pool is empty.
func (*LuaStatePool) Get ¶
func (pl *LuaStatePool) Get() *lua.LState
Get returns a Lua state from the pool. It locks the mutex of the LuaStatePool to ensure thread safety. If there are no saved Lua states in the pool, it calls the New function of the LuaStatePool to create a new Lua state. Otherwise, it retrieves the last saved Lua state from the pool and removes it from the slice. Finally, it returns the retrieved Lua state.
func (*LuaStatePool) InitializeStatePool ¶
func (pl *LuaStatePool) InitializeStatePool() *LuaStatePool
InitializeStatePool initializes the state pool. If the pool is nil, it returns nil. It creates a new slice with a capacity of 4 for storing Lua states. It updates the saved field of the pool with the new slice. Finally, it returns the pool.
func (*LuaStatePool) LogStatistics ¶
func (pl *LuaStatePool) LogStatistics(pool string)
LogStatistics logs the statistics of the Lua states in the pool. It calls the DebugModule function from the util package to log the statistics. The module parameter represents the name of the pool. It retrieves the number of Lua states in the pool using the len function. It retrieves the total size of the saved Lua states in the pool using the getLStateSizes function. The DebugModule function logs the number of Lua states in the pool and the size of the saved Lua states. The logging is conditional based on the verbosity level defined in config.EnvConfig.Verbosity.Level.
func (*LuaStatePool) Put ¶
func (pl *LuaStatePool) Put(L *lua.LState)
Put adds a new Lua state to the pool. It is thread-safe and uses mutex locking to ensure that the shared 'saved' slice is not accessed concurrently.
Parameters:
L: The *lua.LState instance to be added to the pool.
Returns:
None
func (*LuaStatePool) Shutdown ¶
func (pl *LuaStatePool) Shutdown()
Shutdown closes all the saved Lua states in the pool. It iterates over each saved Lua state in the slice and calls its Close method to close it.