diff --git a/src/lauxlib.h b/src/lauxlib.h index 1ca0d74f1d..a44f0272b3 100644 --- a/src/lauxlib.h +++ b/src/lauxlib.h @@ -89,6 +89,7 @@ LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname, int sizehint); LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); +LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); /* diff --git a/src/lib_package.c b/src/lib_package.c index c212e4cbd4..f4293e3433 100644 --- a/src/lib_package.c +++ b/src/lib_package.c @@ -78,8 +78,7 @@ static void **ll_register(lua_State *L, const char *path) lua_pop(L, 1); plib = (void **)lua_newuserdata(L, sizeof(void *)); *plib = NULL; - luaL_getmetatable(L, "_LOADLIB"); - lua_setmetatable(L, -2); + luaL_setmetatable(L, "_LOADLIB"); lua_pushfstring(L, "LOADLIB: %s", path); lua_pushvalue(L, -2); lua_settable(L, LUA_REGISTRYINDEX); diff --git a/src/lj_api.c b/src/lj_api.c index d3ef0aa211..f0c6f4859c 100644 --- a/src/lj_api.c +++ b/src/lj_api.c @@ -960,6 +960,12 @@ LUA_API int lua_setmetatable(lua_State *L, int idx) return 1; } +LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname) +{ + lua_getfield(L, LUA_REGISTRYINDEX, tname); + lua_setmetatable(L, -2); +} + LUA_API int lua_setfenv(lua_State *L, int idx) { cTValue *o = index2adr(L, idx);