MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / luaB_newproxy

Function luaB_newproxy

deps/lua/src/lbaselib.c:421–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419
420
421static int luaB_newproxy (lua_State *L) {
422 lua_settop(L, 1);
423 lua_newuserdata(L, 0); /* create proxy */
424 if (lua_toboolean(L, 1) == 0)
425 return 1; /* no metatable */
426 else if (lua_isboolean(L, 1)) {
427 lua_newtable(L); /* create a new metatable `m' ... */
428 lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */
429 lua_pushboolean(L, 1);
430 lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */
431 }
432 else {
433 int validproxy = 0; /* to check if weaktable[metatable(u)] == true */
434 if (lua_getmetatable(L, 1)) {
435 lua_rawget(L, lua_upvalueindex(1));
436 validproxy = lua_toboolean(L, -1);
437 lua_pop(L, 1); /* remove value */
438 }
439 luaL_argcheck(L, validproxy, 1, "boolean or proxy expected");
440 lua_getmetatable(L, 1); /* metatable is valid; get it */
441 }
442 lua_setmetatable(L, 2);
443 return 1;
444}
445
446
447static const luaL_Reg base_funcs[] = {

Callers

nothing calls this directly

Calls 9

lua_settopFunction · 0.85
lua_newuserdataFunction · 0.85
lua_tobooleanFunction · 0.85
lua_pushvalueFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_rawsetFunction · 0.85
lua_getmetatableFunction · 0.85
lua_rawgetFunction · 0.85
lua_setmetatableFunction · 0.85

Tested by

no test coverage detected