瀏覽代碼

no more checks for non-default compilation options + luaU_dump has
new option to strip debug info

Roberto Ierusalimschy 22 年之前
父節點
當前提交
433cb1d13a
共有 4 個文件被更改,包括 14 次插入22 次删除
  1. 3 5
      lapi.c
  2. 8 10
      ldump.c
  3. 1 5
      lundump.c
  4. 2 2
      lundump.h

+ 3 - 5
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 1.239 2003/05/14 21:06:56 roberto Exp roberto $
+** $Id: lapi.c,v 1.240 2003/07/07 13:34:25 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -732,10 +732,8 @@ LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) {
   lua_lock(L);
   api_checknelems(L, 1);
   o = L->top - 1;
-  if (isLfunction(o) && clvalue(o)->l.nupvalues == 0) {
-    luaU_dump(L, clvalue(o)->l.p, writer, data);
-    status = 1;
-  }
+  if (isLfunction(o) && clvalue(o)->l.nupvalues == 0)
+    status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);
   else
     status = 0;
   lua_unlock(L);

+ 8 - 10
ldump.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldump.c,v 1.4 2003/02/11 23:52:12 lhf Exp $
+** $Id: ldump.c,v 1.4 2003/02/11 23:52:12 lhf Exp lhf $
 ** save bytecodes
 ** See Copyright Notice in lua.h
 */
@@ -22,6 +22,7 @@ typedef struct {
  lua_State* L;
  lua_Chunkwriter write;
  void* data;
+ int strip;
 } DumpState;
 
 static void DumpBlock(const void* b, size_t size, DumpState* D)
@@ -132,9 +133,9 @@ static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
  DumpByte(f->numparams,D);
  DumpByte(f->is_vararg,D);
  DumpByte(f->maxstacksize,D);
- DumpLines(f,D);
- DumpLocals(f,D);
- DumpUpvalues(f,D);
+ if (D->strip) DumpInt(0,D); else DumpLines(f,D);
+ if (D->strip) DumpInt(0,D); else DumpLocals(f,D);
+ if (D->strip) DumpInt(0,D); else DumpUpvalues(f,D);
  DumpConstants(f,D);
  DumpCode(f,D);
 }
@@ -147,10 +148,6 @@ static void DumpHeader(DumpState* D)
  DumpByte(sizeof(int),D);
  DumpByte(sizeof(size_t),D);
  DumpByte(sizeof(Instruction),D);
- DumpByte(SIZE_OP,D);
- DumpByte(SIZE_A,D);
- DumpByte(SIZE_B,D);
- DumpByte(SIZE_C,D);
  DumpByte(sizeof(lua_Number),D);
  DumpNumber(TEST_NUMBER,D);
 }
@@ -158,13 +155,14 @@ static void DumpHeader(DumpState* D)
 /*
 ** dump function as precompiled chunk
 */
-void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data)
+int luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data, int strip)
 {
  DumpState D;
  D.L=L;
  D.write=w;
  D.data=data;
+ D.strip=strip;
  DumpHeader(&D);
  DumpFunction(Main,NULL,&D);
+ return 1;
 }
-

+ 1 - 5
lundump.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.c,v 1.49 2003/04/07 20:34:20 lhf Exp $
+** $Id: lundump.c,v 1.49 2003/04/07 20:34:20 lhf Exp lhf $
 ** load pre-compiled Lua chunks
 ** See Copyright Notice in lua.h
 */
@@ -241,10 +241,6 @@ static void LoadHeader (LoadState* S)
  TESTSIZE(sizeof(int),"int");
  TESTSIZE(sizeof(size_t), "size_t");
  TESTSIZE(sizeof(Instruction), "Instruction");
- TESTSIZE(SIZE_OP, "OP");
- TESTSIZE(SIZE_A, "A");
- TESTSIZE(SIZE_B, "B");
- TESTSIZE(SIZE_C, "C");
  TESTSIZE(sizeof(lua_Number), "number");
  x=LoadNumber(S);
  if ((long)x!=(long)tx)		/* disregard errors in last bits of fraction */

+ 2 - 2
lundump.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.h,v 1.31 2003/04/10 17:39:41 roberto Exp roberto $
+** $Id: lundump.h,v 1.30 2003/04/07 20:34:20 lhf Exp lhf $
 ** load pre-compiled Lua chunks
 ** See Copyright Notice in lua.h
 */
@@ -17,7 +17,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff);
 int luaU_endianness (void);
 
 /* dump one chunk; from ldump.c */
-void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data);
+int luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data, int strip);
 
 /* print one chunk; from print.c */
 void luaU_print (const Proto* Main);