mirror of https://github.com/Hilbis/Hilbish
fix: only add __docProp metatable from SetField function
parent
43ddab699f
commit
179947cd98
13
util/util.go
13
util/util.go
|
@ -1,7 +1,6 @@
|
|||
package util
|
||||
|
||||
import "github.com/yuin/gopher-lua"
|
||||
import "fmt"
|
||||
|
||||
// Document adds a documentation string to a module.
|
||||
// It is accessible via the __doc metatable.
|
||||
|
@ -9,9 +8,6 @@ func Document(L *lua.LState, module lua.LValue, doc string) {
|
|||
mt := L.GetMetatable(module)
|
||||
if mt == lua.LNil {
|
||||
mt = L.NewTable()
|
||||
docProp := L.NewTable()
|
||||
L.SetField(mt, "__docProp", docProp)
|
||||
|
||||
L.SetMetatable(module, mt)
|
||||
}
|
||||
L.SetField(mt, "__doc", lua.LString(doc))
|
||||
|
@ -21,9 +17,16 @@ func Document(L *lua.LState, module lua.LValue, doc string) {
|
|||
// It is accessible via the __docProp metatable. It is a table of the names of the fields.
|
||||
func SetField(L *lua.LState, module lua.LValue, field string, value lua.LValue, doc string) {
|
||||
mt := L.GetMetatable(module)
|
||||
if mt == lua.LNil {
|
||||
mt = L.NewTable()
|
||||
docProp := L.NewTable()
|
||||
L.SetField(mt, "__docProp", docProp)
|
||||
|
||||
L.SetMetatable(module, mt)
|
||||
}
|
||||
docProp := L.GetTable(mt, lua.LString("__docProp"))
|
||||
fmt.Println("docProp", docProp)
|
||||
|
||||
L.SetField(docProp, field, lua.LString(doc))
|
||||
L.SetField(module, field, value)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue