| 419 | |
| 420 | |
| 421 | static 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 | |
| 447 | static const luaL_Reg base_funcs[] = { |
nothing calls this directly
no test coverage detected