[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.dump strip option (5.2 request)
- From: Thomas Harning <harningt@...>
- Date: Tue, 26 Feb 2008 11:36:36 -0500
Daan Nusman wrote:
Hi,
1) I was thinking, for 5.2, why not add a boolean option string.dump
so that to string.dump(f, true) produces bytecode without debug
information.
Right now it is impossible to create stripped bytecode from within a
normally compiled Lua interpreter (not counting luac of course), not
even with a custom-made C function, because lua_dump also does not
expose a "strip" parameter, so
2) let's change lua_dump to include the strip parameter too :)
Simple patch and equally simply tested...
> function test()
>> error("BAD")
>> end
> x1 = string.dump(test)
> =#x1
123
> x2 = string.dump(test,true)
> =#x2
100
> loadstring(x1)()
stdin:2: BAD
stack traceback:
[C]: in function 'error'
stdin:2: in function <stdin:1>
stdin:1: in main chunk
[C]: ?
> loadstring(x2)()
BAD
stack traceback:
[C]: in function 'error'
?: in function <?:1>
stdin:1: in main chunk
[C]: ?
diff -u -ru lua-5.1.3/src/lapi.c lua-5.1.3-dumpstrip/src/lapi.c
--- lua-5.1.3/src/lapi.c 2008-01-28 10:12:52.000000000 -0500
+++ lua-5.1.3-dumpstrip/src/lapi.c 2008-02-26 11:06:29.000000000 -0500
@@ -873,14 +873,14 @@
}
-LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
+LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {
int status;
TValue *o;
lua_lock(L);
api_checknelems(L, 1);
o = L->top - 1;
if (isLfunction(o))
- status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);
+ status = luaU_dump(L, clvalue(o)->l.p, writer, data, strip);
else
status = 1;
lua_unlock(L);
diff -u -ru lua-5.1.3/src/lstrlib.c lua-5.1.3-dumpstrip/src/lstrlib.c
--- lua-5.1.3/src/lstrlib.c 2007-12-28 10:32:23.000000000 -0500
+++ lua-5.1.3-dumpstrip/src/lstrlib.c 2008-02-26 11:08:43.000000000 -0500
@@ -145,10 +145,12 @@
static int str_dump (lua_State *L) {
luaL_Buffer b;
+ int strip = 0;
luaL_checktype(L, 1, LUA_TFUNCTION);
+ strip = lua_toboolean(L, 2);
lua_settop(L, 1);
luaL_buffinit(L,&b);
- if (lua_dump(L, writer, &b) != 0)
+ if (lua_dump(L, writer, &b, strip) != 0)
luaL_error(L, "unable to dump given function");
luaL_pushresult(&b);
return 1;
diff -u -ru lua-5.1.3/src/lua.h lua-5.1.3-dumpstrip/src/lua.h
--- lua-5.1.3/src/lua.h 2008-01-28 10:12:52.000000000 -0500
+++ lua-5.1.3-dumpstrip/src/lua.h 2008-02-26 11:08:55.000000000 -0500
@@ -204,7 +204,7 @@
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname);
-LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
+LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
/*