From fc7958312da513a1bc88e551b8675bf092b8fb6b Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Sat, 24 May 2025 07:32:24 -0500 Subject: [PATCH] add metatable methods --- wrapper.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wrapper.go b/wrapper.go index 03d646a..8aa2d90 100644 --- a/wrapper.go +++ b/wrapper.go @@ -33,6 +33,10 @@ static int execute_with_results(lua_State *L, const char *code, int store_result if (status != 0) return status; return lua_pcall(L, 0, store_results ? LUA_MULTRET : 0, 0); } + +static int has_metatable(lua_State *L, int index) { + return lua_getmetatable(L, index); +} */ import "C" import ( @@ -464,3 +468,13 @@ func (s *State) AddPackagePath(path string) error { code := fmt.Sprintf(`package.path = package.path .. ";%s"`, path) return s.DoString(code) } + +// SetMetatable sets the metatable for the value at the given index +func (s *State) SetMetatable(index int) { + C.lua_setmetatable(s.L, C.int(index)) +} + +// GetMetatable gets the metatable of the value at the given index +func (s *State) GetMetatable(index int) bool { + return C.lua_getmetatable(s.L, C.int(index)) != 0 +}