Skip to content

Commit

Permalink
From Lua 5.2: Add luaL_setmetatable().
Browse files Browse the repository at this point in the history
Contributed by François Perrad.
  • Loading branch information
Mike Pall authored and lukego committed Aug 13, 2017
1 parent 4a307c1 commit 9fabcf9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lauxlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);


/*
Expand Down
3 changes: 1 addition & 2 deletions src/lib_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/lj_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9fabcf9

Please sign in to comment.