api

package
v0.0.0-...-701c767 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LUA_TNONE = iota - 1 // -1
	LUA_TNIL
	LUA_TBOOLEAN
	LUA_TLIGHTUSERDATA
	LUA_TNUMBER
	LUA_TSTRING
	LUA_TTABLE
	LUA_TFUNCTION
	LUA_TUSERDATA
	LUA_TTHREAD
)

与basic types 对应的有typeOf API

basic types
View Source
const (
	LUA_OPADD  = iota // +
	LUA_OPSUB         // -
	LUA_OPMUL         // *
	LUA_OPMOD         // %
	LUA_OPPOW         // ^
	LUA_OPDIV         // /
	LUA_OPIDIV        // //
	LUA_OPBAND        // &
	LUA_OPBOR         // |
	LUA_OPBXOR        // ~
	LUA_OPSHL         // <<
	LUA_OPSHR         // >>
	LUA_OPUNM         // -
	LUA_OPBNOT        // ~

)

arithmetic functions

View Source
const (
	LUA_OPEQ = iota // ==
	LUA_OPLT        // <
	LUA_OPLE        // <=
)

comparsion functions

View Source
const (
	LUA_OK = iota
	LUA_YIELD
	LUA_ERRRUN
	LUA_ERRSYNTAX
	LUA_ERRMEM
	LUA_ERRGCMM
	LUA_ERRERR
	LUA_ERRFILE
)

thread status

View Source
const LUAI_MAXSTACK = 1000000
View Source
const LUA_MINSTACK = 20

const (

LUA_MINSTACK            = 20
LUA_MAXSTACK            = 1000000
LUA_REGISTRYINDEX       = -LUA_MAXSTACK - 100
LUA_RIDX_GLOBALS  int64 = 2

)

View Source
const LUA_REGISTRYINDEX = -LUAI_MAXSTACK - 1000
View Source
const LUA_RIDX_GLOBALS int64 = 2

Variables

This section is empty.

Functions

func LuaUpvalueIndex

func LuaUpvalueIndex(i int) int

Types

type ArithOp

type ArithOp = int

type CompareOp

type CompareOp = int

type GoFunction

type GoFunction func(LuaState) int

type LuaState

type LuaState interface {
	/* basic stack manipulation */
	GetTop() int
	AbsIndex(idx int) int
	CheckStack(n int) bool
	Pop(n int)
	Copy(fromIdx, toIdx int)
	PushValue(idx int)
	Replace(idx int)
	Insert(idx int)
	Remove(idx int)
	Rotate(idx, n int)
	SetTop(idx int)
	/* access functions (stack -> Go) */
	TypeName(tp LuaType) string
	Type(idx int) LuaType
	IsNone(idx int) bool
	IsNil(idx int) bool
	IsNoneOrNil(idx int) bool
	IsBoolean(idx int) bool
	IsInteger(idx int) bool
	IsNumber(idx int) bool
	IsString(idx int) bool
	IsTable(idx int) bool
	IsThread(idx int) bool
	IsFunction(idx int) bool
	IsGoFunction(idx int) bool
	ToBoolean(idx int) bool
	ToInteger(idx int) int64
	ToIntegerX(idx int) (int64, bool)
	ToNumber(idx int) float64
	ToNumberX(idx int) (float64, bool)
	ToString(idx int) string
	ToStringX(idx int) (string, bool)
	ToGoFunction(idx int) GoFunction
	/* push functions (Go -> stack) */
	PushNil()
	PushBoolean(b bool)
	PushInteger(n int64)
	PushNumber(n float64)
	PushString(s string)
	PushGoFunction(f GoFunction)
	PushGoClosure(f GoFunction, n int)
	PushGlobalTable()
	/* Comparison and arithmetic functions */
	Arith(op ArithOp)
	Compare(idx1, idx2 int, op CompareOp) bool
	/* get functions (Lua -> stack) */
	NewTable()
	CreateTable(nArr, nRec int)
	GetTable(idx int) LuaType
	GetField(idx int, k string) LuaType
	GetI(idx int, i int64) LuaType
	RawGetI(idx int, i int64) LuaType
	RawGet(idx int) LuaType
	GetGlobal(name string) LuaType
	GetMetatable(idx int) bool
	/* set functions (stack -> Lua) */
	SetTable(idx int)
	SetField(idx int, k string)
	SetI(idx int, i int64)
	RawSetI(idx int, i int64)
	RawSet(idx int)
	SetGlobal(name string)
	Register(name string, f GoFunction)
	SetMetatable(idx int)
	/* miscellaneous functions */
	Len(idx int)
	Concat(n int)
	RawLen(idx int) uint
	Next(idx int) bool
	Error() int
	/* load and call functions (load and run Lua code) */
	Load(chunk []byte, chunkName, mod string) int
	Call(nArgs, nResults int)
	PCall(nArgs, nResults, msgh int) int
}

type LuaType

type LuaType = int

type LuaVM

type LuaVM interface {
	LuaState
	PC() int          // 返回当前PC 测试时使用
	AddPC(n int)      // 修改PC 用于实现跳转指令
	Fetch() uint32    // 取出当前指令,将PC指向下一条指令
	GetConst(idx int) // 将指定常量推入栈顶
	GetRK(rk int)     // 将指定常量或栈值推入栈顶
	RegisterCount() int
	LoadVararg(n int)
	LoadProto(idx int)
	CloseUpvalues(a int)
}

为了不再增加LUA API 方法,我们引入一个新的接口LuaVM 用来拓展LuaState接口

Jump to

Keyboard shortcuts

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