|
|
@ -1,6 +1,6 @@ |
|
|
|
/*
|
|
|
|
** $Id: ldump.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ |
|
|
|
** save bytecodes |
|
|
|
** $Id: ldump.c,v 1.7 2004/06/09 21:03:53 lhf Exp lhf $ |
|
|
|
** save pre-compiled Lua chunks |
|
|
|
** See Copyright Notice in lua.h |
|
|
|
*/ |
|
|
|
|
|
|
@ -21,16 +21,20 @@ |
|
|
|
|
|
|
|
typedef struct { |
|
|
|
lua_State* L; |
|
|
|
lua_Chunkwriter write; |
|
|
|
lua_Chunkwriter writer; |
|
|
|
void* data; |
|
|
|
int strip; |
|
|
|
int status; |
|
|
|
} DumpState; |
|
|
|
|
|
|
|
static void DumpBlock(const void* b, size_t size, DumpState* D) |
|
|
|
{ |
|
|
|
lua_unlock(D->L); |
|
|
|
(*D->write)(D->L,b,size,D->data); |
|
|
|
lua_lock(D->L); |
|
|
|
if (D->status==0) |
|
|
|
{ |
|
|
|
lua_unlock(D->L); |
|
|
|
D->status=(*D->writer)(D->L,b,size,D->data); |
|
|
|
lua_lock(D->L); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void DumpByte(int y, DumpState* D) |
|
|
@ -54,7 +58,7 @@ static void DumpNumber(lua_Number x, DumpState* D) |
|
|
|
DumpBlock(&x,sizeof(x),D); |
|
|
|
} |
|
|
|
|
|
|
|
static void DumpString(TString* s, DumpState* D) |
|
|
|
static void DumpString(const TString* s, DumpState* D) |
|
|
|
{ |
|
|
|
if (s==NULL || getstr(s)==NULL) |
|
|
|
DumpSize(0,D); |
|
|
@ -154,16 +158,17 @@ static void DumpHeader(DumpState* D) |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
** dump function as precompiled chunk |
|
|
|
** dump Lua function as precompiled chunk |
|
|
|
*/ |
|
|
|
int luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data, int strip) |
|
|
|
int luaU_dump (lua_State* L, const Proto* f, lua_Chunkwriter w, void* data, int strip) |
|
|
|
{ |
|
|
|
DumpState D; |
|
|
|
D.L=L; |
|
|
|
D.write=w; |
|
|
|
D.writer=w; |
|
|
|
D.data=data; |
|
|
|
D.strip=strip; |
|
|
|
D.status=0; |
|
|
|
DumpHeader(&D); |
|
|
|
DumpFunction(Main,NULL,&D); |
|
|
|
return 1; |
|
|
|
DumpFunction(f,NULL,&D); |
|
|
|
return D.status; |
|
|
|
} |
|
|
|