MCPcopy Create free account
hub / github.com/defold/defold / compat_luaL_setfuncs

Function compat_luaL_setfuncs

engine/script/src/luacjson/lua_cjson.c:1688–1700  ·  view source on GitHub ↗

Compatibility for Lua 5.1 and older LuaJIT. * * compat_luaL_setfuncs() is used to create a module table where the functions * have json_config_t as their first upvalue. Code borrowed from Lua 5.2 * source's luaL_setfuncs(). */

Source from the content-addressed store, hash-verified

1686 * source's luaL_setfuncs().
1687 */
1688static void compat_luaL_setfuncs(lua_State *l, const luaL_Reg *reg, int nup)
1689{
1690 int i;
1691
1692 luaL_checkstack(l, nup, "too many upvalues");
1693 for (; reg->name != NULL; reg++) { /* fill the table with given functions */
1694 for (i = 0; i < nup; i++) /* copy upvalues to the top */
1695 lua_pushvalue(l, -nup);
1696 lua_pushcclosure(l, reg->func, nup); /* closure with those upvalues */
1697 lua_setfield(l, -(nup + 2), reg->name);
1698 }
1699 lua_pop(l, nup); /* remove upvalues */
1700}
1701#else
1702#define compat_luaL_setfuncs(L, reg, nup) luaL_setfuncs(L, reg, nup)
1703#endif

Callers 1

lua_cjson_newFunction · 0.85

Calls 4

luaL_checkstackFunction · 0.85
lua_pushvalueFunction · 0.85
lua_pushcclosureFunction · 0.85
lua_setfieldFunction · 0.85

Tested by

no test coverage detected