new version (from lhf)
This commit is contained in:
35
lundump.c
35
lundump.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lundump.c,v 1.54 2002/10/08 18:46:08 roberto Exp roberto $
|
** $Id: lundump.c,v 1.43 2002/08/07 00:36:03 lhf Exp lhf $
|
||||||
** load pre-compiled Lua chunks
|
** load pre-compiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
lua_State* L;
|
lua_State* L;
|
||||||
ZIO* Z;
|
ZIO* Z;
|
||||||
Mbuffer *buff;
|
Mbuffer* b;
|
||||||
int swap;
|
int swap;
|
||||||
const char* name;
|
const char* name;
|
||||||
} LoadState;
|
} LoadState;
|
||||||
@@ -46,7 +46,7 @@ static void LoadBlock (LoadState* S, void* b, size_t size)
|
|||||||
{
|
{
|
||||||
if (S->swap)
|
if (S->swap)
|
||||||
{
|
{
|
||||||
char *p=(char*) b+size-1;
|
char* p=(char*) b+size-1;
|
||||||
int n=size;
|
int n=size;
|
||||||
while (n--) *p--=(char)ezgetc(S);
|
while (n--) *p--=(char)ezgetc(S);
|
||||||
}
|
}
|
||||||
@@ -58,10 +58,10 @@ static void LoadVector (LoadState* S, void* b, int m, size_t size)
|
|||||||
{
|
{
|
||||||
if (S->swap)
|
if (S->swap)
|
||||||
{
|
{
|
||||||
char *q=(char*) b;
|
char* q=(char*) b;
|
||||||
while (m--)
|
while (m--)
|
||||||
{
|
{
|
||||||
char *p=q+size-1;
|
char* p=q+size-1;
|
||||||
int n=size;
|
int n=size;
|
||||||
while (n--) *p--=(char)ezgetc(S);
|
while (n--) *p--=(char)ezgetc(S);
|
||||||
q+=size;
|
q+=size;
|
||||||
@@ -100,7 +100,7 @@ static TString* LoadString (LoadState* S)
|
|||||||
return NULL;
|
return NULL;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char* s=luaZ_openspace(S->L,S->buff,size);
|
char* s=luaZ_openspace(S->L,S->b,size);
|
||||||
ezread(S,s,size);
|
ezread(S,s,size);
|
||||||
return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
|
return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
|
||||||
}
|
}
|
||||||
@@ -130,10 +130,10 @@ static void LoadLocals (LoadState* S, Proto* f)
|
|||||||
|
|
||||||
static void LoadLines (LoadState* S, Proto* f)
|
static void LoadLines (LoadState* S, Proto* f)
|
||||||
{
|
{
|
||||||
int n;
|
int size=LoadInt(S);
|
||||||
n=LoadInt(S);
|
f->lineinfo=luaM_newvector(S->L,size,int);
|
||||||
f->lineinfo=luaM_newvector(S->L,n,int);
|
f->sizelineinfo=size;
|
||||||
LoadVector(S,f->lineinfo,n,sizeof(*f->lineinfo));
|
LoadVector(S,f->lineinfo,size,sizeof(*f->lineinfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Proto* LoadFunction (LoadState* S, TString* p);
|
static Proto* LoadFunction (LoadState* S, TString* p);
|
||||||
@@ -233,8 +233,7 @@ static void LoadHeader (LoadState* S)
|
|||||||
TESTSIZE(sizeof(lua_Number), "number");
|
TESTSIZE(sizeof(lua_Number), "number");
|
||||||
x=LoadNumber(S);
|
x=LoadNumber(S);
|
||||||
if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */
|
if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */
|
||||||
luaG_runerror(S->L,"unknown number format in %s: read %f; expected %f",
|
luaG_runerror(S->L,"unknown number format in %s",S->name);
|
||||||
S->name,x,tx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Proto* LoadChunk (LoadState* S)
|
static Proto* LoadChunk (LoadState* S)
|
||||||
@@ -244,12 +243,11 @@ static Proto* LoadChunk (LoadState* S)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** load one chunk from a file or buffer
|
** load precompiled chunk
|
||||||
*/
|
*/
|
||||||
Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer *buff)
|
Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff)
|
||||||
{
|
{
|
||||||
LoadState S;
|
LoadState S;
|
||||||
Proto* f;
|
|
||||||
const char* s=zname(Z);
|
const char* s=zname(Z);
|
||||||
if (*s=='@' || *s=='=')
|
if (*s=='@' || *s=='=')
|
||||||
S.name=s+1;
|
S.name=s+1;
|
||||||
@@ -259,11 +257,8 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer *buff)
|
|||||||
S.name=s;
|
S.name=s;
|
||||||
S.L=L;
|
S.L=L;
|
||||||
S.Z=Z;
|
S.Z=Z;
|
||||||
S.buff=buff;
|
S.b=buff;
|
||||||
f=LoadChunk(&S);
|
return LoadChunk(&S);
|
||||||
if (zgetc(Z)!=EOZ)
|
|
||||||
luaG_runerror(L,"%s apparently contains more than one chunk",S.name);
|
|
||||||
return f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user