MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / luaB_newproxy

Function luaB_newproxy

lua/lbaselib.c:429–452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427
428
429static int luaB_newproxy (lua_State *L) {
430 lua_settop(L, 1);
431 lua_newuserdata(L, 0); /* create proxy */
432 if (lua_toboolean(L, 1) == 0)
433 return 1; /* no metatable */
434 else if (lua_isboolean(L, 1)) {
435 lua_newtable(L); /* create a new metatable `m' ... */
436 lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */
437 lua_pushboolean(L, 1);
438 lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */
439 }
440 else {
441 int validproxy = 0; /* to check if weaktable[metatable(u)] == true */
442 if (lua_getmetatable(L, 1)) {
443 lua_rawget(L, lua_upvalueindex(1));
444 validproxy = lua_toboolean(L, -1);
445 lua_pop(L, 1); /* remove value */
446 }
447 luaL_argcheck(L, validproxy, 1, "boolean or proxy expected");
448 lua_getmetatable(L, 1); /* metatable is valid; get it */
449 }
450 lua_setmetatable(L, 2);
451 return 1;
452}
453
454
455static 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