static int luaopen_table_new(lua_State *L)
{
- GCfunc *fn = lj_lib_pushcc(L, lj_cf_table_new, FF_table_new, 0);
- GCtab *t = tabref(curr_func(L)->c.env); /* Reference to "table". */
- setfuncV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "new")), fn);
- lj_gc_anybarriert(L, t);
- setfuncV(L, L->top++, fn);
- return 1;
+ return lj_lib_postreg(L, lj_cf_table_new, FF_table_new, "new");
}
/* ------------------------------------------------------------------------ */
}
}
+/* Push internal function on the stack. */
+GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, int id, int n)
+{
+ GCfunc *fn;
+ lua_pushcclosure(L, f, n);
+ fn = funcV(L->top-1);
+ fn->c.ffid = (uint8_t)id;
+ setmref(fn->c.pc, &G(L)->bc_cfunc_int);
+ return fn;
+}
+
void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env)
{
luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4);
L->top--;
}
+int lj_lib_postreg(lua_State *L, lua_CFunction cf, int id, const char *name)
+{
+ GCfunc *fn = lj_lib_pushcf(L, cf, id);
+ GCtab *t = tabref(curr_func(L)->c.env); /* Reference to parent table. */
+ setfuncV(L, lj_tab_setstr(L, t, lj_str_newz(L, name)), fn);
+ lj_gc_anybarriert(L, t);
+ setfuncV(L, L->top++, fn);
+ return 1;
+}
+
/* -- Type checks --------------------------------------------------------- */
TValue *lj_lib_checkany(lua_State *L, int narg)
#define lj_lib_checkfpu(L) UNUSED(L)
#endif
-/* Push internal function on the stack. */
-static LJ_AINLINE GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f,
- int id, int n)
-{
- GCfunc *fn;
- lua_pushcclosure(L, f, n);
- fn = funcV(L->top-1);
- fn->c.ffid = (uint8_t)id;
- setmref(fn->c.pc, &G(L)->bc_cfunc_int);
- return fn;
-}
-
+LJ_FUNC GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, int id, int n);
#define lj_lib_pushcf(L, fn, id) (lj_lib_pushcc(L, (fn), (id), 0))
/* Library function declarations. Scanned by buildvm. */
const uint8_t *init, const lua_CFunction *cf);
LJ_FUNC void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f,
GCtab *env);
+LJ_FUNC int lj_lib_postreg(lua_State *L, lua_CFunction cf, int id,
+ const char *name);
/* Library init data tags. */
#define LIBINIT_LENMASK 0x3f