mirror of
https://github.com/Hilbis/Hilbish
synced 2025-07-03 01:32:03 +00:00
lots of commented out code ive found a go lua library which implements lua 5.4 and found an opportunity to start working on it. this commit basically removes everything and just leaves enough for the shell to be "usable" and able to start. there are no builtins or libraries (besides the `hilbish` global)
39 lines
996 B
Go
39 lines
996 B
Go
package util
|
|
|
|
import (
|
|
"github.com/yuin/gopher-lua"
|
|
rt "github.com/arnodel/golua/runtime"
|
|
)
|
|
|
|
// Document adds a documentation string to a module.
|
|
// It is accessible via the __doc metatable.
|
|
func Document(L *lua.LState, module lua.LValue, doc string) {
|
|
/*
|
|
mt := L.GetMetatable(module)
|
|
if mt == lua.LNil {
|
|
mt = L.NewTable()
|
|
L.SetMetatable(module, mt)
|
|
}
|
|
L.SetField(mt, "__doc", lua.LString(doc))
|
|
*/
|
|
}
|
|
|
|
// SetField sets a field in a table, adding docs for it.
|
|
// It is accessible via the __docProp metatable. It is a table of the names of the fields.
|
|
func SetField(rtm *rt.Runtime, module *rt.Table, field string, value rt.Value, doc string) {
|
|
mt := module.Metatable()
|
|
|
|
if mt == nil {
|
|
mt = rt.NewTable()
|
|
docProp := rt.NewTable()
|
|
mt.Set(rt.StringValue("__docProp"), rt.TableValue(docProp))
|
|
|
|
module.SetMetatable(mt)
|
|
}
|
|
docProp := mt.Get(rt.StringValue("__docProp"))
|
|
|
|
docProp.AsTable().Set(rt.StringValue(field), rt.StringValue(doc))
|
|
module.Set(rt.StringValue(field), value)
|
|
}
|
|
|