lua

package module
v0.0.0-...-7250ec3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2015 License: MIT Imports: 24 Imported by: 0

README

===============================================================================
GopherLua: VM and compiler for Lua in Go.
===============================================================================

.. image:: https://godoc.org/github.com/yuin/gopher-lua?status.svg
    :target: http://godoc.org/github.com/yuin/gopher-lua

|

GopherLua is a Lua5.1 VM and compiler written in Go. GopherLua has a same goal
with Lua: **Be a scripting language with extensible semantics** . It provides a
Go APIs that allow you to easily embed a scripting language to your Go host 
programs.

----------------------------------------------------------------
Performance (fib(30))
----------------------------------------------------------------
Performance measurements in script languages on Go.

- `otto <https://github.com/robertkrimen/otto>`_
- `anko <https://github.com/mattn/anko>`_
- GopherLua

Summary

================ ========================= 
 prog              time
================ ========================= 
 otto              0m24.848s
 anko              0m20.207s
 GopherLua         0m1.248s
================ =========================

GopherLua 20x faster than other implementations in this benchmark.

fib.js

.. code-block:: javascript

       function fib(n) {
           if (n < 2) return n;
           return fib(n - 2) + fib(n - 1);
       }
       
       console.log(fib(30));

.. code-block:: bash

       $ time otto fib.js
       832040
       
       real    0m24.848s
       user    0m0.015s
       sys     0m0.078s

fib.ank

.. code-block::

       func fib(n) {
           if n < 2 {
             return n
           }
           return fib(n - 2) + fib(n - 1)
       }
       
       println(fib(30));

.. code-block:: bash

       $ time anko fib.ank
       
       832040
       
       real    0m20.207s
       user    0m0.030s
       sys     0m0.078s

fib.lua

.. code-block:: lua

       local function fib(n)
           if n < 2 then return n end
           return fib(n - 2) + fib(n - 1)
       end
       
       print(fib(30))

.. code-block:: bash

       $ time glua fib.lua
       832040
       
       real    0m1.248s
       user    0m0.015s
       sys     0m0.187s

----------------------------------------------------------------
Installation
----------------------------------------------------------------

.. code-block:: bash
   
   go get github.com/yuin/gopher-lua

----------------------------------------------------------------
Usage
----------------------------------------------------------------
GopherLua APIs perform in much the same way as Lua, **but the stack is used only 
for passing arguments and receiving returned values.**

Import a package.

.. code-block:: go
   
   import (
       "github.com/yuin/gopher-lua"
   )

Run scripts in the VM.

.. code-block:: go
   
   L := lua.NewState()
   defer L.Close()
   if err := L.DoString(`print("hello")`); err != nil {
       panic(err)
   }

.. code-block:: go

   L := lua.NewState()
   defer L.Close()
   if err := L.DoFile("hello.lua"); err != nil {
       panic(err)
   }

Refer to `Lua Reference Manual <http://www.lua.org/manual/5.1/>`_ and `Go doc <http://godoc.org/github.com/yuin/gopher-lua>`_ for further information.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Data model
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All data in a GopherLua program is a ``LValue`` . ``LValue`` is an interface 
type that has following methods.

- ``String() string``
- ``Type() LValueType``


Objects implement a LValue interface are

================ ========================= ================== =======================
 Type name        Go type                   Type() value       Constants
================ ========================= ================== =======================
 ``LNilType``      (constants)              ``LTNil``          ``LNil``
 ``LBool``         (constants)              ``LTBool``         ``LTrue``, ``LFalse``
 ``LNumber``        float64                 ``LTNumber``       ``-``
 ``LString``        string                  ``LTString``       ``-``
 ``LFunction``      struct pointer          ``LTFunction``     ``-``
 ``LUserData``      struct pointer          ``LTUserData``     ``-``
 ``LState``         struct pointer          ``LTThread``       ``-``
 ``LTable``         struct pointer          ``LTTable``        ``-``
================ ========================= ================== =======================

You can test an object type in Go way(type assertion) or using a ``Type()`` value.

.. code-block:: go

   lv := L.Get(-1) // get the value at the top of the stack
   if str, ok := lv.(lua.LString); ok {
       // lv is LString
       fmt.Println(string(str))
   }
   if lv.Type() != lua.LTString {
       panic("string required.")
   }

.. code-block:: go

   lv := L.Get(-1) // get the value at the top of the stack
   if tbl, ok := lv.(*lua.LTable); ok {
       // lv is LTable
       fmt.Println(L.ObjLen(tbl))
   }

Note that ``LBool`` , ``LNumber`` , ``LString`` is not a pointer.

To test ``LNilType`` and ``LBool``, You **must** use pre-defined constants.

.. code-block:: go

   lv := L.Get(-1) // get the value at the top of the stack
   
   if lv == LTrue { // correct
   }
   
   if bl, ok == lv.(lua.LBool); ok && bool(bl) { // wrong
   }

In Lua, both ``nil`` and ``false`` make a condition false. ``LVIsFalse`` and ``LVAsBool`` implement this specification.

.. code-block:: go

   lv := L.Get(-1) // get the value at the top of the stack
   if LVIsFalse(lv) { // lv is nil or false
   }
   
   if LVAsBool(lv) { // lv is neither nil nor false
   }

Objects that based on go structs(``LFunction``. ``LUserData``, ``LTable``)
have some public methods and fields. You can use these methods and fields for 
performance and debugging, but there are some limitations.

- Metatable does not work.
- No error handlings.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Callstack & Registry size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Size of the callstack & registry is **fixed** for mainly performance.
You can change the size of the callstack & registry.

.. code-block:: go

   lua.RegistrySize = 1024 * 20
   lua.CallStackSize = 1024
   L = lua.NewState()
   defer L.Close()


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
API
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Refer to `Lua Reference Manual <http://www.lua.org/manual/5.1/>`_ and `Go doc(LState methods) <http://godoc.org/github.com/yuin/gopher-lua>`_ for further information.

+++++++++++++++++++++++++++++++++++++++++
Calling Go from Lua
+++++++++++++++++++++++++++++++++++++++++

.. code-block:: go

   func Double(L lua.LState) int {
       lv := L.ToInt(1)             /* get argument */
       L.Push(lua.LNumber(lv * 2)) /* push result */
       return 1                     /* number of results */
   }
   
   func main() {
       L := lua.NewState()
       defer L.Close()
       L.SetGlobal("double", L.NewFunction(Double)) /* Original lua_setglobal uses stack... */
   }

.. code-block:: lua

   print(double(20)) -- > "40"

Any function registered with GopherLua is a ``lua.LGFunction``, defined in ``value.go``

.. code-block:: go

   type LGFunction func(*LState) int

Working with coroutines.

.. code-block:: go

   co := L.NewThread() /* create a new thread */
   fn := L.GetGlobal("coro").(*lua.LFunction) /* get function from lua */
   for {
       st, err, values := L.Resume(co, fn)
       if st == lua.ResumeError {
           println("yield break(error)")
           println(err.Error())
           break
       }
    
       for i, lv := range values {
           fmt.Printf("%v : %v\n", i, lv)
       }
    
       if st == lua.ResumeOK {
           println("yield break(ok)")
           break
       }
   }

+++++++++++++++++++++++++++++++++++++++++
Calling Lua from Go
+++++++++++++++++++++++++++++++++++++++++

.. code-block:: go

   L := lua.NewState()
   defer L.Close()
   if err := L.DoFile("double.lua"); err != nil {
       panic(err)
   }
   if err := L.CallByParam(lua.P{
       Fn: L.GetGlobal("double"),
       NRet: 1,
       Protect: true,
       }, lua.LNumber(10)); err != nil {
       panic(err)
   }
   ret := L.Get(-1) // returned value
   L.Pop(1)  // remove received value

If ``Protect`` is false, GopherLua will panic instead of returning an ``error`` value.


----------------------------------------------------------------
Differences between Lua and GopherLua
----------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pattern match
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- GopherLua uses the regexp package to implement the pattern match.
    - The Pattern match only works for utf8 strings.
    - The regexp package does not support back-references.
    - The regexp package does not support position-captures.

GopherLua has an option to use the Go regexp syntax as a pattern match format.

.. code-block:: go

   lua.LuaRegex = false
   L := lua.NewState()
   defer L.Close()

.. code-block:: lua

   print(string.gsub("abc $!?", [[a(\w+)]], "${1}")) --> bc $!?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unsupported functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- ``string.dump`` 
- ``os.setlocale``
- ``collectgarbage``
- ``lua_Debug.namewhat``
- ``package.loadlib``
- debug hooks

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Miscellaneous notes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- ``file:setvbuf`` does not support a line bufferring.

----------------------------------------------------------------
Standalone interpreter
----------------------------------------------------------------
Lua has an interpreter called ``lua`` . GopherLua has an interpreter called ``glua`` .

.. code-block:: bash

   go get github.com/yuin/gopher-lua/cmd/glua

``glua`` has same options as ``lua`` .

----------------------------------------------------------------
License
----------------------------------------------------------------
MIT

----------------------------------------------------------------
Author
----------------------------------------------------------------
Yusuke Inuzuka

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 (
	OP_MOVE     int = iota /*      A B     R(A) := R(B)                      */
	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_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_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 EnvironIndex = -10001
View Source
const GlobalsIndex = -10002
View Source
const LNumberBit = 64
View Source
const LNumberScanFormat = "%f"
View Source
const MultRet = -1
View Source
const PackageAuthors = "Yusuke Inuzuka"
View Source
const PackageCopyRight = PackageName + " " + PackageVersion + " Copyright (C) 2015 " + PackageAuthors
View Source
const PackageName = "GopherLua"
View Source
const PackageVersion = "0.1"
View Source
const RegistryIndex = -10000

Variables

View Source
var CallStackSize = 1024
View Source
var CompatVarArg = true
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 LuaLDir string
View Source
var LuaOS string
View Source
var LuaPath = "LUA_PATH"
View Source
var LuaPathDefault string
View Source
var LuaRegex = true
View Source
var MaxArrayIndex = 67108864
View Source
var MaxTableGetLoop = 100
View Source
var RegistrySize = 1024 * 20

Functions

func LVAsBool

func LVAsBool(v LValue) bool

func LVAsString

func LVAsString(v LValue) string

func LVCanConvToString

func LVCanConvToString(v LValue) bool

func LVIsFalse

func LVIsFalse(v LValue) bool

func UpvalueIndex

func UpvalueIndex(i int) int

Types

type ApiError

type ApiError struct {
	Type   ApiErrorType
	Object LValue
}

func (*ApiError) Error

func (e *ApiError) Error() string

type ApiErrorType

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

type CompileError

type CompileError struct {
	Context *funcContext
	Line    int
	Message string
}

func (*CompileError) Error

func (e *CompileError) Error() string

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
}

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
}

func Compile

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

func (*FunctionProto) String

func (fp *FunctionProto) String() string

type Global

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

type LBool

type LBool bool

func (LBool) String

func (bl LBool) String() string

func (LBool) Type

func (bl LBool) Type() LValueType

type LFunction

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

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 LNilType

type LNilType struct{}

func (*LNilType) String

func (nl *LNilType) String() string

func (*LNilType) Type

func (nl *LNilType) Type() LValueType

type LNumber

type LNumber float64

func LVAsNumber

func LVAsNumber(v LValue) LNumber

func (LNumber) Format

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

fmt.Formatter interface

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
	// contains filtered or unexported fields
}

func NewState

func NewState() *LState

func (*LState) ArgError

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

func (*LState) Call

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

func (*LState) CallByParam

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

func (*LState) CallMeta

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

func (*LState) CheckAny

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

func (*LState) CheckBool

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

func (*LState) CheckFunction

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

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) CheckOption

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

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) Close

func (ls *LState) Close()

func (*LState) Concat

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

func (*LState) CreateTable

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

func (*LState) DoFile

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

func (*LState) DoString

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

func (*LState) Equal

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

func (*LState) Error

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

func (*LState) FindTable

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

func (*LState) GPCall

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

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) 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) Insert

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

func (*LState) LessThan

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

func (*LState) Load

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

func (*LState) LoadFile

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

func (*LState) LoadString

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

func (*LState) NewClosure

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

func (*LState) NewFunction

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

func (*LState) NewTable

func (ls *LState) NewTable() *LTable

func (*LState) NewThread

func (ls *LState) NewThread() *LState

func (*LState) NewTypeMetatable

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

func (*LState) NewUserData

func (ls *LState) NewUserData() *LUserData

func (*LState) Next

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

func (*LState) ObjLen

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

func (*LState) OpenLibs

func (ls *LState) OpenLibs()

func (*LState) OptBool

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

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) PCall

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

func (*LState) Pop

func (ls *LState) Pop(n int)

func (*LState) Push

func (ls *LState) Push(value LValue)

func (*LState) RaiseError

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

func (*LState) RawEqual

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

func (*LState) RawGet

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

func (*LState) RawGetInt

func (ls *LState) RawGetInt(obj LValue, key int) LValue

func (*LState) RawSet

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

func (*LState) RawSetInt

func (ls *LState) RawSetInt(obj LValue, 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) RegisterModuleToTable

func (ls *LState) RegisterModuleToTable(tbl LValue, funcs map[string]LGFunction) LValue

func (*LState) Remove

func (ls *LState) Remove(index int)

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, *ApiError, []LValue)

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) 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) SetMetatable

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

func (*LState) SetMx

func (ls *LState) SetMx(mx int)

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) Status

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

func (*LState) String

func (ls *LState) String() string

func (*LState) TableForEach

func (ls *LState) TableForEach(obj LValue, cb func(LValue, LValue))

func (*LState) ToBool

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

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) 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) Where

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

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 (LString) Format

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

fmt.Formatter interface

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 (*LTable) Append

func (tb *LTable) Append(value LValue)

func (*LTable) ForEach

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

func (*LTable) Insert

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

func (*LTable) Len

func (tb *LTable) Len() int

func (*LTable) MaxN

func (tb *LTable) MaxN() int

func (*LTable) Next

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

func (*LTable) RawGet

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

func (*LTable) RawGetH

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

func (*LTable) RawGetInt

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

func (*LTable) RawSet

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

func (*LTable) RawSetH

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

func (*LTable) RawSetInt

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

func (*LTable) Remove

func (tb *LTable) Remove(pos int)

func (*LTable) String

func (tb *LTable) String() string

func (*LTable) Type

func (tb *LTable) Type() LValueType

type LUserData

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

func (*LUserData) String

func (ud *LUserData) String() string

func (*LUserData) Type

func (ud *LUserData) Type() LValueType

type LValue

type LValue interface {
	String() string
	Type() LValueType
}

type LValueType

type LValueType int
const (
	LTNil LValueType = iota
	LTBool
	LTNumber
	LTString
	LTFunction
	LTUserData
	LTThread
	LTTable
)

func (LValueType) String

func (vt LValueType) String() string

type P

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

type ResumeState

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

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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