dump/undump of upvalue names
This commit is contained in:
32
ldump.c
32
ldump.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldump.c,v 1.1 2002/10/25 21:31:28 roberto Exp roberto $
|
** $Id: ldump.c,v 1.3 2003/01/10 11:08:45 lhf Exp $
|
||||||
** save bytecodes
|
** save bytecodes
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -19,13 +19,12 @@
|
|||||||
#define DumpLiteral(s,D) DumpBlock("" s,(sizeof(s))-1,D)
|
#define DumpLiteral(s,D) DumpBlock("" s,(sizeof(s))-1,D)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
lua_State *L;
|
lua_State* L;
|
||||||
lua_Chunkwriter write;
|
lua_Chunkwriter write;
|
||||||
void *data;
|
void* data;
|
||||||
} DumpState;
|
} DumpState;
|
||||||
|
|
||||||
|
static void DumpBlock(const void* b, size_t size, DumpState* D)
|
||||||
static void DumpBlock(const void *b, size_t size, DumpState* D)
|
|
||||||
{
|
{
|
||||||
lua_unlock(D->L);
|
lua_unlock(D->L);
|
||||||
(*D->write)(D->L,b,size,D->data);
|
(*D->write)(D->L,b,size,D->data);
|
||||||
@@ -89,6 +88,18 @@ static void DumpLines(const Proto* f, DumpState* D)
|
|||||||
DumpVector(f->lineinfo,f->sizelineinfo,sizeof(*f->lineinfo),D);
|
DumpVector(f->lineinfo,f->sizelineinfo,sizeof(*f->lineinfo),D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DumpUpvalues(const Proto* f, DumpState* D)
|
||||||
|
{
|
||||||
|
if (f->upvalues==NULL)
|
||||||
|
DumpInt(0,D);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int i,n=f->nupvalues;
|
||||||
|
DumpInt(n,D);
|
||||||
|
for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
|
static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
|
||||||
|
|
||||||
static void DumpConstants(const Proto* f, DumpState* D)
|
static void DumpConstants(const Proto* f, DumpState* D)
|
||||||
@@ -122,12 +133,13 @@ static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
|
|||||||
{
|
{
|
||||||
DumpString((f->source==p) ? NULL : f->source,D);
|
DumpString((f->source==p) ? NULL : f->source,D);
|
||||||
DumpInt(f->lineDefined,D);
|
DumpInt(f->lineDefined,D);
|
||||||
DumpByte(f->nupvalues,D);
|
DumpInt(f->nupvalues,D);
|
||||||
DumpByte(f->numparams,D);
|
DumpByte(f->numparams,D);
|
||||||
DumpByte(f->is_vararg,D);
|
DumpByte(f->is_vararg,D);
|
||||||
DumpByte(f->maxstacksize,D);
|
DumpByte(f->maxstacksize,D);
|
||||||
DumpLocals(f,D);
|
|
||||||
DumpLines(f,D);
|
DumpLines(f,D);
|
||||||
|
DumpLocals(f,D);
|
||||||
|
DumpUpvalues(f,D);
|
||||||
DumpConstants(f,D);
|
DumpConstants(f,D);
|
||||||
DumpCode(f,D);
|
DumpCode(f,D);
|
||||||
}
|
}
|
||||||
@@ -148,7 +160,10 @@ static void DumpHeader(DumpState* D)
|
|||||||
DumpNumber(TEST_NUMBER,D);
|
DumpNumber(TEST_NUMBER,D);
|
||||||
}
|
}
|
||||||
|
|
||||||
void luaU_dump(lua_State *L, const Proto* Main, lua_Chunkwriter w, void* data)
|
/*
|
||||||
|
** dump function as precompiled chunk
|
||||||
|
*/
|
||||||
|
void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data)
|
||||||
{
|
{
|
||||||
DumpState D;
|
DumpState D;
|
||||||
D.L=L;
|
D.L=L;
|
||||||
@@ -157,4 +172,3 @@ void luaU_dump(lua_State *L, const Proto* Main, lua_Chunkwriter w, void* data)
|
|||||||
DumpHeader(&D);
|
DumpHeader(&D);
|
||||||
DumpFunction(Main,NULL,&D);
|
DumpFunction(Main,NULL,&D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
lundump.c
26
lundump.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lundump.c,v 1.57 2002/11/14 16:15:53 roberto Exp roberto $
|
** $Id: lundump.c,v 1.47 2003/01/10 11:08:45 lhf Exp $
|
||||||
** load pre-compiled Lua chunks
|
** load pre-compiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -138,6 +138,25 @@ static void LoadLines (LoadState* S, Proto* f)
|
|||||||
LoadVector(S,f->lineinfo,size,sizeof(*f->lineinfo));
|
LoadVector(S,f->lineinfo,size,sizeof(*f->lineinfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void LoadUpvalues (LoadState* S, Proto* f)
|
||||||
|
{
|
||||||
|
int i,n,noname;
|
||||||
|
n=LoadInt(S);
|
||||||
|
noname=(n==0);
|
||||||
|
if (!noname && n!=f->nupvalues)
|
||||||
|
luaG_runerror(S->L,"bad nupvalues in %s: read %d; expected %d",
|
||||||
|
S->name,n,f->nupvalues);
|
||||||
|
n=f->nupvalues;
|
||||||
|
f->upvalues=luaM_newvector(S->L,n,TString*);
|
||||||
|
if (noname)
|
||||||
|
{
|
||||||
|
TString* name=luaS_newliteral(S->L,"(no name)");
|
||||||
|
for (i=0; i<n; i++) f->upvalues[i]=name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
|
||||||
|
}
|
||||||
|
|
||||||
static Proto* LoadFunction (LoadState* S, TString* p);
|
static Proto* LoadFunction (LoadState* S, TString* p);
|
||||||
|
|
||||||
static void LoadConstants (LoadState* S, Proto* f)
|
static void LoadConstants (LoadState* S, Proto* f)
|
||||||
@@ -177,12 +196,13 @@ static Proto* LoadFunction (LoadState* S, TString* p)
|
|||||||
Proto* f=luaF_newproto(S->L);
|
Proto* f=luaF_newproto(S->L);
|
||||||
f->source=LoadString(S); if (f->source==NULL) f->source=p;
|
f->source=LoadString(S); if (f->source==NULL) f->source=p;
|
||||||
f->lineDefined=LoadInt(S);
|
f->lineDefined=LoadInt(S);
|
||||||
f->nupvalues=LoadByte(S);
|
f->nupvalues=LoadInt(S);
|
||||||
f->numparams=LoadByte(S);
|
f->numparams=LoadByte(S);
|
||||||
f->is_vararg=LoadByte(S);
|
f->is_vararg=LoadByte(S);
|
||||||
f->maxstacksize=LoadByte(S);
|
f->maxstacksize=LoadByte(S);
|
||||||
LoadLocals(S,f);
|
|
||||||
LoadLines(S,f);
|
LoadLines(S,f);
|
||||||
|
LoadLocals(S,f);
|
||||||
|
LoadUpvalues(S,f);
|
||||||
LoadConstants(S,f);
|
LoadConstants(S,f);
|
||||||
LoadCode(S,f);
|
LoadCode(S,f);
|
||||||
#ifndef TRUST_BINARIES
|
#ifndef TRUST_BINARIES
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lundump.h,v 1.28 2002/10/09 13:42:01 roberto Exp roberto $
|
** $Id: lundump.h,v 1.28 2002/12/13 11:12:35 lhf Exp $
|
||||||
** load pre-compiled Lua chunks
|
** load pre-compiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -11,13 +11,13 @@
|
|||||||
#include "lzio.h"
|
#include "lzio.h"
|
||||||
|
|
||||||
/* load one chunk; from lundump.c */
|
/* load one chunk; from lundump.c */
|
||||||
Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer *buff);
|
Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff);
|
||||||
|
|
||||||
/* find byte order; from lundump.c */
|
/* find byte order; from lundump.c */
|
||||||
int luaU_endianness (void);
|
int luaU_endianness (void);
|
||||||
|
|
||||||
/* dump one chunk; from dump.c */
|
/* dump one chunk; from ldump.c */
|
||||||
void luaU_dump (lua_State *L, const Proto* Main, lua_Chunkwriter w, void* data);
|
void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data);
|
||||||
|
|
||||||
/* print one chunk; from print.c */
|
/* print one chunk; from print.c */
|
||||||
void luaU_print (const Proto* Main);
|
void luaU_print (const Proto* Main);
|
||||||
|
|||||||
Reference in New Issue
Block a user