From 179947cd98a8c6100cd1ee03e4ea88750326eee4 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:19:36 -0500 Subject: [PATCH] fix: only add __docProp metatable from SetField function --- util/util.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/util/util.go b/util/util.go index c26d514..718c623 100644 --- a/util/util.go +++ b/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) } +