"indent -kr -i2 -br -brf -nut" plus a few manual formating
This commit is contained in:
230
ldump.c
230
ldump.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldump.c,v 2.23 2014/02/28 16:13:01 roberto Exp roberto $
|
** $Id: ldump.c,v 2.24 2014/03/01 15:18:44 roberto Exp roberto $
|
||||||
** save precompiled Lua chunks
|
** save precompiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -15,10 +15,11 @@
|
|||||||
#include "lstate.h"
|
#include "lstate.h"
|
||||||
#include "lundump.h"
|
#include "lundump.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
lua_State* L;
|
lua_State *L;
|
||||||
lua_Writer writer;
|
lua_Writer writer;
|
||||||
void* data;
|
void *data;
|
||||||
int strip;
|
int strip;
|
||||||
int status;
|
int status;
|
||||||
} DumpState;
|
} DumpState;
|
||||||
@@ -27,164 +28,167 @@ typedef struct {
|
|||||||
#define DumpVar(x,D) DumpBlock(&x,sizeof(x),D)
|
#define DumpVar(x,D) DumpBlock(&x,sizeof(x),D)
|
||||||
#define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D)
|
#define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D)
|
||||||
|
|
||||||
static void DumpBlock(const void* b, size_t size, DumpState* D)
|
|
||||||
{
|
static void DumpBlock (const void *b, size_t size, DumpState *D) {
|
||||||
if (D->status==0)
|
if (D->status == 0) {
|
||||||
{
|
|
||||||
lua_unlock(D->L);
|
lua_unlock(D->L);
|
||||||
D->status=(*D->writer)(D->L,b,size,D->data);
|
D->status = (*D->writer)(D->L, b, size, D->data);
|
||||||
lua_lock(D->L);
|
lua_lock(D->L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpByte(int y, DumpState* D)
|
|
||||||
{
|
static void DumpByte (int y, DumpState *D) {
|
||||||
lu_byte x=(lu_byte)y;
|
lu_byte x = (lu_byte)y;
|
||||||
DumpVar(x,D);
|
DumpVar(x, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpInt(int x, DumpState* D)
|
|
||||||
{
|
static void DumpInt (int x, DumpState *D) {
|
||||||
DumpVar(x,D);
|
DumpVar(x, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpNumber(lua_Number x, DumpState* D)
|
|
||||||
{
|
static void DumpNumber (lua_Number x, DumpState *D) {
|
||||||
DumpVar(x,D);
|
DumpVar(x, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpInteger(lua_Integer x, DumpState* D)
|
|
||||||
{
|
static void DumpInteger (lua_Integer x, DumpState *D) {
|
||||||
DumpVar(x,D);
|
DumpVar(x, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpString(const TString* s, DumpState* D)
|
|
||||||
{
|
static void DumpString (const TString *s, DumpState *D) {
|
||||||
if (s==NULL) DumpByte(0,D);
|
if (s == NULL)
|
||||||
|
DumpByte(0, D);
|
||||||
else {
|
else {
|
||||||
size_t size = s->tsv.len+1; /* include trailing '\0' */
|
size_t size = s->tsv.len + 1; /* include trailing '\0' */
|
||||||
if (size < 0xFF) DumpByte(size,D);
|
if (size < 0xFF)
|
||||||
else
|
DumpByte(size, D);
|
||||||
{
|
else {
|
||||||
DumpByte(0xFF,D);
|
DumpByte(0xFF, D);
|
||||||
DumpVar(size,D);
|
DumpVar(size, D);
|
||||||
}
|
}
|
||||||
DumpVector(getstr(s),size-1,D); /* no need to save '\0' */
|
DumpVector(getstr(s), size - 1, D); /* no need to save '\0' */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpCode(const Proto* f, DumpState* D)
|
|
||||||
{
|
static void DumpCode (const Proto *f, DumpState *D) {
|
||||||
DumpInt(f->sizecode,D);
|
DumpInt(f->sizecode, D);
|
||||||
DumpVector(f->code,f->sizecode,D);
|
DumpVector(f->code, f->sizecode, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpFunction(const Proto* f, DumpState* D);
|
|
||||||
|
|
||||||
static void DumpConstants(const Proto* f, DumpState* D)
|
static void DumpFunction(const Proto *f, DumpState *D);
|
||||||
{
|
|
||||||
int i,n=f->sizek;
|
static void DumpConstants (const Proto *f, DumpState *D) {
|
||||||
DumpInt(n,D);
|
int i;
|
||||||
for (i=0; i<n; i++)
|
int n = f->sizek;
|
||||||
{
|
DumpInt(n, D);
|
||||||
const TValue* o=&f->k[i];
|
for (i = 0; i < n; i++) {
|
||||||
DumpByte(ttype(o),D);
|
const TValue *o = &f->k[i];
|
||||||
switch (ttype(o))
|
DumpByte(ttype(o), D);
|
||||||
{
|
switch (ttype(o)) {
|
||||||
case LUA_TNIL:
|
case LUA_TNIL:
|
||||||
break;
|
break;
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
DumpByte(bvalue(o),D);
|
DumpByte(bvalue(o), D);
|
||||||
break;
|
break;
|
||||||
case LUA_TNUMFLT:
|
case LUA_TNUMFLT:
|
||||||
DumpNumber(fltvalue(o),D);
|
DumpNumber(fltvalue(o), D);
|
||||||
break;
|
break;
|
||||||
case LUA_TNUMINT:
|
case LUA_TNUMINT:
|
||||||
DumpInteger(ivalue(o),D);
|
DumpInteger(ivalue(o), D);
|
||||||
break;
|
break;
|
||||||
case LUA_TSHRSTR: case LUA_TLNGSTR:
|
case LUA_TSHRSTR:
|
||||||
DumpString(rawtsvalue(o),D);
|
case LUA_TLNGSTR:
|
||||||
|
DumpString(rawtsvalue(o), D);
|
||||||
break;
|
break;
|
||||||
default: lua_assert(0);
|
default:
|
||||||
|
lua_assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n=f->sizep;
|
n = f->sizep;
|
||||||
DumpInt(n,D);
|
DumpInt(n, D);
|
||||||
for (i=0; i<n; i++) DumpFunction(f->p[i],D);
|
for (i = 0; i < n; i++)
|
||||||
|
DumpFunction(f->p[i], D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpUpvalues(const Proto* f, DumpState* D)
|
|
||||||
{
|
static void DumpUpvalues (const Proto *f, DumpState *D) {
|
||||||
int i,n=f->sizeupvalues;
|
int i, n = f->sizeupvalues;
|
||||||
DumpInt(n,D);
|
DumpInt(n, D);
|
||||||
for (i=0; i<n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
{
|
DumpByte(f->upvalues[i].instack, D);
|
||||||
DumpByte(f->upvalues[i].instack,D);
|
DumpByte(f->upvalues[i].idx, D);
|
||||||
DumpByte(f->upvalues[i].idx,D);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpDebug(const Proto* f, DumpState* D)
|
|
||||||
{
|
static void DumpDebug (const Proto *f, DumpState *D) {
|
||||||
int i,n;
|
int i, n;
|
||||||
DumpString((D->strip) ? NULL : f->source,D);
|
DumpString((D->strip) ? NULL : f->source, D);
|
||||||
n= (D->strip) ? 0 : f->sizelineinfo;
|
n = (D->strip) ? 0 : f->sizelineinfo;
|
||||||
DumpInt(n,D);
|
DumpInt(n, D);
|
||||||
DumpVector(f->lineinfo,n,D);
|
DumpVector(f->lineinfo, n, D);
|
||||||
n= (D->strip) ? 0 : f->sizelocvars;
|
n = (D->strip) ? 0 : f->sizelocvars;
|
||||||
DumpInt(n,D);
|
DumpInt(n, D);
|
||||||
for (i=0; i<n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
{
|
DumpString(f->locvars[i].varname, D);
|
||||||
DumpString(f->locvars[i].varname,D);
|
DumpInt(f->locvars[i].startpc, D);
|
||||||
DumpInt(f->locvars[i].startpc,D);
|
DumpInt(f->locvars[i].endpc, D);
|
||||||
DumpInt(f->locvars[i].endpc,D);
|
|
||||||
}
|
}
|
||||||
n= (D->strip) ? 0 : f->sizeupvalues;
|
n = (D->strip) ? 0 : f->sizeupvalues;
|
||||||
DumpInt(n,D);
|
DumpInt(n, D);
|
||||||
for (i=0; i<n; i++) DumpString(f->upvalues[i].name,D);
|
for (i = 0; i < n; i++)
|
||||||
|
DumpString(f->upvalues[i].name, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpFunction(const Proto* f, DumpState* D)
|
|
||||||
{
|
static void DumpFunction (const Proto *f, DumpState *D) {
|
||||||
DumpInt(f->linedefined,D);
|
DumpInt(f->linedefined, D);
|
||||||
DumpInt(f->lastlinedefined,D);
|
DumpInt(f->lastlinedefined, 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);
|
||||||
DumpCode(f,D);
|
DumpCode(f, D);
|
||||||
DumpConstants(f,D);
|
DumpConstants(f, D);
|
||||||
DumpUpvalues(f,D);
|
DumpUpvalues(f, D);
|
||||||
DumpDebug(f,D);
|
DumpDebug(f, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpHeader(DumpState* D)
|
|
||||||
{
|
static void DumpHeader (DumpState *D) {
|
||||||
DumpBlock(LUA_SIGNATURE,sizeof(LUA_SIGNATURE),D);
|
DumpBlock(LUA_SIGNATURE, sizeof(LUA_SIGNATURE), D);
|
||||||
DumpBlock(LUAC_DATA,sizeof(LUAC_DATA),D);
|
DumpBlock(LUAC_DATA, sizeof(LUAC_DATA), D);
|
||||||
DumpByte(LUAC_VERSION,D);
|
DumpByte(LUAC_VERSION, D);
|
||||||
DumpByte(LUAC_FORMAT,D);
|
DumpByte(LUAC_FORMAT, D);
|
||||||
DumpByte(sizeof(int),D);
|
DumpByte(sizeof(int), D);
|
||||||
DumpByte(sizeof(size_t),D);
|
DumpByte(sizeof(size_t), D);
|
||||||
DumpByte(sizeof(Instruction),D);
|
DumpByte(sizeof(Instruction), D);
|
||||||
DumpByte(sizeof(lua_Integer),D);
|
DumpByte(sizeof(lua_Integer), D);
|
||||||
DumpByte(sizeof(lua_Number),D);
|
DumpByte(sizeof(lua_Number), D);
|
||||||
DumpInteger(LUAC_INT,D);
|
DumpInteger(LUAC_INT, D);
|
||||||
DumpNumber(LUAC_NUM,D);
|
DumpNumber(LUAC_NUM, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** dump Lua function as precompiled chunk
|
** dump Lua function as precompiled chunk
|
||||||
*/
|
*/
|
||||||
int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
|
int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,
|
||||||
{
|
int strip) {
|
||||||
DumpState D;
|
DumpState D;
|
||||||
D.L=L;
|
D.L = L;
|
||||||
D.writer=w;
|
D.writer = w;
|
||||||
D.data=data;
|
D.data = data;
|
||||||
D.strip=strip;
|
D.strip = strip;
|
||||||
D.status=0;
|
D.status = 0;
|
||||||
DumpHeader(&D);
|
DumpHeader(&D);
|
||||||
DumpByte(f->sizeupvalues,&D);
|
DumpByte(f->sizeupvalues, &D);
|
||||||
DumpFunction(f,&D);
|
DumpFunction(f, &D);
|
||||||
return D.status;
|
return D.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
317
lundump.c
317
lundump.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lundump.c,v 2.29 2014/02/28 16:13:01 roberto Exp roberto $
|
** $Id: lundump.c,v 2.30 2014/03/01 15:18:44 roberto Exp roberto $
|
||||||
** load precompiled Lua chunks
|
** load precompiled Lua chunks
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -20,18 +20,6 @@
|
|||||||
#include "lundump.h"
|
#include "lundump.h"
|
||||||
#include "lzio.h"
|
#include "lzio.h"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
lua_State* L;
|
|
||||||
ZIO* Z;
|
|
||||||
Mbuffer* b;
|
|
||||||
const char* name;
|
|
||||||
} LoadState;
|
|
||||||
|
|
||||||
static l_noret error(LoadState* S, const char* why)
|
|
||||||
{
|
|
||||||
luaO_pushfstring(S->L,"%s: %s precompiled chunk",S->name,why);
|
|
||||||
luaD_throw(S->L,LUA_ERRSYNTAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define LoadVar(S,x) LoadBlock(S,&x,sizeof(x))
|
#define LoadVar(S,x) LoadBlock(S,&x,sizeof(x))
|
||||||
#define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0]))
|
#define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0]))
|
||||||
@@ -40,207 +28,234 @@ static l_noret error(LoadState* S, const char* why)
|
|||||||
#define luai_verifycode(L,b,f) /* empty */
|
#define luai_verifycode(L,b,f) /* empty */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void LoadBlock(LoadState* S, void* b, size_t size)
|
|
||||||
{
|
typedef struct {
|
||||||
if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
|
lua_State *L;
|
||||||
|
ZIO *Z;
|
||||||
|
Mbuffer *b;
|
||||||
|
const char *name;
|
||||||
|
} LoadState;
|
||||||
|
|
||||||
|
|
||||||
|
static l_noret error(LoadState *S, const char *why) {
|
||||||
|
luaO_pushfstring(S->L, "%s: %s precompiled chunk", S->name, why);
|
||||||
|
luaD_throw(S->L, LUA_ERRSYNTAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static lu_byte LoadByte(LoadState* S)
|
|
||||||
{
|
static void LoadBlock (LoadState *S, void *b, size_t size) {
|
||||||
|
if (luaZ_read(S->Z, b, size) != 0)
|
||||||
|
error(S, "truncated");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static lu_byte LoadByte (LoadState *S) {
|
||||||
lu_byte x;
|
lu_byte x;
|
||||||
LoadVar(S,x);
|
LoadVar(S, x);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LoadInt(LoadState* S)
|
|
||||||
{
|
static int LoadInt (LoadState *S) {
|
||||||
int x;
|
int x;
|
||||||
LoadVar(S,x);
|
LoadVar(S, x);
|
||||||
if (x<0) error(S,"corrupted");
|
if (x < 0)
|
||||||
|
error(S, "corrupted");
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static lua_Number LoadNumber(LoadState* S)
|
|
||||||
{
|
static lua_Number LoadNumber (LoadState *S) {
|
||||||
lua_Number x;
|
lua_Number x;
|
||||||
LoadVar(S,x);
|
LoadVar(S, x);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static lua_Integer LoadInteger(LoadState* S)
|
|
||||||
{
|
static lua_Integer LoadInteger (LoadState *S) {
|
||||||
lua_Integer x;
|
lua_Integer x;
|
||||||
LoadVar(S,x);
|
LoadVar(S, x);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static TString* LoadString(LoadState* S)
|
|
||||||
{
|
static TString *LoadString (LoadState *S) {
|
||||||
size_t size = LoadByte(S);
|
size_t size = LoadByte(S);
|
||||||
if (size == 0xFF) LoadVar(S,size);
|
if (size == 0xFF)
|
||||||
if (size==0)
|
LoadVar(S, size);
|
||||||
|
if (size == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
else
|
else {
|
||||||
{
|
char *s = luaZ_openspace(S->L, S->b, --size);
|
||||||
char* s=luaZ_openspace(S->L,S->b,--size);
|
LoadVector(S, s, size);
|
||||||
LoadVector(S,s,size);
|
return luaS_newlstr(S->L, s, size);
|
||||||
return luaS_newlstr(S->L,s,size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadCode(LoadState* S, Proto* f)
|
|
||||||
{
|
static void LoadCode (LoadState *S, Proto *f) {
|
||||||
int n=LoadInt(S);
|
int n = LoadInt(S);
|
||||||
f->code=luaM_newvector(S->L,n,Instruction);
|
f->code = luaM_newvector(S->L, n, Instruction);
|
||||||
f->sizecode=n;
|
f->sizecode = n;
|
||||||
LoadVector(S,f->code,n);
|
LoadVector(S, f->code, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadFunction(LoadState* S, Proto* f);
|
|
||||||
|
|
||||||
static void LoadConstants(LoadState* S, Proto* f)
|
static void LoadFunction(LoadState *S, Proto *f);
|
||||||
{
|
|
||||||
int i,n;
|
|
||||||
n=LoadInt(S);
|
static void LoadConstants (LoadState *S, Proto *f) {
|
||||||
f->k=luaM_newvector(S->L,n,TValue);
|
int i, n;
|
||||||
f->sizek=n;
|
n = LoadInt(S);
|
||||||
for (i=0; i<n; i++) setnilvalue(&f->k[i]);
|
f->k = luaM_newvector(S->L, n, TValue);
|
||||||
for (i=0; i<n; i++)
|
f->sizek = n;
|
||||||
{
|
for (i = 0; i < n; i++)
|
||||||
TValue* o=&f->k[i];
|
setnilvalue(&f->k[i]);
|
||||||
int t=LoadByte(S);
|
for (i = 0; i < n; i++) {
|
||||||
switch (t)
|
TValue *o = &f->k[i];
|
||||||
{
|
int t = LoadByte(S);
|
||||||
|
switch (t) {
|
||||||
case LUA_TNIL:
|
case LUA_TNIL:
|
||||||
setnilvalue(o);
|
setnilvalue(o);
|
||||||
break;
|
break;
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
setbvalue(o,LoadByte(S));
|
setbvalue(o, LoadByte(S));
|
||||||
break;
|
break;
|
||||||
case LUA_TNUMFLT:
|
case LUA_TNUMFLT:
|
||||||
setnvalue(o,LoadNumber(S));
|
setnvalue(o, LoadNumber(S));
|
||||||
break;
|
break;
|
||||||
case LUA_TNUMINT:
|
case LUA_TNUMINT:
|
||||||
setivalue(o,LoadInteger(S));
|
setivalue(o, LoadInteger(S));
|
||||||
break;
|
break;
|
||||||
case LUA_TSHRSTR: case LUA_TLNGSTR:
|
case LUA_TSHRSTR:
|
||||||
setsvalue2n(S->L,o,LoadString(S));
|
case LUA_TLNGSTR:
|
||||||
|
setsvalue2n(S->L, o, LoadString(S));
|
||||||
break;
|
break;
|
||||||
default: lua_assert(0);
|
default:
|
||||||
|
lua_assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n=LoadInt(S);
|
n = LoadInt(S);
|
||||||
f->p=luaM_newvector(S->L,n,Proto*);
|
f->p = luaM_newvector(S->L, n, Proto *);
|
||||||
f->sizep=n;
|
f->sizep = n;
|
||||||
for (i=0; i<n; i++) f->p[i]=NULL;
|
for (i = 0; i < n; i++)
|
||||||
for (i=0; i<n; i++)
|
f->p[i] = NULL;
|
||||||
{
|
for (i = 0; i < n; i++) {
|
||||||
f->p[i]=luaF_newproto(S->L);
|
f->p[i] = luaF_newproto(S->L);
|
||||||
LoadFunction(S,f->p[i]);
|
LoadFunction(S, f->p[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadUpvalues(LoadState* S, Proto* f)
|
|
||||||
{
|
static void LoadUpvalues (LoadState *S, Proto *f) {
|
||||||
int i,n;
|
int i, n;
|
||||||
n=LoadInt(S);
|
n = LoadInt(S);
|
||||||
f->upvalues=luaM_newvector(S->L,n,Upvaldesc);
|
f->upvalues = luaM_newvector(S->L, n, Upvaldesc);
|
||||||
f->sizeupvalues=n;
|
f->sizeupvalues = n;
|
||||||
for (i=0; i<n; i++) f->upvalues[i].name=NULL;
|
for (i = 0; i < n; i++)
|
||||||
for (i=0; i<n; i++)
|
f->upvalues[i].name = NULL;
|
||||||
{
|
for (i = 0; i < n; i++) {
|
||||||
f->upvalues[i].instack=LoadByte(S);
|
f->upvalues[i].instack = LoadByte(S);
|
||||||
f->upvalues[i].idx=LoadByte(S);
|
f->upvalues[i].idx = LoadByte(S);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadDebug(LoadState* S, Proto* f)
|
|
||||||
{
|
static void LoadDebug (LoadState *S, Proto *f) {
|
||||||
int i,n;
|
int i, n;
|
||||||
f->source=LoadString(S);
|
f->source = LoadString(S);
|
||||||
n=LoadInt(S);
|
n = LoadInt(S);
|
||||||
f->lineinfo=luaM_newvector(S->L,n,int);
|
f->lineinfo = luaM_newvector(S->L, n, int);
|
||||||
f->sizelineinfo=n;
|
f->sizelineinfo = n;
|
||||||
LoadVector(S,f->lineinfo,n);
|
LoadVector(S, f->lineinfo, n);
|
||||||
n=LoadInt(S);
|
n = LoadInt(S);
|
||||||
f->locvars=luaM_newvector(S->L,n,LocVar);
|
f->locvars = luaM_newvector(S->L, n, LocVar);
|
||||||
f->sizelocvars=n;
|
f->sizelocvars = n;
|
||||||
for (i=0; i<n; i++) f->locvars[i].varname=NULL;
|
for (i = 0; i < n; i++)
|
||||||
for (i=0; i<n; i++)
|
f->locvars[i].varname = NULL;
|
||||||
{
|
for (i = 0; i < n; i++) {
|
||||||
f->locvars[i].varname=LoadString(S);
|
f->locvars[i].varname = LoadString(S);
|
||||||
f->locvars[i].startpc=LoadInt(S);
|
f->locvars[i].startpc = LoadInt(S);
|
||||||
f->locvars[i].endpc=LoadInt(S);
|
f->locvars[i].endpc = LoadInt(S);
|
||||||
}
|
}
|
||||||
n=LoadInt(S);
|
n = LoadInt(S);
|
||||||
for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
|
for (i = 0; i < n; i++)
|
||||||
|
f->upvalues[i].name = LoadString(S);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadFunction(LoadState* S, Proto* f)
|
|
||||||
{
|
static void LoadFunction (LoadState *S, Proto *f) {
|
||||||
f->linedefined=LoadInt(S);
|
f->linedefined = LoadInt(S);
|
||||||
f->lastlinedefined=LoadInt(S);
|
f->lastlinedefined = 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);
|
||||||
LoadCode(S,f);
|
LoadCode(S, f);
|
||||||
LoadConstants(S,f);
|
LoadConstants(S, f);
|
||||||
LoadUpvalues(S,f);
|
LoadUpvalues(S, f);
|
||||||
LoadDebug(S,f);
|
LoadDebug(S, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkstring(LoadState *S, const char *s, const char *msg)
|
|
||||||
{
|
static void checkstring (LoadState *S, const char *s, const char *msg) {
|
||||||
char buff[sizeof(LUA_SIGNATURE)+sizeof(LUAC_DATA)]; /* larger than each */
|
char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than each */
|
||||||
LoadVector(S,buff,strlen(s)+1);
|
LoadVector(S, buff, strlen(s) + 1);
|
||||||
if (strcmp(s,buff)!=0) error(S,msg);
|
if (strcmp(s, buff) != 0)
|
||||||
|
error(S, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fchecksize(LoadState *S, size_t size, const char *tname)
|
|
||||||
{
|
static void fchecksize (LoadState *S, size_t size, const char *tname) {
|
||||||
if (LoadByte(S) != size)
|
if (LoadByte(S) != size)
|
||||||
error(S,luaO_pushfstring(S->L,"%s size mismatch in",tname));
|
error(S, luaO_pushfstring(S->L, "%s size mismatch in", tname));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define checksize(S,t) fchecksize(S,sizeof(t),#t)
|
#define checksize(S,t) fchecksize(S,sizeof(t),#t)
|
||||||
|
|
||||||
static void checkHeader(LoadState* S)
|
static void checkHeader (LoadState *S) {
|
||||||
{
|
checkstring(S, LUA_SIGNATURE + 1, "not a");
|
||||||
checkstring(S,LUA_SIGNATURE+1,"not a");
|
checkstring(S, LUAC_DATA, "corrupted");
|
||||||
checkstring(S,LUAC_DATA,"corrupted");
|
if (LoadByte(S) != LUAC_VERSION)
|
||||||
if (LoadByte(S) != LUAC_VERSION) error(S,"version mismatch in");
|
error(S, "version mismatch in");
|
||||||
if (LoadByte(S) != LUAC_FORMAT) error(S,"format mismatch in");
|
if (LoadByte(S) != LUAC_FORMAT)
|
||||||
checksize(S,int);
|
error(S, "format mismatch in");
|
||||||
checksize(S,size_t);
|
checksize(S, int);
|
||||||
checksize(S,Instruction);
|
checksize(S, size_t);
|
||||||
checksize(S,lua_Integer);
|
checksize(S, Instruction);
|
||||||
checksize(S,lua_Number);
|
checksize(S, lua_Integer);
|
||||||
if (LoadInteger(S) != LUAC_INT) error(S,"endianess mismatch in");
|
checksize(S, lua_Number);
|
||||||
if (LoadNumber(S) != LUAC_NUM) error(S,"float format mismatch in");
|
if (LoadInteger(S) != LUAC_INT)
|
||||||
|
error(S, "endianess mismatch in");
|
||||||
|
if (LoadNumber(S) != LUAC_NUM)
|
||||||
|
error(S, "float format mismatch in");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** load precompiled chunk
|
** load precompiled chunk
|
||||||
*/
|
*/
|
||||||
Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
|
Closure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff,
|
||||||
{
|
const char *name) {
|
||||||
LoadState S;
|
LoadState S;
|
||||||
Closure* cl;
|
Closure *cl;
|
||||||
if (*name=='@' || *name=='=')
|
if (*name == '@' || *name == '=')
|
||||||
S.name=name+1;
|
S.name = name + 1;
|
||||||
else if (*name==LUA_SIGNATURE[0])
|
else if (*name == LUA_SIGNATURE[0])
|
||||||
S.name="binary string";
|
S.name = "binary string";
|
||||||
else
|
else
|
||||||
S.name=name;
|
S.name = name;
|
||||||
S.L=L;
|
S.L = L;
|
||||||
S.Z=Z;
|
S.Z = Z;
|
||||||
S.b=buff;
|
S.b = buff;
|
||||||
checkHeader(&S);
|
checkHeader(&S);
|
||||||
cl=luaF_newLclosure(L,LoadByte(&S));
|
cl = luaF_newLclosure(L, LoadByte(&S));
|
||||||
setclLvalue(L,L->top,cl); incr_top(L);
|
setclLvalue(L, L->top, cl);
|
||||||
cl->l.p=luaF_newproto(L);
|
incr_top(L);
|
||||||
LoadFunction(&S,cl->l.p);
|
cl->l.p = luaF_newproto(L);
|
||||||
lua_assert(cl->l.nupvalues==cl->l.p->sizeupvalues);
|
LoadFunction(&S, cl->l.p);
|
||||||
luai_verifycode(L,buff,cl->l.p);
|
lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
|
||||||
|
luai_verifycode(L, buff, cl->l.p);
|
||||||
return cl;
|
return cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user