lua

package module
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 29 Imported by: 4

README

Lua虚拟机

    
    // 创建虚拟机 
    co := lua.NewState()
    co.OpenLibs()
	co.dofile("test.lua")
    co.SetGlobal("a", 1)
	

参考

项目内核参照了以下项目:

Documentation

Overview

GopherLua: VM and compiler for Lua in Go

Index

Constants

View Source
const (
	VarArgHasArg   uint8 = 1
	VarArgIsVarArg uint8 = 2
	VarArgNeedsArg uint8 = 4
)
View Source
const (
	// BaseLibName is here for consistency; the base functions have no namespace/library.
	BaseLibName = ""
	// LoadLibName is here for consistency; the loading system has no namespace/library.
	LoadLibName = "package"
	// TabLibName is the name of the table Library.
	TabLibName = "table"
	// IoLibName is the name of the io Library.
	IoLibName = "io"
	// OsLibName is the name of the os Library.
	OsLibName = "os"
	// StringLibName is the name of the string Library.
	StringLibName = "string"
	// MathLibName is the name of the math Library.
	MathLibName = "math"
	// DebugLibName is the name of the debug Library.
	DebugLibName = "debug"
	// ChannelLibName is the name of the channel Library.
	ChannelLibName = "channel"
	// CoroutineLibName is the name of the coroutine Library.
	CoroutineLibName = "coroutine"
)
View Source
const (
	OP_MOVE     int = iota /*      A B     R(A) := R(B)                            */
	OP_MOVEN               /*      A B     R(A) := R(B); followed by R(C) MOVE ops */
	OP_LOADK               /*     A Bx    R(A) := Kst(Bx)                          */
	OP_LOADBOOL            /*  A B C   R(A) := (Bool)B; if (C) pc++                */
	OP_LOADNIL             /*   A B     R(A) := ... := R(B) := nil                 */
	OP_GETUPVAL            /*  A B     R(A) := UpValue[B]                          */

	OP_GETGLOBAL  /* A Bx    R(A) := Gbl[Kst(Bx)]                            */
	OP_GETTABLE   /*  A B C   R(A) := R(B)[RK(C)]                             */
	OP_GETTABLEKS /*  A B C   R(A) := R(B)[RK(C)] ; RK(C) is constant string */

	OP_SETGLOBAL  /* A Bx    Gbl[Kst(Bx)] := R(A)                            */
	OP_SETUPVAL   /*  A B     UpValue[B] := R(A)                              */
	OP_SETTABLE   /*  A B C   R(A)[RK(B)] := RK(C)                            */
	OP_SETTABLEKS /*  A B C   R(A)[RK(B)] := RK(C) ; RK(B) is constant string */

	OP_NEWTABLE /*  A B C   R(A) := {} (size = BC)                         */

	OP_SELF /*      A B C   R(A+1) := R(B); R(A) := R(B)[RK(C)]             */

	OP_ADD /*       A B C   R(A) := RK(B) + RK(C)                           */
	OP_SUB /*       A B C   R(A) := RK(B) - RK(C)                           */
	OP_MUL /*       A B C   R(A) := RK(B) * RK(C)                           */
	OP_DIV /*       A B C   R(A) := RK(B) / RK(C)                           */
	OP_MOD /*       A B C   R(A) := RK(B) % RK(C)                           */
	OP_POW /*       A B C   R(A) := RK(B) ^ RK(C)                           */
	OP_UNM /*       A B     R(A) := -R(B)                                   */
	OP_NOT /*       A B     R(A) := not R(B)                                */
	OP_LEN /*       A B     R(A) := length of R(B)                          */

	OP_CONCAT /*    A B C   R(A) := R(B).. ... ..R(C)                       */

	OP_JMP /*       sBx     pc+=sBx                                 */

	OP_EQ /*        A B C   if ((RK(B) == RK(C)) ~= A) then pc++            */
	OP_LT /*        A B C   if ((RK(B) <  RK(C)) ~= A) then pc++            */
	OP_LE /*        A B C   if ((RK(B) <= RK(C)) ~= A) then pc++            */

	OP_TEST    /*      A C     if not (R(A) <=> C) then pc++                   */
	OP_TESTSET /*   A B C   if (R(B) <=> C) then R(A) := R(B) else pc++     */

	OP_CALL     /*      A B C   R(A) ... R(A+C-2) := R(A)(R(A+1) ... R(A+B-1)) */
	OP_TAILCALL /*  A B C   return R(A)(R(A+1) ... R(A+B-1))              */
	OP_RETURN   /*    A B     return R(A) ... R(A+B-2)      (see note)      */

	OP_FORLOOP /*   A sBx   R(A)+=R(A+2);
	     if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
	OP_FORPREP /*   A sBx   R(A)-=R(A+2); pc+=sBx                           */

	OP_TFORLOOP /*  A C     R(A+3) ... R(A+3+C) := R(A)(R(A+1) R(A+2));
	    if R(A+3) ~= nil then { pc++; R(A+2)=R(A+3); }  */
	OP_SETLIST /*   A B C   R(A)[(C-1)*FPF+i] := R(A+i) 1 <= i <= B        */

	OP_CLOSE   /*     A       close all variables in the stack up to (>=) R(A)*/
	OP_CLOSURE /*   A Bx    R(A) := closure(KPROTO[Bx] R(A) ... R(A+n))  */

	OP_VARARG /*     A B     R(A) R(A+1) ... R(A+B-1) = vararg            */

	OP_NOP /* NOP */
)
View Source
const (
	M0 int = iota
	M1
	M2
	M3
	M4
	M5
	M6
)
View Source
const (
	EmptyString = LString("")
)
View Source
const EnvironIndex = -10001
View Source
const FramesPerSegment = 8

FramesPerSegment should be a power of 2 constant for performance reasons. It will allow the go compiler to change the divs and mods into bitshifts. Max is 256 due to current use of uint8 to count how many frames in a segment are used.

View Source
const GlobalsIndex = -10002
View Source
const LNumberBit = 64
View Source
const LNumberScanFormat = "%f"
View Source
const LuaVersion = "Lua 5.1"
View Source
const MultRet = -1
View Source
const PackageAuthors = "Yusuke Inuzuka"
View Source
const PackageCopyRight = PackageName + " " + PackageVersion + " Copyright (C) 2015 -2017 " + PackageAuthors
View Source
const PackageName = "GopherLua"
View Source
const PackageVersion = "0.1"
View Source
const RegistryIndex = -10000

Variables

View Source
var (
	InvalidFormat = errors.New("invalid format")
	InvalidIP     = errors.New("invalid ip addr")
	InvalidPort   = errors.New("expect check socket err: port <1 or port > 65535")
)
View Source
var (
	Esc       = []byte{'\\', '\\'}
	CR        = []byte{'\\', '\r'}
	CN        = []byte{'\\', '\n'}
	CT        = []byte{'\\', '\t'}
	Quotation = []byte{'\\', '"'}
)
View Source
var (
	InvalidVelaName  = errors.New("invalid name")
	AlreadyRun       = errors.New("already running")
	NotFoundCode     = errors.New("not found code")
	NotFoundVelaData = errors.New("not found vela data")
	InvalidVelaData  = errors.New("invalid vela data")
	InvalidTree      = errors.New("invalid tree")
	NotFoundTree     = errors.New("not found tree")
)
View Source
var CallStackSize = 256
View Source
var CompatVarArg = true
View Source
var False = []byte("false")
View Source
var FieldsPerFlush = 50
View Source
var LFalse = LBool(false)
View Source
var LNil = LValue(&LNilType{})
View Source
var LTrue = LBool(true)
View Source
var LuaDirSep string
View Source
var LuaExecDir = "!"
View Source
var LuaIgMark = "-"
View Source
var LuaLDir string
View Source
var LuaOS string
View Source
var LuaPath = "LUA_PATH"
View Source
var LuaPathDefault string
View Source
var LuaPathMark = "?"
View Source
var LuaPathSep = ";"
View Source
var MaxArrayIndex = 67108864
View Source
var MaxTableGetLoop = 100
View Source
var RegistryGrowStep = 32
View Source
var RegistrySize = 256 * 20
View Source
var True = []byte("true")
View Source
var VelaStateValue = [...]string{"init", "run", "error", "close", "panic", "private", "mode"}

Functions

func B2S

func B2S(b []byte) string

func CheckBool

func CheckBool(L *LState, lv LValue) bool

func CheckInt

func CheckInt(L *LState, lv LValue) int

func CheckInt64

func CheckInt64(L *LState, lv LValue) int64

func CheckIntOrDefault

func CheckIntOrDefault(L *LState, lv LValue, d int) int

func CheckSocket

func CheckSocket(v string) error

func CheckString

func CheckString(L *LState, lv LValue) string

func FileSuffix

func FileSuffix(path string) string

func HijackTable added in v1.5.0

func HijackTable(fsm *CallFrameFSM) bool

func IsChar

func IsChar(ch byte) bool

func IsFalse

func IsFalse(v LValue) bool

func IsInt

func IsInt(v LValue) int

func IsIntChar

func IsIntChar(ch byte) bool

func IsNull

func IsNull(v []byte) bool

func IsString

func IsString(v LValue) string

func IsTrue

func IsTrue(v LValue) bool

func L2SS

func L2SS(L *LState) []string

func LVAsBool

func LVAsBool(v LValue) bool

LVIsFalse returns false if a given LValue is a nil or false otherwise true.

func LVAsString

func LVAsString(v LValue) string

LVAsString returns string representation of a given LValue if the LValue is a string or number, otherwise an empty string.

func LVCanConvToString

func LVCanConvToString(v LValue) bool

LVCanConvToString returns true if a given LValue is a string or number otherwise false.

func LVIsFalse

func LVIsFalse(v LValue) bool

LVIsFalse returns true if a given LValue is a nil or false otherwise false.

func OpenBase

func OpenBase(L *LState) int

func OpenChannel

func OpenChannel(L *LState) int

func OpenCoroutine

func OpenCoroutine(L *LState) int

func OpenDebug

func OpenDebug(L *LState) int

func OpenIo

func OpenIo(L *LState) int

func OpenMath

func OpenMath(L *LState) int

func OpenOs

func OpenOs(L *LState) int

func OpenPackage

func OpenPackage(L *LState) int

func OpenString

func OpenString(L *LState) int

func OpenTable

func OpenTable(L *LState) int

func S2B

func S2B(s string) (b []byte)

func UpvalueIndex

func UpvalueIndex(i int) int

func VelaNameE

func VelaNameE(v string) error

func WithFunc

func WithFunc(gn LGFunction) func(e *Export)

func WithIndex

func WithIndex(ex func(*LState, string) LValue) func(e *Export)

func WithNewIndex

func WithNewIndex(nex func(*LState, string, LValue)) func(e *Export)

func WithTable

func WithTable(kv UserKV) func(e *Export)

Types

type ApiError

type ApiError struct {
	Type       ApiErrorType
	Object     LValue
	StackTrace string
	// Underlying error. This attribute is set only if the Type is ApiErrorFile or ApiErrorSyntax
	Cause error
}

func (*ApiError) Error

func (e *ApiError) Error() string

type ApiErrorType

type ApiErrorType int
const (
	ApiErrorSyntax ApiErrorType = iota
	ApiErrorFile
	ApiErrorRun
	ApiErrorError
	ApiErrorPanic
)

type CallBackFunction

type CallBackFunction func(LValue) (stop bool)

type CallFrameFSM added in v1.5.0

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

func (*CallFrameFSM) Index added in v1.5.0

func (fsm *CallFrameFSM) Index(hook func(*LState, string) LValue) bool

func (*CallFrameFSM) Meta added in v1.5.0

func (fsm *CallFrameFSM) Meta(hook func(*LState, LValue) LValue) bool

func (*CallFrameFSM) NewIndex added in v1.5.0

func (fsm *CallFrameFSM) NewIndex(hook func(*LState, string, LValue)) bool

func (*CallFrameFSM) NewMeta added in v1.5.0

func (fsm *CallFrameFSM) NewMeta(hook func(*LState, LValue, LValue)) bool

func (*CallFrameFSM) OpCode added in v1.5.0

func (fsm *CallFrameFSM) OpCode() int

type Closer

type Closer interface {
	VelaEntry
	io.Closer
}

func CheckCloser

func CheckCloser(val *VelaData) Closer

type CompileError

type CompileError struct {
	Line    int
	Message string
	// contains filtered or unexported fields
}

func (*CompileError) Error

func (e *CompileError) Error() string

type Console

type Console interface {
	Println(string)
	Printf(string, ...interface{})
	Invalid(string, ...interface{})
}

type DbgCall

type DbgCall struct {
	Name string
	Pc   int
}

type DbgLocalInfo

type DbgLocalInfo struct {
	Name    string
	StartPc int
	EndPc   int
}

type Debug

type Debug struct {
	Name            string
	What            string
	Source          string
	CurrentLine     int
	NUpvalues       int
	LineDefined     int
	LastLineDefined int
	// contains filtered or unexported fields
}

func (*Debug) Sample

func (dbg *Debug) Sample() *Sample

type ExData

type ExData []ExDataKV

func (*ExData) Del

func (ed *ExData) Del(key string)

func (*ExData) Get

func (ed *ExData) Get(key string) interface{}

func (*ExData) Len

func (ed *ExData) Len() int

func (*ExData) Less

func (ed *ExData) Less(i, j int) bool

func (*ExData) Reset

func (ed *ExData) Reset()

func (*ExData) Set

func (ed *ExData) Set(key string, value interface{})

func (*ExData) Swap

func (ed *ExData) Swap(i, j int)

type ExDataKV

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

type Export

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

func NewExport

func NewExport(name string, opt ...func(*Export)) Export

func (Export) AssertFloat64

func (e Export) AssertFloat64() (float64, bool)

func (Export) AssertFunction

func (e Export) AssertFunction() (*LFunction, bool)

func (Export) AssertString

func (e Export) AssertString() (string, bool)

func (Export) Hijack added in v1.5.0

func (e Export) Hijack(*CallFrameFSM) bool

func (Export) Index

func (e Export) Index(L *LState, key string) LValue

func (Export) NewIndex

func (e Export) NewIndex(L *LState, key string, val LValue)

func (Export) String

func (e Export) String() string

func (Export) Type

func (e Export) Type() LValueType

type FunctionProto

type FunctionProto struct {
	SourceName         string
	LineDefined        int
	LastLineDefined    int
	NumUpvalues        uint8
	NumParameters      uint8
	IsVarArg           uint8
	NumUsedRegisters   uint8
	Code               []uint32
	Constants          []LValue
	FunctionPrototypes []*FunctionProto

	DbgSourcePositions []int
	DbgLocals          []*DbgLocalInfo
	DbgCalls           []DbgCall
	DbgUpvalues        []string
	// contains filtered or unexported fields
}

func Compile

func Compile(chunk []ast.Stmt, name string) (proto *FunctionProto, err error)

func (*FunctionProto) String

func (fp *FunctionProto) String() string

type Generic added in v1.5.0

type Generic[T any] struct {
	Data T
}

func NewGeneric added in v1.5.0

func NewGeneric[T any](data T) *Generic[T]

func (*Generic[T]) AssertFloat64 added in v1.5.0

func (gen *Generic[T]) AssertFloat64() (float64, bool)

func (*Generic[T]) AssertFunction added in v1.5.0

func (gen *Generic[T]) AssertFunction() (*LFunction, bool)

func (*Generic[T]) AssertString added in v1.5.0

func (gen *Generic[T]) AssertString() (string, bool)

func (*Generic[T]) GobDecode added in v1.5.0

func (gen *Generic[T]) GobDecode(data []byte) error

func (*Generic[T]) GobEncode added in v1.5.0

func (gen *Generic[T]) GobEncode() ([]byte, error)

func (*Generic[T]) Hijack added in v1.5.0

func (gen *Generic[T]) Hijack(fsm *CallFrameFSM) bool

func (*Generic[T]) Index added in v1.5.0

func (gen *Generic[T]) Index(L *LState, key string) LValue

func (*Generic[T]) LValue added in v1.5.0

func (gen *Generic[T]) LValue() (LValue, bool)

func (*Generic[T]) MarshalJSON added in v1.5.0

func (gen *Generic[T]) MarshalJSON() ([]byte, error)

func (*Generic[T]) Meta added in v1.5.0

func (gen *Generic[T]) Meta(L *LState, key LValue) LValue

func (*Generic[T]) NewIndex added in v1.5.0

func (gen *Generic[T]) NewIndex(L *LState, key string, val LValue)

func (*Generic[T]) NewMeta added in v1.5.0

func (gen *Generic[T]) NewMeta(L *LState, key LValue, val LValue)

func (*Generic[T]) String added in v1.5.0

func (gen *Generic[T]) String() string

func (*Generic[T]) ToLValue added in v1.5.0

func (gen *Generic[T]) ToLValue() LValue

func (*Generic[T]) Type added in v1.5.0

func (gen *Generic[T]) Type() LValueType

func (*Generic[T]) UnmarshalJSON added in v1.5.0

func (gen *Generic[T]) UnmarshalJSON(bytes []byte) error

type Global

type Global struct {
	MainThread    *LState
	CurrentThread *LState
	Registry      *LTable
	Global        *LTable
	// contains filtered or unexported fields
}

type GoFuncErr

type GoFuncErr func(...interface{}) error

func (GoFuncErr) AssertFloat64

func (ge GoFuncErr) AssertFloat64() (float64, bool)

func (GoFuncErr) AssertFunction

func (ge GoFuncErr) AssertFunction() (*LFunction, bool)

func (GoFuncErr) AssertString

func (ge GoFuncErr) AssertString() (string, bool)

func (GoFuncErr) Hijack added in v1.5.0

func (ge GoFuncErr) Hijack(*CallFrameFSM) bool

func (GoFuncErr) String

func (ge GoFuncErr) String() string

func (GoFuncErr) Type

func (ge GoFuncErr) Type() LValueType

type GoFuncInt

type GoFuncInt func(...interface{}) int

func (GoFuncInt) AssertFloat64

func (gi GoFuncInt) AssertFloat64() (float64, bool)

func (GoFuncInt) AssertFunction

func (gi GoFuncInt) AssertFunction() (*LFunction, bool)

func (GoFuncInt) AssertString

func (gi GoFuncInt) AssertString() (string, bool)

func (GoFuncInt) Hijack added in v1.5.0

func (gi GoFuncInt) Hijack(*CallFrameFSM) bool

func (GoFuncInt) Peek

func (gi GoFuncInt) Peek() LValue

func (GoFuncInt) String

func (gi GoFuncInt) String() string

func (GoFuncInt) Type

func (gi GoFuncInt) Type() LValueType

type GoFuncStr

type GoFuncStr func(...interface{}) string

func (GoFuncStr) AssertFloat64

func (gs GoFuncStr) AssertFloat64() (float64, bool)

func (GoFuncStr) AssertFunction

func (gs GoFuncStr) AssertFunction() (*LFunction, bool)

func (GoFuncStr) AssertString

func (gs GoFuncStr) AssertString() (string, bool)

func (GoFuncStr) Hijack added in v1.5.0

func (gs GoFuncStr) Hijack(*CallFrameFSM) bool

func (GoFuncStr) String

func (gs GoFuncStr) String() string

func (GoFuncStr) Type

func (gs GoFuncStr) Type() LValueType

type GoFunction

type GoFunction func() error

func (GoFunction) AssertFloat64

func (fn GoFunction) AssertFloat64() (float64, bool)

func (GoFunction) AssertFunction

func (fn GoFunction) AssertFunction() (*LFunction, bool)

func (GoFunction) AssertString

func (fn GoFunction) AssertString() (string, bool)

func (GoFunction) Hijack added in v1.5.0

func (fn GoFunction) Hijack(*CallFrameFSM) bool

func (GoFunction) String

func (fn GoFunction) String() string

func (GoFunction) Type

func (fn GoFunction) Type() LValueType

type IO

type IO interface {
	VelaEntry
	io.Writer
	io.Reader
}

func CheckIO

func CheckIO(val *VelaData) IO

type IndexEx

type IndexEx interface {
	Index(*LState, string) LValue
}

type JsonEncoder

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

func Json

func Json(cap int) *JsonEncoder

func (*JsonEncoder) Arr

func (enc *JsonEncoder) Arr(name string)

func (*JsonEncoder) Bool

func (enc *JsonEncoder) Bool(v bool)

func (*JsonEncoder) Bytes

func (enc *JsonEncoder) Bytes() []byte

func (*JsonEncoder) Char

func (enc *JsonEncoder) Char(ch byte)

func (*JsonEncoder) End

func (enc *JsonEncoder) End(val string)

func (*JsonEncoder) False

func (enc *JsonEncoder) False(key string)

func (*JsonEncoder) Float32

func (enc *JsonEncoder) Float32(f float32)

func (*JsonEncoder) Float64

func (enc *JsonEncoder) Float64(f float64)

func (*JsonEncoder) Insert

func (enc *JsonEncoder) Insert(v []byte)

func (*JsonEncoder) Int

func (enc *JsonEncoder) Int(n int)

func (*JsonEncoder) Join

func (enc *JsonEncoder) Join(key string, v []string)

func (*JsonEncoder) KB

func (enc *JsonEncoder) KB(key string, b bool)

func (*JsonEncoder) KF64

func (enc *JsonEncoder) KF64(key string, v float64)

func (*JsonEncoder) KI

func (enc *JsonEncoder) KI(key string, n int)

func (*JsonEncoder) KL

func (enc *JsonEncoder) KL(key string, n int64)

func (*JsonEncoder) KT

func (enc *JsonEncoder) KT(key string, t time.Time)

func (*JsonEncoder) KUL

func (enc *JsonEncoder) KUL(key string, n uint64)

func (*JsonEncoder) KV

func (enc *JsonEncoder) KV(key string, s interface{})

func (*JsonEncoder) Key

func (enc *JsonEncoder) Key(key string)

func (*JsonEncoder) Len

func (enc *JsonEncoder) Len() int

func (*JsonEncoder) Long

func (enc *JsonEncoder) Long(n int64)

func (*JsonEncoder) Raw

func (enc *JsonEncoder) Raw(key string, val []byte)

func (*JsonEncoder) Reset

func (enc *JsonEncoder) Reset()

func (*JsonEncoder) Tab

func (enc *JsonEncoder) Tab(name string)

func (*JsonEncoder) True

func (enc *JsonEncoder) True(key string)

func (*JsonEncoder) ULong

func (enc *JsonEncoder) ULong(n uint64)

func (*JsonEncoder) Val

func (enc *JsonEncoder) Val(v string)

func (*JsonEncoder) Write

func (enc *JsonEncoder) Write(val []byte)

func (*JsonEncoder) WriteByte

func (enc *JsonEncoder) WriteByte(ch byte)

func (*JsonEncoder) WriteString

func (enc *JsonEncoder) WriteString(val string)

type LBool

type LBool bool

func (LBool) AssertFloat64

func (bl LBool) AssertFloat64() (float64, bool)

func (LBool) AssertFunction

func (bl LBool) AssertFunction() (*LFunction, bool)

func (LBool) AssertString

func (bl LBool) AssertString() (string, bool)

func (LBool) Hijack added in v1.5.0

func (bl LBool) Hijack(*CallFrameFSM) bool

func (LBool) Peek

func (bl LBool) Peek() LValue

func (LBool) String

func (bl LBool) String() string

func (LBool) Type

func (bl LBool) Type() LValueType

type LChannel

type LChannel chan LValue

func (LChannel) AssertFloat64

func (ch LChannel) AssertFloat64() (float64, bool)

func (LChannel) AssertFunction

func (ch LChannel) AssertFunction() (*LFunction, bool)

func (LChannel) AssertString

func (ch LChannel) AssertString() (string, bool)

func (LChannel) Hijack added in v1.5.0

func (ch LChannel) Hijack(*CallFrameFSM) bool

func (LChannel) String

func (ch LChannel) String() string

func (LChannel) Type

func (ch LChannel) Type() LValueType

type LFunction

type LFunction struct {
	IsG       bool
	Env       *LTable
	Proto     *FunctionProto
	GFunction LGFunction
	Upvalues  []*Upvalue
}

func CheckFunction

func CheckFunction(L *LState, lv LValue) *LFunction

func IsFunc

func IsFunc(v LValue) *LFunction

func NewFunction

func NewFunction(gn LGFunction) *LFunction

func (*LFunction) AssertFloat64

func (fn *LFunction) AssertFloat64() (float64, bool)

func (*LFunction) AssertFunction

func (fn *LFunction) AssertFunction() (*LFunction, bool)

func (*LFunction) AssertString

func (fn *LFunction) AssertString() (string, bool)

func (*LFunction) Hijack added in v1.5.0

func (fn *LFunction) Hijack(*CallFrameFSM) bool

func (*LFunction) LocalName

func (fn *LFunction) LocalName(regno, pc int) (string, bool)

func (*LFunction) String

func (fn *LFunction) String() string

func (*LFunction) Type

func (fn *LFunction) Type() LValueType

type LGFunction

type LGFunction func(*LState) int

type LInt

type LInt int

func (LInt) AssertFloat64

func (i LInt) AssertFloat64() (float64, bool)

func (LInt) AssertFunction

func (i LInt) AssertFunction() (*LFunction, bool)

func (LInt) AssertString

func (i LInt) AssertString() (string, bool)

func (LInt) Hijack added in v1.5.0

func (i LInt) Hijack(*CallFrameFSM) bool

func (LInt) String

func (i LInt) String() string

func (LInt) Type

func (i LInt) Type() LValueType

type LInt64

type LInt64 int64

func (LInt64) AssertFloat64

func (i LInt64) AssertFloat64() (float64, bool)

func (LInt64) AssertFunction

func (i LInt64) AssertFunction() (*LFunction, bool)

func (LInt64) AssertString

func (i LInt64) AssertString() (string, bool)

func (LInt64) Hijack added in v1.5.0

func (i LInt64) Hijack(*CallFrameFSM) bool

func (LInt64) String

func (i LInt64) String() string

func (LInt64) Type

func (i LInt64) Type() LValueType

type LNilType

type LNilType struct{}

func (*LNilType) AssertFloat64

func (nl *LNilType) AssertFloat64() (float64, bool)

func (*LNilType) AssertFunction

func (nl *LNilType) AssertFunction() (*LFunction, bool)

func (*LNilType) AssertString

func (nl *LNilType) AssertString() (string, bool)

func (*LNilType) Hijack added in v1.5.0

func (nl *LNilType) Hijack(*CallFrameFSM) bool

func (*LNilType) Peek

func (nl *LNilType) Peek() LValue

func (*LNilType) String

func (nl *LNilType) String() string

func (*LNilType) Type

func (nl *LNilType) Type() LValueType

type LNumber

type LNumber float64

func CheckNumber

func CheckNumber(L *LState, lv LValue) LNumber

func IsNumber

func IsNumber(v LValue) LNumber

func LVAsNumber

func LVAsNumber(v LValue) LNumber

LVAsNumber tries to convert a given LValue to a number.

func (LNumber) AssertFloat64

func (nm LNumber) AssertFloat64() (float64, bool)

func (LNumber) AssertFunction

func (nm LNumber) AssertFunction() (*LFunction, bool)

func (LNumber) AssertString

func (nm LNumber) AssertString() (string, bool)

func (LNumber) Format

func (nm LNumber) Format(f fmt.State, c rune)

fmt.Formatter interface

func (LNumber) Hijack added in v1.5.0

func (nm LNumber) Hijack(*CallFrameFSM) bool

func (LNumber) String

func (nm LNumber) String() string

func (LNumber) Type

func (nm LNumber) Type() LValueType

type LState

type LState struct {
	G       *Global
	Parent  *LState
	Env     *LTable
	Panic   func(*LState)
	Dead    bool
	Options Options

	Exdata  interface{}
	Console Console
	// contains filtered or unexported fields
}

func NewState

func NewState(opts ...Options) *LState

func (*LState) A

func (ls *LState) A() interface{}

func (*LState) ArgError

func (ls *LState) ArgError(n int, message string)

func (*LState) AssertFloat64

func (ls *LState) AssertFloat64() (float64, bool)

func (*LState) AssertFunction

func (ls *LState) AssertFunction() (*LFunction, bool)

func (*LState) AssertString

func (ls *LState) AssertString() (string, bool)

func (*LState) B

func (ls *LState) B() interface{}

func (*LState) C

func (ls *LState) C() interface{}

func (*LState) Call

func (ls *LState) Call(nargs, nret int)

func (*LState) CallByParam

func (ls *LState) CallByParam(cp P, args ...LValue) error

func (*LState) CallMeta

func (ls *LState) CallMeta(obj LValue, event string) LValue

func (*LState) Callback

func (ls *LState) Callback(fn CallBackFunction)

func (*LState) CheckAny

func (ls *LState) CheckAny(n int) LValue

func (*LState) CheckBool

func (ls *LState) CheckBool(n int) bool

func (*LState) CheckChannel

func (ls *LState) CheckChannel(n int) chan LValue

Checks whether the given index is an LChannel and returns this channel.

func (*LState) CheckCodeVM

func (ls *LState) CheckCodeVM(name string) bool

func (*LState) CheckFile

func (ls *LState) CheckFile(n int) string

func (*LState) CheckFunction

func (ls *LState) CheckFunction(n int) *LFunction

func (*LState) CheckIndexEx

func (ls *LState) CheckIndexEx(id int) IndexEx

func (*LState) CheckInt

func (ls *LState) CheckInt(n int) int

func (*LState) CheckInt64

func (ls *LState) CheckInt64(n int) int64

func (*LState) CheckNumber

func (ls *LState) CheckNumber(n int) LNumber

func (*LState) CheckObject

func (ls *LState) CheckObject(n int) LValue

func (*LState) CheckOption

func (ls *LState) CheckOption(n int, options []string) int

func (*LState) CheckSocket

func (ls *LState) CheckSocket(n int) string

func (*LState) CheckSockets

func (ls *LState) CheckSockets(n int) string

func (*LState) CheckString

func (ls *LState) CheckString(n int) string

func (*LState) CheckTable

func (ls *LState) CheckTable(n int) *LTable

func (*LState) CheckThread

func (ls *LState) CheckThread(n int) *LState

func (*LState) CheckType

func (ls *LState) CheckType(n int, typ LValueType)

func (*LState) CheckTypes

func (ls *LState) CheckTypes(n int, typs ...LValueType)

func (*LState) CheckUserData

func (ls *LState) CheckUserData(n int) *LUserData

func (*LState) CheckVelaData

func (ls *LState) CheckVelaData(n int) *VelaData

func (*LState) Close

func (ls *LState) Close()

func (*LState) CodeVM

func (ls *LState) CodeVM() string

func (*LState) Concat

func (ls *LState) Concat(values ...LValue) string

func (*LState) Context

func (ls *LState) Context() context.Context

Context returns the LState's context. To change the context, use WithContext.

func (*LState) Copy

func (ls *LState) Copy(L *LState)

func (*LState) CreateTable

func (ls *LState) CreateTable(acap, hcap int) *LTable

func (*LState) D

func (ls *LState) D() interface{}

func (*LState) DoFile

func (ls *LState) DoFile(path string) error

func (*LState) DoString

func (ls *LState) DoString(source string) error

func (*LState) E

func (ls *LState) E() interface{}

func (*LState) Equal

func (ls *LState) Equal(lhs, rhs LValue) bool

func (*LState) Error

func (ls *LState) Error(lv LValue, level int)

This function is equivalent to lua_error( http://www.lua.org/manual/5.1/manual.html#lua_error ).

func (*LState) FindTable

func (ls *LState) FindTable(obj *LTable, n string, size int) LValue

func (*LState) ForEach

func (ls *LState) ForEach(tb *LTable, cb func(LValue, LValue))

func (*LState) GPCall

func (ls *LState) GPCall(fn LGFunction, data LValue) error

func (*LState) Get

func (ls *LState) Get(idx int) LValue

func (*LState) GetFEnv

func (ls *LState) GetFEnv(obj LValue) LValue

func (*LState) GetField

func (ls *LState) GetField(obj LValue, skey string) LValue

func (*LState) GetGlobal

func (ls *LState) GetGlobal(name string) LValue

func (*LState) GetInfo

func (ls *LState) GetInfo(what string, dbg *Debug, fn LValue) (LValue, error)

func (*LState) GetLocal

func (ls *LState) GetLocal(dbg *Debug, no int) (string, LValue)

func (*LState) GetMetaField

func (ls *LState) GetMetaField(obj LValue, event string) LValue

func (*LState) GetMetatable

func (ls *LState) GetMetatable(obj LValue) LValue

func (*LState) GetStack

func (ls *LState) GetStack(level int) (*Debug, bool)

func (*LState) GetTable

func (ls *LState) GetTable(obj LValue, key LValue) LValue

func (*LState) GetTop

func (ls *LState) GetTop() int

func (*LState) GetTypeMetatable

func (ls *LState) GetTypeMetatable(typ string) LValue

func (*LState) GetUpvalue

func (ls *LState) GetUpvalue(fn *LFunction, no int) (string, LValue)

func (*LState) Hijack added in v1.5.0

func (ls *LState) Hijack(*CallFrameFSM) bool

func (*LState) Insert

func (ls *LState) Insert(value LValue, index int)

func (*LState) IsClosed

func (ls *LState) IsClosed() bool

func (*LState) IsFalse

func (ls *LState) IsFalse(n int) bool

func (*LState) IsFunc

func (ls *LState) IsFunc(n int) *LFunction

func (*LState) IsInt

func (ls *LState) IsInt(n int) int

func (*LState) IsNumber

func (ls *LState) IsNumber(n int) LNumber

func (*LState) IsString

func (ls *LState) IsString(n int) string

func (*LState) IsTrue

func (ls *LState) IsTrue(n int) bool

func (*LState) Keepalive

func (ls *LState) Keepalive()

func (*LState) LessThan

func (ls *LState) LessThan(lhs, rhs LValue) bool

func (*LState) Load

func (ls *LState) Load(reader io.Reader, name string) (*LFunction, error)

func (*LState) LoadFile

func (ls *LState) LoadFile(path string) (*LFunction, error)

func (*LState) LoadString

func (ls *LState) LoadString(source string) (*LFunction, error)

func (*LState) Metadata

func (ls *LState) Metadata(id int) interface{}

func (*LState) NewClosure

func (ls *LState) NewClosure(fn LGFunction, upvalues ...LValue) *LFunction

func (*LState) NewFunction

func (ls *LState) NewFunction(fn LGFunction) *LFunction

func (*LState) NewFunctionFromProto

func (ls *LState) NewFunctionFromProto(proto *FunctionProto) *LFunction

func (*LState) NewTable

func (ls *LState) NewTable() *LTable

func (*LState) NewThread

func (ls *LState) NewThread() (*LState, context.CancelFunc)

NewThread returns a new LState that shares with the original state all global objects. If the original state has context.Context, the new state has a new child context of the original state and this function returns its cancel function.

func (*LState) NewTypeMetatable

func (ls *LState) NewTypeMetatable(typ string) *LTable

func (*LState) NewUserData

func (ls *LState) NewUserData() *LUserData

func (*LState) NewVela

func (ls *LState) NewVela(key string, typeof string) *VelaData

func (*LState) NewVelaData

func (ls *LState) NewVelaData(key string, typeof string) *VelaData

func (*LState) Next

func (ls *LState) Next(tb *LTable, key LValue) (LValue, LValue)

func (*LState) ObjLen

func (ls *LState) ObjLen(v1 LValue) int

func (*LState) OpenLibs

func (ls *LState) OpenLibs()

OpenLibs loads the built-in libraries. It is equivalent to running OpenLoad, then OpenBase, then iterating over the other OpenXXX functions in any order.

func (*LState) OptBool

func (ls *LState) OptBool(n int, d bool) bool

func (*LState) OptChannel

func (ls *LState) OptChannel(n int, ch chan LValue) chan LValue

If the given index is a LChannel, returns this channel. If this argument is absent or is nil, returns ch. Otherwise, raises an error.

func (*LState) OptFunction

func (ls *LState) OptFunction(n int, d *LFunction) *LFunction

func (*LState) OptInt

func (ls *LState) OptInt(n int, d int) int

func (*LState) OptInt64

func (ls *LState) OptInt64(n int, d int64) int64

func (*LState) OptNumber

func (ls *LState) OptNumber(n int, d LNumber) LNumber

func (*LState) OptString

func (ls *LState) OptString(n int, d string) string

func (*LState) OptTable

func (ls *LState) OptTable(n int, d *LTable) *LTable

func (*LState) OptUserData

func (ls *LState) OptUserData(n int, d *LUserData) *LUserData

func (*LState) Output

func (ls *LState) Output(v string)

func (*LState) PCall

func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error)

func (*LState) Pop

func (ls *LState) Pop(n int)

func (*LState) PreloadModule

func (ls *LState) PreloadModule(name string, loader LGFunction)

Set a module loader to the package.preload table.

func (*LState) Push

func (ls *LState) Push(value LValue)

func (*LState) PushAny

func (ls *LState) PushAny(v interface{})

func (*LState) Pushf

func (ls *LState) Pushf(format string, v ...interface{})

func (*LState) RaiseError

func (ls *LState) RaiseError(format string, args ...interface{})

This function is equivalent to luaL_error( http://www.lua.org/manual/5.1/manual.html#luaL_error ).

func (*LState) RawEqual

func (ls *LState) RawEqual(lhs, rhs LValue) bool

func (*LState) RawGet

func (ls *LState) RawGet(tb *LTable, key LValue) LValue

func (*LState) RawGetInt

func (ls *LState) RawGetInt(tb *LTable, key int) LValue

func (*LState) RawSet

func (ls *LState) RawSet(tb *LTable, key LValue, value LValue)

func (*LState) RawSetInt

func (ls *LState) RawSetInt(tb *LTable, key int, value LValue)

func (*LState) Register

func (ls *LState) Register(name string, fn LGFunction)

func (*LState) RegisterModule

func (ls *LState) RegisterModule(name string, funcs map[string]LGFunction) LValue

func (*LState) Remove

func (ls *LState) Remove(index int)

func (*LState) RemoveCallerFrame

func (ls *LState) RemoveCallerFrame() *callFrame

RemoveCallerFrame removes the stack frame above the current stack frame. This is useful in tail calls. It returns the new current frame.

func (*LState) RemoveContext

func (ls *LState) RemoveContext() context.Context

RemoveContext removes the context associated with this LState and returns this context.

func (*LState) Replace

func (ls *LState) Replace(idx int, value LValue)

func (*LState) Resume

func (ls *LState) Resume(th *LState, fn *LFunction, args ...LValue) (ResumeState, error, []LValue)

func (*LState) SetA

func (ls *LState) SetA(v interface{})

func (*LState) SetB

func (ls *LState) SetB(v interface{})

func (*LState) SetC

func (ls *LState) SetC(v interface{})

func (*LState) SetContext

func (ls *LState) SetContext(ctx context.Context)

SetContext set a context ctx to this LState. The provided ctx must be non-nil.

func (*LState) SetD

func (ls *LState) SetD(v interface{})

func (*LState) SetE

func (ls *LState) SetE(v interface{})

func (*LState) SetFEnv

func (ls *LState) SetFEnv(obj LValue, env LValue)

func (*LState) SetField

func (ls *LState) SetField(obj LValue, key string, value LValue)

func (*LState) SetFuncs

func (ls *LState) SetFuncs(tb *LTable, funcs map[string]LGFunction, upvalues ...LValue) *LTable

func (*LState) SetGlobal

func (ls *LState) SetGlobal(name string, value LValue)

func (*LState) SetLocal

func (ls *LState) SetLocal(dbg *Debug, no int, lv LValue) string

func (*LState) SetMetadata

func (ls *LState) SetMetadata(id int, v interface{})

func (*LState) SetMetatable

func (ls *LState) SetMetatable(obj LValue, mt LValue)

func (*LState) SetMx

func (ls *LState) SetMx(mx int)

Set maximum memory size. This function can only be called from the main thread.

func (*LState) SetTable

func (ls *LState) SetTable(obj LValue, key LValue, value LValue)

func (*LState) SetTop

func (ls *LState) SetTop(idx int)

func (*LState) SetUpvalue

func (ls *LState) SetUpvalue(fn *LFunction, no int, lv LValue) string

func (*LState) SetValue

func (ls *LState) SetValue(key interface{}, v interface{})

func (*LState) StackTrace

func (ls *LState) StackTrace(level int) string

func (*LState) Status

func (ls *LState) Status(th *LState) string

func (*LState) String

func (ls *LState) String() string

func (*LState) ToBool

func (ls *LState) ToBool(n int) bool

func (*LState) ToChannel

func (ls *LState) ToChannel(n int) chan LValue

Converts the Lua value at the given acceptable index to the chan LValue.

func (*LState) ToFunction

func (ls *LState) ToFunction(n int) *LFunction

func (*LState) ToInt

func (ls *LState) ToInt(n int) int

func (*LState) ToInt64

func (ls *LState) ToInt64(n int) int64

func (*LState) ToNumber

func (ls *LState) ToNumber(n int) LNumber

func (*LState) ToString

func (ls *LState) ToString(n int) string

func (*LState) ToStringMeta

func (ls *LState) ToStringMeta(lv LValue) LValue

ToStringMeta returns string representation of given LValue. This method calls the `__tostring` meta method if defined.

func (*LState) ToTable

func (ls *LState) ToTable(n int) *LTable

func (*LState) ToThread

func (ls *LState) ToThread(n int) *LState

func (*LState) ToUserData

func (ls *LState) ToUserData(n int) *LUserData

func (*LState) Type

func (ls *LState) Type() LValueType

func (*LState) TypeError

func (ls *LState) TypeError(n int, typ LValueType)

func (*LState) Use

func (ls *LState) Use(value LValue)

func (*LState) Value

func (ls *LState) Value(key interface{}) interface{}

func (*LState) Where

func (ls *LState) Where(level int) string

func (*LState) WithValue

func (ls *LState) WithValue(key interface{}, v interface{}) context.Context

func (*LState) XMoveTo

func (ls *LState) XMoveTo(other *LState, n int)

func (*LState) Yield

func (ls *LState) Yield(values ...LValue) int

type LString

type LString string

func B2L

func B2L(b []byte) LString

func JsonMarshal

func JsonMarshal(L *LState, i interface{}) LString

func S2L

func S2L(s string) LString

func (LString) AssertFloat64

func (st LString) AssertFloat64() (float64, bool)

func (LString) AssertFunction

func (st LString) AssertFunction() (*LFunction, bool)

func (LString) AssertString

func (st LString) AssertString() (string, bool)

func (LString) Format

func (st LString) Format(f fmt.State, c rune)

fmt.Formatter interface

func (LString) Hijack added in v1.5.0

func (st LString) Hijack(*CallFrameFSM) bool

func (LString) String

func (st LString) String() string

func (LString) Type

func (st LString) Type() LValueType

type LTable

type LTable struct {
	Metatable LValue
	// contains filtered or unexported fields
}

func CheckTable

func CheckTable(L *LState, lv LValue) *LTable

func CloneTable

func CloneTable(v *LTable) *LTable

func CreateTable

func CreateTable(acap, hcap int) *LTable

func (*LTable) Append

func (tb *LTable) Append(value LValue)

Append appends a given LValue to this LTable.

func (*LTable) Array

func (tb *LTable) Array() []LValue

func (*LTable) AssertFloat64

func (tb *LTable) AssertFloat64() (float64, bool)

func (*LTable) AssertFunction

func (tb *LTable) AssertFunction() (*LFunction, bool)

func (*LTable) AssertString

func (tb *LTable) AssertString() (string, bool)

func (*LTable) CheckBool

func (tb *LTable) CheckBool(key string, d bool) bool

func (*LTable) CheckInt

func (tb *LTable) CheckInt(key string, d int) int

table check int or default

func (*LTable) CheckSocket

func (tb *LTable) CheckSocket(key string, L *LState) string

func (*LTable) CheckSockets

func (tb *LTable) CheckSockets(key string, L *LState) string

func (*LTable) CheckString

func (tb *LTable) CheckString(key string, d string) string

table check string or default

func (*LTable) CheckUint32

func (tb *LTable) CheckUint32(key string, d uint32) uint32

table check int or default

func (*LTable) CheckVelaData

func (tb *LTable) CheckVelaData(L *LState, key string) *VelaData

func (*LTable) ForEach

func (tb *LTable) ForEach(cb func(LValue, LValue))

ForEach iterates over this table of elements, yielding each in turn to a given function.

func (*LTable) Hijack added in v1.5.0

func (tb *LTable) Hijack(*CallFrameFSM) bool

func (*LTable) Insert

func (tb *LTable) Insert(i int, value LValue)

Insert inserts a given LValue at position `i` in this table.

func (*LTable) Int

func (tb *LTable) Int() []int

func (*LTable) Int64

func (tb *LTable) Int64() []int64

func (*LTable) IsArray

func (tb *LTable) IsArray() bool

func (*LTable) Len

func (tb *LTable) Len() int

Len returns length of this LTable without using __len.

func (*LTable) MaxN

func (tb *LTable) MaxN() int

MaxN returns a maximum number key that nil value does not exist before it.

func (*LTable) Next

func (tb *LTable) Next(key LValue) (LValue, LValue)

This function is equivalent to lua_next ( http://www.lua.org/manual/5.1/manual.html#lua_next ).

func (*LTable) Pickup

func (tb *LTable) Pickup(vt LValueType, fn func(lv LValue))

func (*LTable) Range

func (tb *LTable) Range(cb func(string, LValue))

func (*LTable) RangeDict

func (tb *LTable) RangeDict(cb func(LValue, LValue) bool)

func (*LTable) RangeStrDict

func (tb *LTable) RangeStrDict(cb func(string, LValue) bool)

func (*LTable) RawGet

func (tb *LTable) RawGet(key LValue) LValue

RawGet returns an LValue associated with a given key without __index metamethod.

func (*LTable) RawGetH

func (tb *LTable) RawGetH(key LValue) LValue

RawGet returns an LValue associated with a given key without __index metamethod.

func (*LTable) RawGetInt

func (tb *LTable) RawGetInt(key int) LValue

RawGetInt returns an LValue at position `key` without __index metamethod.

func (*LTable) RawGetString

func (tb *LTable) RawGetString(key string) LValue

RawGetString returns an LValue associated with a given key without __index metamethod.

func (*LTable) RawSet

func (tb *LTable) RawSet(key LValue, value LValue)

RawSet sets a given LValue to a given index without the __newindex metamethod. It is recommended to use `RawSetString` or `RawSetInt` for performance if you already know the given LValue is a string or number.

func (*LTable) RawSetH

func (tb *LTable) RawSetH(key LValue, value LValue)

RawSetH sets a given LValue to a given index without the __newindex metamethod.

func (*LTable) RawSetInt

func (tb *LTable) RawSetInt(key int, value LValue)

RawSetInt sets a given LValue at a position `key` without the __newindex metamethod.

func (*LTable) RawSetString

func (tb *LTable) RawSetString(key string, value LValue)

RawSetString sets a given LValue to a given string index without the __newindex metamethod.

func (*LTable) Remove

func (tb *LTable) Remove(pos int) LValue

Remove removes from this table the element at a given position.

func (*LTable) String

func (tb *LTable) String() string

func (*LTable) Strings

func (tb *LTable) Strings() []string

func (*LTable) Type

func (tb *LTable) Type() LValueType

func (*LTable) Uint

func (tb *LTable) Uint() []int

func (*LTable) Uint64

func (tb *LTable) Uint64() []int64

type LUint

type LUint uint

func (LUint) AssertFloat64

func (ui LUint) AssertFloat64() (float64, bool)

func (LUint) AssertFunction

func (ui LUint) AssertFunction() (*LFunction, bool)

func (LUint) AssertString

func (ui LUint) AssertString() (string, bool)

func (LUint) Hijack added in v1.5.0

func (ui LUint) Hijack(*CallFrameFSM) bool

func (LUint) String

func (ui LUint) String() string

func (LUint) Type

func (ui LUint) Type() LValueType

type LUint64

type LUint64 uint64

func (LUint64) AssertFloat64

func (ui LUint64) AssertFloat64() (float64, bool)

func (LUint64) AssertFunction

func (ui LUint64) AssertFunction() (*LFunction, bool)

func (LUint64) AssertString

func (ui LUint64) AssertString() (string, bool)

func (LUint64) Hijack added in v1.5.0

func (ui LUint64) Hijack(*CallFrameFSM) bool

func (LUint64) String

func (ui LUint64) String() string

func (LUint64) Type

func (ui LUint64) Type() LValueType

type LUserData

type LUserData struct {
	Value     interface{}
	Env       *LTable
	Metatable LValue
}

func (*LUserData) AssertFloat64

func (ud *LUserData) AssertFloat64() (float64, bool)

func (*LUserData) AssertFunction

func (ud *LUserData) AssertFunction() (*LFunction, bool)

func (*LUserData) AssertString

func (ud *LUserData) AssertString() (string, bool)

func (*LUserData) Hijack added in v1.5.0

func (ud *LUserData) Hijack(*CallFrameFSM) bool

func (*LUserData) String

func (ud *LUserData) String() string

func (*LUserData) Type

func (ud *LUserData) Type() LValueType

type LVFace

type LVFace interface {
	ToLValue() LValue
}

type LValue

type LValue interface {
	String() string
	Type() LValueType
	// to reduce `runtime.assertI2T2` costs, this method should be used instead of the type assertion in heavy paths(typically inside the VM).
	AssertFloat64() (float64, bool)
	// to reduce `runtime.assertI2T2` costs, this method should be used instead of the type assertion in heavy paths(typically inside the VM).
	AssertString() (string, bool)
	// to reduce `runtime.assertI2T2` costs, this method should be used instead of the type assertion in heavy paths(typically inside the VM).
	AssertFunction() (*LFunction, bool)
	Hijack(*CallFrameFSM) bool
}

func ToLValue

func ToLValue(v interface{}) LValue

type LValueType

type LValueType int
const (
	LTNil LValueType = iota
	LTBool
	LTNumber
	LTInt
	LTUint
	LTInt64
	LTUint64
	LTString
	LTFunction
	LTUserData
	LTThread
	LTTable
	LTChannel
	LTVelaData
	LTSlice
	LTMap
	LTKv
	LTSkv
	LTAnyData
	LTObject
	LTGoFunction
	LTGoFuncErr
	LTGoFuncStr
	LTGoFuncInt
	LTGeneric
)

func (LValueType) String

func (vt LValueType) String() string

type MetaEx

type MetaEx interface {
	Meta(*LState, LValue) LValue
}

MetaEx 通过 LValue 获取 a[1]

type MetaTableEx

type MetaTableEx interface {
	MetaTable(*LState, string) LValue
}

MetaTableEx 通过 string 获取 内容 a:key()

type NewIndexEx

type NewIndexEx interface {
	NewIndex(*LState, string, LValue)
}

type NewMetaEx

type NewMetaEx interface {
	NewMeta(*LState, LValue, LValue)
}

NewMetaEx 通过LValue 设置 a[1] = 123

type OptionEx

type OptionEx struct {
	State    *LState
	OnAfter  func() error
	OnBefore func() error
}

func NewOption

func NewOption(v ...OptionFunc) *OptionEx

type OptionFunc

type OptionFunc func(*OptionEx)

func After

func After(fn func() error) OptionFunc

func Before

func Before(fn func() error) OptionFunc

func WithState

func WithState(co *LState) OptionFunc

type Options

type Options struct {
	// Call stack size. This defaults to `lua.CallStackSize`.
	CallStackSize int
	// Data stack size. This defaults to `lua.RegistrySize`.
	RegistrySize int
	// Allow the registry to grow from the registry size specified up to a value of RegistryMaxSize. A value of 0
	// indicates no growth is permitted. The registry will not shrink again after any growth.
	RegistryMaxSize int
	// If growth is enabled, step up by an additional `RegistryGrowStep` each time to avoid having to resize too often.
	// This defaults to `lua.RegistryGrowStep`
	RegistryGrowStep int
	// Controls whether or not libraries are opened by default
	SkipOpenLibs bool
	// Tells whether a Go stacktrace should be included in a Lua stacktrace when panics occur.
	IncludeGoStackTrace bool
	// If `MinimizeStackMemory` is set, the call stack will be automatically grown or shrank up to a limit of
	// `CallStackSize` in order to minimize memory usage. This does incur a slight performance penalty.
	MinimizeStackMemory bool
}

Options is a configuration that is used to create a new LState.

type P

type P struct {
	Fn      LValue
	NRet    int
	Protect bool
	Handler *LFunction
}

type Reader

type Reader interface {
	VelaEntry
	io.Reader
}

func CheckReader

func CheckReader(val *VelaData) Reader

type ReaderCloser

type ReaderCloser interface {
	VelaEntry
	io.Reader
	io.Closer
}

type ResumeState

type ResumeState int
const (
	ResumeOK ResumeState = iota
	ResumeYield
	ResumeError
)

type Sample

type Sample struct {
	FnIsG             bool
	FnSourceName      string
	FnLineDefined     int
	FnLastLineDefined int

	//parent
	ParentIdx        int
	ParentPc         int
	ParentBase       int
	ParentLocalBase  int
	ParentReturnBase int
	ParentNArgs      int
	ParentNRet       int
	ParentTailCall   int
}

type SuperVelaData

type SuperVelaData struct {
	Uptime time.Time
	Status VelaState
	TypeOf string
	// contains filtered or unexported fields
}

SuperVelaData 防止过多的方法定义

func (*SuperVelaData) CodeVM

func (sv *SuperVelaData) CodeVM() string

func (*SuperVelaData) Help

func (sv *SuperVelaData) Help(out Console)

func (*SuperVelaData) Index

func (sv *SuperVelaData) Index(*LState, string) LValue

func (*SuperVelaData) Init

func (sv *SuperVelaData) Init(typeof string)

func (*SuperVelaData) IsClose

func (sv *SuperVelaData) IsClose() bool

func (*SuperVelaData) IsInit

func (sv *SuperVelaData) IsInit() bool

func (*SuperVelaData) IsPanic

func (sv *SuperVelaData) IsPanic() bool

func (*SuperVelaData) IsRun

func (sv *SuperVelaData) IsRun() bool

func (*SuperVelaData) Meta

func (sv *SuperVelaData) Meta(*LState, LValue) LValue

func (*SuperVelaData) Name

func (sv *SuperVelaData) Name() string

func (*SuperVelaData) NewIndex

func (sv *SuperVelaData) NewIndex(*LState, string, LValue)

func (*SuperVelaData) NewMeta

func (sv *SuperVelaData) NewMeta(*LState, LValue, LValue)

func (*SuperVelaData) Show

func (sv *SuperVelaData) Show(out Console)

func (*SuperVelaData) State

func (sv *SuperVelaData) State() VelaState

func (*SuperVelaData) Type

func (sv *SuperVelaData) Type() string

func (*SuperVelaData) V

func (sv *SuperVelaData) V(opts ...interface{})

type Upvalue

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

func (*Upvalue) Close

func (uv *Upvalue) Close()

func (*Upvalue) IsClosed

func (uv *Upvalue) IsClosed() bool

func (*Upvalue) SetValue

func (uv *Upvalue) SetValue(value LValue)

func (*Upvalue) Value

func (uv *Upvalue) Value() LValue

type UserKV

type UserKV interface {
	LValue
	Get(string) LValue
	Set(string, LValue)
	V(string) (LValue, bool)
}

func NewSafeUserKV

func NewSafeUserKV() UserKV

func NewUserKV

func NewUserKV() UserKV

type VelaCode

type VelaCode interface {
	Key() string
	NewVelaData(*LState, string, string) *VelaData
}

type VelaData

type VelaData struct {
	Data VelaEntry
	// contains filtered or unexported fields
}

func NewVelaData

func NewVelaData(v VelaEntry) *VelaData

func (*VelaData) AssertFloat64

func (vd *VelaData) AssertFloat64() (float64, bool)

func (*VelaData) AssertFunction

func (vd *VelaData) AssertFunction() (*LFunction, bool)

func (*VelaData) AssertString

func (vd *VelaData) AssertString() (string, bool)

func (*VelaData) Close

func (vd *VelaData) Close() error

func (*VelaData) CodeVM

func (vd *VelaData) CodeVM() string

func (*VelaData) Hijack added in v1.5.0

func (vd *VelaData) Hijack(fsm *CallFrameFSM) bool

func (*VelaData) IsNil

func (vd *VelaData) IsNil() bool

func (*VelaData) IsPrivate

func (vd *VelaData) IsPrivate() bool

func (*VelaData) Private

func (vd *VelaData) Private(L *LState)

func (*VelaData) Set

func (vd *VelaData) Set(v VelaEntry)

func (*VelaData) String

func (vd *VelaData) String() string

func (*VelaData) Type

func (vd *VelaData) Type() LValueType

type VelaEntry

type VelaEntry interface {
	Name() string     //获取当前对象名称
	Type() string     //获取对象类型
	State() VelaState //获取状态
	Start() error
	Close() error
	NewMeta(*LState, LValue, LValue)  //设置字段
	Meta(*LState, LValue) LValue      //获取字段
	Index(*LState, string) LValue     //获取字符串字段 __index function
	NewIndex(*LState, string, LValue) //设置字段 __newindex function

	Show(Console) //控制台打印
	Help(Console) //控制台 辅助信息
	//V  设置信息
	V(...interface{})
}

type VelaState

type VelaState uint32
const (
	VTInit VelaState = iota
	VTRun
	VTErr
	VTClose
	VTPanic
	VTPrivate
	VTMode
)

func (VelaState) String

func (v VelaState) String() string

type Writer

type Writer interface {
	VelaEntry
	io.Writer
}

func CheckWriter

func CheckWriter(val *VelaData) Writer

type WriterCloser

type WriterCloser interface {
	VelaEntry
	io.Writer
	io.Closer
}

Directories

Path Synopsis
Package cast provides easy and safe casting in Go.
Package cast provides easy and safe casting in Go.
Lua pattern match functions for Go
Lua pattern match functions for Go

Jump to

Keyboard shortcuts

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