MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaL_newmetatable

Function luaL_newmetatable

3rd/lua-5.4.3/src/lauxlib.c:311–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309*/
310
311LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
312 if (luaL_getmetatable(L, tname) != LUA_TNIL) /* name already in use? */
313 return 0; /* leave previous value on top, but return 0 */
314 lua_pop(L, 1);
315 lua_createtable(L, 0, 2); /* create metatable */
316 lua_pushstring(L, tname);
317 lua_setfield(L, -2, "__name"); /* metatable.__name = tname */
318 lua_pushvalue(L, -1);
319 lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
320 return 1;
321}
322
323
324LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {

Callers 2

newboxFunction · 0.85
createmetaFunction · 0.85

Calls 4

lua_createtableFunction · 0.85
lua_pushstringFunction · 0.85
lua_setfieldFunction · 0.85
lua_pushvalueFunction · 0.85

Tested by

no test coverage detected