lua

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package lua provides a wrapper around gopher-lua to easily enable Lua scripting support in Go applications. See New() for initialisation of Lua instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lua

type Lua struct {
	// contains filtered or unexported fields
}

Lua is a wrapper around lua-state and provides functions for managing state and executing lua code.

func New

func New(opts ...Option) (*Lua, error)

New returns a new Lua instance initialised. Options can be provided to bind globals, register modules etc.

func (*Lua) Call

func (l *Lua) Call(name string, args ...interface{}) (lua.LValue, error)

Call a lua function by its name. Args are automatically converted to appropriate types using the Luar library

func (*Lua) Destroy

func (l *Lua) Destroy()

Destroy releases all resources held by the lua state and marks the instance closed for usage.

func (*Lua) Execute

func (l *Lua) Execute(src string) error

Execute the given lua script string. Use Call() for calling a function for result.

func (*Lua) ExecuteFile

func (l *Lua) ExecuteFile(fileName string) error

ExecuteFile reads and executes the lua file. Use Call() for calling a function for result.

type Option

type Option func(l *Lua) error

Option can be provided to New() to customise initialization of Lua state.

func Globals

func Globals(vals map[string]interface{}) Option

Globals sets all values in the map as global variables in the lua state. See Module() to create a module from the map.

func Module

func Module(name string, structOrMap interface{}) Option

Module defines a Lua module with public struct fields and methods exported. Use Globals() if you need to set the struct or the map as a single value.

func Path

func Path(dirs ...string) Option

Path appends the given directories to LUA_PATH in correct format.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets a context to be used by the lua state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL