Move load/dump functions to lj_load.c. Add load modes.
This commit is contained in:
44
src/lj_api.c
44
src/lj_api.c
@@ -23,9 +23,6 @@
|
||||
#include "lj_frame.h"
|
||||
#include "lj_trace.h"
|
||||
#include "lj_vm.h"
|
||||
#include "lj_lex.h"
|
||||
#include "lj_bcdump.h"
|
||||
#include "lj_parse.h"
|
||||
#include "lj_strscan.h"
|
||||
|
||||
/* -- Common helper functions --------------------------------------------- */
|
||||
@@ -1138,47 +1135,6 @@ LUA_API int lua_resume(lua_State *L, int nargs)
|
||||
return LUA_ERRRUN;
|
||||
}
|
||||
|
||||
/* -- Load and dump Lua code ---------------------------------------------- */
|
||||
|
||||
static TValue *cpparser(lua_State *L, lua_CFunction dummy, void *ud)
|
||||
{
|
||||
LexState *ls = (LexState *)ud;
|
||||
GCproto *pt;
|
||||
GCfunc *fn;
|
||||
UNUSED(dummy);
|
||||
cframe_errfunc(L->cframe) = -1; /* Inherit error function. */
|
||||
pt = lj_lex_setup(L, ls) ? lj_bcread(ls) : lj_parse(ls);
|
||||
fn = lj_func_newL_empty(L, pt, tabref(L->env));
|
||||
/* Don't combine above/below into one statement. */
|
||||
setfuncV(L, L->top++, fn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data,
|
||||
const char *chunkname)
|
||||
{
|
||||
LexState ls;
|
||||
int status;
|
||||
ls.rfunc = reader;
|
||||
ls.rdata = data;
|
||||
ls.chunkarg = chunkname ? chunkname : "?";
|
||||
lj_str_initbuf(&ls.sb);
|
||||
status = lj_vm_cpcall(L, NULL, &ls, cpparser);
|
||||
lj_lex_cleanup(L, &ls);
|
||||
lj_gc_check(L);
|
||||
return status;
|
||||
}
|
||||
|
||||
LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data)
|
||||
{
|
||||
cTValue *o = L->top-1;
|
||||
api_checknelems(L, 1);
|
||||
if (tvisfunc(o) && isluafunc(funcV(o)))
|
||||
return lj_bcwrite(L, funcproto(funcV(o)), writer, data, 0);
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* -- GC and memory management -------------------------------------------- */
|
||||
|
||||
LUA_API int lua_gc(lua_State *L, int what, int data)
|
||||
|
||||
Reference in New Issue
Block a user