diff --git a/util/export.go b/util/export.go index 71114e3..ee0b4a6 100644 --- a/util/export.go +++ b/util/export.go @@ -4,12 +4,14 @@ import ( rt "github.com/arnodel/golua/runtime" ) +// LuaExport represents a Go function which can be exported to Lua. type LuaExport struct { Function rt.GoFunctionFunc ArgNum int Variadic bool } +// SetExports puts the Lua function exports in the table. func SetExports(rtm *rt.Runtime, tbl *rt.Table, exports map[string]LuaExport) { for name, export := range exports { rtm.SetEnvGoFunc(tbl, name, export.Function, export.ArgNum, export.Variadic) diff --git a/util/util.go b/util/util.go index 0371f00..abeaa9e 100644 --- a/util/util.go +++ b/util/util.go @@ -39,6 +39,7 @@ func SetField(rtm *rt.Runtime, module *rt.Table, field string, value rt.Value, d module.Set(rt.StringValue(field), value) } +// DoString runs the code string in the Lua runtime. func DoString(rtm *rt.Runtime, code string) error { chunk, err := rtm.CompileAndLoadLuaChunk("", []byte(code), rt.TableValue(rtm.GlobalEnv())) if chunk != nil { @@ -48,6 +49,7 @@ func DoString(rtm *rt.Runtime, code string) error { return err } +// DoString runs the contents of the file in the Lua runtime. func DoFile(rtm *rt.Runtime, filename string) error { data, err := os.ReadFile(filename) if err != nil { @@ -57,6 +59,8 @@ func DoFile(rtm *rt.Runtime, filename string) error { return DoString(rtm, string(data)) } +// HandleStrCallback handles function parameters for Go functions which take +// a string and a closure. func HandleStrCallback(t *rt.Thread, c *rt.GoCont) (string, *rt.Closure, error) { if err := c.CheckNArgs(2); err != nil { return "", nil, err