Documentation
¶
Index ¶
- Constants
- func ArgErr(arg int, err error) error
- func Compare(t *Thread, op Op, x, y Value) (bool, error)
- func Equals(t *Thread, x, y Value) (bool, error)
- func ExactArgs(want int) argsCheck
- func IsBool(v Value) bool
- func IsFloat(v Value) bool
- func IsFunction(v Value) bool
- func IsGoFunc(v Value) bool
- func IsGoValue(v Value) bool
- func IsInt(v Value) bool
- func IsNil(v Value) bool
- func IsNumber(v Value) bool
- func IsString(v Value) bool
- func IsTable(v Value) bool
- func IsThread(v Value) bool
- func MaxArgs(max int) argsCheck
- func MinArgs(min int) argsCheck
- func RangeArgs(min, max int) argsCheck
- func Truth(v Value) bool
- func TypeErr(arg int, typ, want string) error
- func TypeName(v Value) string
- func ValidArgs(kinds ...code.Type) argsCheck
- type Bool
- type Callable
- type Config
- type Constant
- type Context
- type Debug
- type Error
- type Float
- type Func
- type Function
- type GoFunc
- type GoValue
- type HasMeta
- type Importer
- type Int
- type Library
- type Loader
- type Number
- type Op
- type Path
- type String
- type Table
- func (t *Table) Get(k Value) Value
- func (t *Table) Length() Int
- func (t *Table) Meta() *Table
- func (t *Table) Next(key Value) (k, v Value, ok bool)
- func (t *Table) Set(k, v Value)
- func (t *Table) SetMeta(meta *Table)
- func (t *Table) Slice() (slice []Value)
- func (t *Table) String() string
- func (v *Table) Type(t *Thread) Type
- type Thread
- func (t *Thread) Call(fv Value, args ...Value) ([]Value, error)
- func (t *Thread) CallN(fv Value, args []Value, want int) ([]Value, error)
- func (t *Thread) Caller(level int) Debug
- func (t *Thread) Context() Context
- func (t *Thread) Exec(chunk *code.Chunk, args ...Value) ([]Value, error)
- func (t *Thread) ExecN(chunk *code.Chunk, args []Value, want int) ([]Value, error)
- func (t *Thread) Global(name string) Value
- func (t *Thread) Globals() *Table
- func (t *Thread) Index(tbl, key Value) (Value, error)
- func (t *Thread) IsMainThread() bool
- func (t *Thread) Load(chunk *code.Chunk) *Func
- func (t *Thread) Require(lib Library, global bool) (Value, error)
- func (t *Thread) SetGlobal(name string, global Value) *Thread
- func (t *Thread) String() string
- func (v *Thread) Type(t *Thread) Type
- func (t *Thread) TypeOf(obj Value) Type
- type Tuple
- func (args *Tuple) Arg(arg int) Value
- func (args *Tuple) Bool(arg int) (Bool, error)
- func (args *Tuple) BoolOpt(arg int, opt Bool) Bool
- func (args *Tuple) Check(ls *Thread, check argsCheck) error
- func (args *Tuple) Float(arg int) (Float, error)
- func (args *Tuple) FloatOpt(arg int, opt Float) Float
- func (args *Tuple) GoFunc(arg int) (*GoFunc, error)
- func (args *Tuple) Int(arg int) (Int, error)
- func (args *Tuple) IntOpt(arg int, opt Int) Int
- func (args *Tuple) Number(arg int) (Number, error)
- func (args *Tuple) NumberOpt(arg int, opt Number) Number
- func (args *Tuple) String(arg int) (String, error)
- func (args *Tuple) StringOpt(arg int, opt String) String
- func (args *Tuple) Table(arg int) (*Table, error)
- func (args *Tuple) Thread(arg int) (*Thread, error)
- type Type
- type Uint
- type Value
Constants ¶
const ( True = Bool(true) False = Bool(false) )
const ( // Lua search paths. LUAPATH_DEFAULT = LUA_DIR + "?.lua;" + LUA_DIR + "?/init.lua;" + GO_DIR + "?.lua;" + GO_DIR + "?/init.lua;" + "./?.lua;" + "./?/init.lua" LUA_DIR = ROOT_DEFAULT + "share/lua/5.3/" LUAPATH = "GLUA_PATH" // Go search paths. GOPATH_DEFAULT = GO_DIR + "?.so;" + GO_DIR + "loadall.so;" + "./?.so" GO_DIR = ROOT_DEFAULT + "lib/lua/5.3/" GOPATH = "GLUA_GOPATH" // System root paths. ROOT_DEFAULT = "/usr/local/" ROOT = "LUA_ROOT" // PATH_MARK is the string that marks the substitution points in a template. PATH_MARK = "?" // PATH_SEP is the character that separates templates in a path. PATH_SEP = ";" // EXEC_DIR in a Windows path is replaced by the executable's directory. EXEC_DIR = "!" // LUA_DIRSEP is the directory separator (for submodules). // // CHANGE it if your machine does not use "/" as the directory // separator and is not Windows. // // Windows Lua automatically uses "\". DIR_SEP = "/" // MOD_SEP (LUA_CSUBSEP/LUA_LSUBSEP) is the character that replaces dots // in submodule names when searching for a Go/Lua loader. MOD_SEP = DIR_SEP // LUA_IGMARK is a mark to ignore all before it when building // the luaopen_ function name. IGNORE_MARK = "-" )
Configuration for paths
const ( NilType = code.NilType BoolType = code.BoolType NumberType = code.NumberType StringType = code.StringType TableType = code.TableType FuncType = code.FuncType GoType = code.GoType ThreadType = code.ThreadType IntType = code.IntType FloatType = code.FloatType )
const EnvID = "_ENV"
const Nil = nilType(0)
Variables ¶
This section is empty.
Functions ¶
func IsFloat ¶
IsFloat reports whether the Value is a Float;
That is, the value is a Number and is represented as a Float.
func IsFunction ¶
IsFunction reports whether the Value implements the Function interface (i.e. *Func or *GoFunc).
func IsInt ¶
IsInt reports whether the Value is an Int;
That is, the value is a Number and is represented as an Int.
func IsString ¶
IsString reports whether the Value is a String or a Number (which is always convertible to a string).
Types ¶
type Callable ¶
type Callable interface {
// contains filtered or unexported methods
}
func ToCallable ¶
ToCallable converts the Value to a Callable value (either Lua or Go function).
On success, returns the function; otherwise nil.
type Float ¶
type Float float64
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
A Func represents a Lua function value.
type Function ¶
type Function interface {
Callable
}
func ToFunction ¶
ToFunction converts the Value to a Function (either Lua or Go function).
On success, returns the function; otherwise nil.
type GoFunc ¶
type GoFunc struct {
// contains filtered or unexported fields
}
GoFunc represents a Go builtin function value.
func ToGoFunc ¶
ToGoFunc converts the Value to a *GoFunc.
On success, returns the *GoFunc; otherwise nil.
type GoValue ¶
type GoValue struct {
Value interface{}
// contains filtered or unexported fields
}
type Int ¶
type Int int64
type Path ¶
type Path string
@path templates
A typical path is a list of directories wherein to search for a given file. The path used by require is a list of "templates", each of them specifying an alternative way to transform a module name (the argument to require) into a file name. Each template in the path is a file name containing optional question marks. For each template, require substitutes the module name for each question mark and checks whether there is a file with the resulting name; if not, it goes to the next template. The templates in a path are separated by semicolons, a character seldom used for file names in most operating systems.
For instance, consider the path: "?;?.lua;c:\windows\?;/usr/local/lua/?/?.lua"
With this path, the call require"sql" will try to open the following Lua files:
sql sql.lua c:\windows\sql /usr/local/lua/sql/sql.lua
The path require uses to search for Lua files is aways the current value of the variable "package.path". When the module package is initialized, it sets the variable with the value of the environment variable LUA_PATH_5_3; if this environment variable is undefined, Lua tries the environment variable LUA_PATH. If both are undefined, Lua uses a compiled-defined default path (-E prevents the use of these environment variables and forces the default).
When using the value of an environment variable, Lua substitues the default path for any substring ";;". For instance, if we set LUA_PATH_5_3 to "mydir/?.lua;;", the final path will be the template "mydir/?.lua" followed by the default path.
Path is a template (or list of templates separated by ';') used to search for Lua and Go packages.
func (Path) Search ¶
Search searches for the given name in the given path.
A path is a string containing a sequence of templates separated by semicolons. For each template, the function replaces each interrogation mark (if any) in the template with a copy of name wherein all occurences of sep (a dot, by default) were replaced by rep (the system's directory separator, by default), and then tries to ope nthe resulting file name.
For instance, if the path is the string:
"./?.lua;./.lc;/usr/local/?/init.lua"
The search for the name "foo.bar" will try to open the files (in order):
"./foo/bar.lua" "./foo/bar.lc" "/usr/local/foo/bar/init.lua"
Returns the resulting name of the first file that it can open in read mode (after closing the file), or "" and the error if none succeeds (this error message lists all the file names it tried to open). func SearchPath(ls *Thread, name, path, sep, dirsep string) (string, error) {
type String ¶
type String string
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func NewTableFromMap ¶
func NewTableSize ¶
type Thread ¶
type Thread struct {
// contains filtered or unexported fields
}
func ToThread ¶
ToThread converts the Value to a *Thread.
On success, returns the *Thread; otherwise nil.
func (*Thread) IsMainThread ¶
type Value ¶
type Value interface {
String() string
Type(*Thread) Type
// contains filtered or unexported methods
}
func Require ¶
@require(module)
1: Check in package.loaded whether "module" is already loaded.
If so, return corresponding value. Therefore, once a module is loaded, other calls requiring the same module simply return the same value, without running any code again.
2: Otherwise, searches for a Lua file with the module name (this
search is guided by "package.path"). If it finds such a file, it loads it with LoadFile. The result is a function that we call a "Loader". Loader: A function that, when called, loads the module.
3: Otherwise, searches for a Go library with that name (this search is
guided by "package.gopath"). If it finds a Go library, it loads it with the low-level function "package.loadlib", looking for a function called "luaopen_modname". The loader in this case is the result of "loadlib", which is the Go function "luaopen_modname" represented as a Lua function.
4: No matter whether the module was found in a Lua file or a Go library,
require now has a loader for it. To finally load the module, require calls the loader with two arguments: the module name and the name of the file where it got the loader (most modules just ignore these arguments). If the loader returns any value, require returns this value and stores it in the "package.loaded" table, to return the same value in future calls for this same module. IF the loader returns no value, and the table entry "package.loaded[module]" is still empty, require behaves as if the module returned true. Without this correction, a subsequent call to require would run the module again.