83 lines
2.2 KiB
Markdown
83 lines
2.2 KiB
Markdown
# API Quick Reference
|
|
|
|
## Core State
|
|
- New(openLibs ...bool) *State
|
|
- Close()
|
|
- Cleanup()
|
|
|
|
## Stack
|
|
- GetTop() int
|
|
- SetTop(index int)
|
|
- Pop(n int)
|
|
- PushCopy(index int)
|
|
- Remove(index int)
|
|
|
|
## Type Checks
|
|
- GetType(index int) LuaType
|
|
- IsNil/IsBoolean/IsNumber/IsString/IsTable/IsFunction(index int) bool
|
|
|
|
## Values
|
|
- ToString/ToNumber/ToBoolean(index int) T
|
|
- ToValue(index int) (any, error)
|
|
- ToTable(index int) (any, error)
|
|
- PushNil/PushBoolean/PushNumber/PushString/PushValue()
|
|
|
|
## Tables
|
|
- NewTable()
|
|
- CreateTable(narr, nrec int)
|
|
- GetTable/SetTable(index int)
|
|
- GetField/SetField(index int, key string)
|
|
- GetFieldString/Number/Bool/Table(index int, key string, default T) T
|
|
- GetTableLength(index int) int
|
|
- Next(index int) bool
|
|
- ForEachTableKV/ForEachArray(index int, fn func)
|
|
- NewTableBuilder() *TableBuilder
|
|
|
|
## Functions
|
|
- RegisterGoFunction(name string, fn GoFunction) error
|
|
- UnregisterGoFunction(name string)
|
|
- PushGoFunction(fn GoFunction) error
|
|
- Call(nargs, nresults int) error
|
|
- CallGlobal(name string, args ...any) ([]any, error)
|
|
|
|
## Globals
|
|
- GetGlobal/SetGlobal(name string)
|
|
|
|
## Execution
|
|
- LoadString/LoadFile(source string) error
|
|
- DoString/DoFile(source string) error
|
|
- Execute(code string) (int, error)
|
|
- ExecuteWithResult(code string) (any, error)
|
|
- BatchExecute(statements []string) error
|
|
|
|
## Bytecode
|
|
- CompileBytecode(code, name string) ([]byte, error)
|
|
- LoadBytecode(bytecode []byte, name string) error
|
|
- RunBytecode() error
|
|
- RunBytecodeWithResults(nresults int) error
|
|
- LoadAndRunBytecode(bytecode []byte, name string) error
|
|
- LoadAndRunBytecodeWithResults(bytecode []byte, name string, nresults int) error
|
|
- CompileAndRun(code, name string) error
|
|
|
|
## Validation
|
|
- CheckArgs(specs ...ArgSpec) error
|
|
- CheckMinArgs/CheckExactArgs(n int) error
|
|
- SafeToString/Number/Table(index int) (T, error)
|
|
|
|
## Error Handling
|
|
- PushError(format string, args ...any) int
|
|
- GetStackTrace() string
|
|
- GetErrorInfo(context string) *LuaError
|
|
- CreateLuaError(code int, context string) *LuaError
|
|
|
|
## Package
|
|
- SetPackagePath/AddPackagePath(path string) error
|
|
|
|
## Metatable
|
|
- SetMetatable(index int)
|
|
- GetMetatable(index int) bool
|
|
|
|
## Constants
|
|
- TypeNil/Boolean/Number/String/Table/Function/UserData/Thread
|
|
- LUA_MINSTACK/MAXSTACK/REGISTRYINDEX/GLOBALSINDEX
|