| 297 | */ |
| 298 | |
| 299 | LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { |
| 300 | if (luaL_getmetatable(L, tname) != LUA_TNIL) /* name already in use? */ |
| 301 | return 0; /* leave previous value on top, but return 0 */ |
| 302 | lua_pop(L, 1); |
| 303 | lua_createtable(L, 0, 2); /* create metatable */ |
| 304 | lua_pushstring(L, tname); |
| 305 | lua_setfield(L, -2, "__name"); /* metatable.__name = tname */ |
| 306 | lua_pushvalue(L, -1); |
| 307 | lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ |
| 308 | return 1; |
| 309 | } |
| 310 | |
| 311 | |
| 312 | LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) { |
no test coverage detected