luajit

package module
v0.0.0-...-0230a3b Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: MIT Imports: 5 Imported by: 0

README

LuaJIT-to-Go

Go wrapper for LuaJIT.

Documentation

Index

Constants

View Source
const (
	LUA_MINSTACK      = 20      // Minimum Lua stack size
	LUA_MAXSTACK      = 1000000 // Maximum Lua stack size
	LUA_REGISTRYINDEX = -10000  // Pseudo-index for the Lua registry
	LUA_GLOBALSINDEX  = -10002  // Pseudo-index for globals table
)

Stack management constants from lua.h

Variables

This section is empty.

Functions

This section is empty.

Types

type GoFunction

type GoFunction func(*State) int

type LuaError

type LuaError struct {
	Code    int
	Message string
}

LuaError represents an error from the Lua state

func (*LuaError) Error

func (e *LuaError) Error() string

type LuaType

type LuaType int

LuaType represents Lua value types

const (
	// These constants must match lua.h's LUA_T* values
	TypeNone          LuaType = -1
	TypeNil           LuaType = 0
	TypeBoolean       LuaType = 1
	TypeLightUserData LuaType = 2
	TypeNumber        LuaType = 3
	TypeString        LuaType = 4
	TypeTable         LuaType = 5
	TypeFunction      LuaType = 6
	TypeUserData      LuaType = 7
	TypeThread        LuaType = 8
)

func (LuaType) String

func (t LuaType) String() string

String returns the string representation of the Lua type

type State

type State struct {
	L *C.lua_State
	// contains filtered or unexported fields
}

State represents a Lua state with configurable stack safety

func New

func New() *State

New creates a new Lua state with minimal stack checking

func NewSafe

func NewSafe() *State

NewSafe creates a new Lua state with full stack safety guarantees

func (*State) AddPackagePath

func (s *State) AddPackagePath(path string) error

func (*State) Cleanup

func (s *State) Cleanup()

func (*State) Close

func (s *State) Close()

Close closes the Lua state

func (*State) DoFile

func (s *State) DoFile(filename string) error

DoFile executes a Lua file with appropriate stack management

func (*State) DoString

func (s *State) DoString(str string) error

DoString executes a Lua string with appropriate stack management

func (*State) GetField

func (s *State) GetField(index int, key string)

GetField gets a field from a table with cached absolute index

func (*State) GetGlobal

func (s *State) GetGlobal(name string)

GetGlobal gets a global variable and pushes it onto the stack

func (*State) GetTable

func (s *State) GetTable(index int)

GetTable gets a table field with cached absolute index

func (*State) GetTableLength

func (s *State) GetTableLength(index int) int

func (*State) GetTop

func (s *State) GetTop() int

func (*State) GetType

func (s *State) GetType(index int) LuaType

func (*State) IsFunction

func (s *State) IsFunction(index int) bool

func (*State) IsTable

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

func (*State) NewTable

func (s *State) NewTable()

NewTable creates a new table and pushes it onto the stack

func (*State) Pop

func (s *State) Pop(n int)

func (*State) PushBoolean

func (s *State) PushBoolean(b bool)

func (*State) PushGoFunction

func (s *State) PushGoFunction(fn GoFunction) error

func (*State) PushNil

func (s *State) PushNil()

func (*State) PushNumber

func (s *State) PushNumber(n float64)

func (*State) PushString

func (s *State) PushString(str string)

func (*State) PushTable

func (s *State) PushTable(table map[string]interface{}) error

PushTable pushes a Go map onto the Lua stack as a table with stack checking

func (*State) PushValue

func (s *State) PushValue(v interface{}) error

PushValue pushes a Go value onto the stack

func (*State) RegisterGoFunction

func (s *State) RegisterGoFunction(name string, fn GoFunction) error

func (*State) Remove

func (s *State) Remove(index int)

Remove removes element with cached absolute index

func (*State) SetField

func (s *State) SetField(index int, key string)

SetField sets a field in a table at the given index with cached absolute index

func (*State) SetGlobal

func (s *State) SetGlobal(name string)

SetGlobal sets a global variable from the value at the top of the stack

func (*State) SetPackagePath

func (s *State) SetPackagePath(path string) error

func (*State) SetTable

func (s *State) SetTable(index int)

SetTable sets a table field with cached absolute index

func (*State) ToBoolean

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

func (*State) ToNumber

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

func (*State) ToString

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

func (*State) ToTable

func (s *State) ToTable(index int) (map[string]interface{}, error)

ToTable converts a Lua table to a Go map

func (*State) ToValue

func (s *State) ToValue(index int) (interface{}, error)

ToValue converts a Lua value to a Go value

func (*State) UnregisterGoFunction

func (s *State) UnregisterGoFunction(name string)

type TableValue

type TableValue interface {
	~string | ~float64 | ~bool | ~int | ~map[string]interface{} | ~[]float64 | ~[]interface{}
}

TableValue represents any value that can be stored in a Lua table

Jump to

Keyboard shortcuts

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