xlua

package
v0.0.0-...-ae61dc4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TNIL      = C.LUA_TNIL
	TBOOLEAN  = C.LUA_TBOOLEAN
	TNUMBER   = C.LUA_TNUMBER
	TSTRING   = C.LUA_TSTRING
	TTABLE    = C.LUA_TTABLE
	TFUNCTION = C.LUA_TFUNCTION
)
View Source
const (
	AttrMapSet = 1 << 0
	AttrMapGet = 1 << 1
)
View Source
const (
	//限制map元素数量
	MapSizeLimit = 16
)

Variables

View Source
var (
	ErrStepLimit = errors.New("run step arraive limit")
)

Functions

func CallGoFunc

func CallGoFunc(s unsafe.Pointer, f unsafe.Pointer) int

func LuaOnStep

func LuaOnStep(s unsafe.Pointer)

func NewMapContext

func NewMapContext() context.Context

func Panic

func Panic(msg string)

使用:go tool cgo xlua.go 生成导出给c调用

Types

type ILuaState

type ILuaState interface {
	//设置当前步数
	SetStep(step int)
	//关闭状态机
	Close()
	//打开所有标准库
	OpenLibs()
	//加载执行脚本
	Exec(script []byte) error
	//检测脚本语法错误
	Check(script []byte) (err error)
	//获取环境
	Context() context.Context
	//注册全局函数,函数不能引用其他go指针数据
	SetFunc(name string, fn LuaFunc) ILuaState
	//设置执行步限制
	SetLimit(limit int) ILuaState
	//获取当前执行步数
	GetStep() int
	//global
	SetGlobal(name string) ILuaState
	SetGlobalValue(name string, v interface{}) ILuaState
	GetGlobal(name string) int
	GetTop() int
	SetTop(idx int)
	Pop(idx int)
	//get stack
	GetType(idx int) int
	ToStr(idx int) string
	ToInt(idx int) int64
	ToFloat(idx int) float64
	ToBool(idx int) bool
	ToFunc(idx int) LuaFunc
	ToValue(idx int) interface{}
	IsStr(idx int) bool
	IsInt(idx int) bool
	IsFloat(idx int) bool
	IsBool(idx int) bool
	IsTable(idx int) bool
	IsFunc(idx int) bool
	//push stack
	PushNil()
	PushValue(v interface{})
	PushStr(v string)
	PushInt(v int64)
	PushFloat(v float64)
	PushBool(v bool)
	PushFunc(fn LuaFunc)
	//table
	NewTable() ITable
	//each top stack table
	ForEach(fn func() bool)
	//是否是数组,并返回长度
	IsArray(idx int) (int, bool)
	Next(idx int) int
	TableLen(idx int) int
	SetTable(idx int)
	SetField(idx int, key string)
	GetTable(idx int) int
	GetField(idx int, key string) int
	//作为对象设置table值
	SetValue(idx int, k string, v interface{})
	GetValue(idx int, k string) interface{}
	//做为数组设置table值
	SetArray(idx int, k int, v interface{})
	GetArray(idx int, k int) interface{}
	//对idx位置的table操作
	ToTable(idx int) ITable
}

func NewLuaState

func NewLuaState(ctx context.Context, exp time.Duration, attr ...int) ILuaState

type ITable

type ITable interface {
	Set(k interface{}, v interface{}) ITable
	Get(k interface{}) interface{}
	ForEach(fn func() bool)
	IsArray(lp ...*int) bool
	Append(v interface{}) ITable
}

type LuaFunc

type LuaFunc func(l ILuaState) int

Jump to

Keyboard shortcuts

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