Skip to content

Commit

Permalink
Added strip option to string.dump
Browse files Browse the repository at this point in the history
  • Loading branch information
MCJack123 committed Apr 15, 2022
1 parent 149f5d4 commit b984a49
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,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_dump53) (lua_State *L, lua_Writer writer, void *data, int strip);

LUA_API void *lua_vcontext (lua_State *L);

Expand Down
9 changes: 7 additions & 2 deletions src/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,21 +976,26 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
}


LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
LUA_API int lua_dump53 (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);
return status;
}


LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
return lua_dump53(L, writer, data, 0);
}


LUA_API int lua_status (lua_State *L) {
return L->status;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lstrlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ static int writer (lua_State *L, const void* b, size_t size, void* B) {

static int str_dump (lua_State *L) {
luaL_Buffer b;
int strip = lua_gettop(L) > 1 && lua_toboolean(L, 2);
luaL_checktype(L, 1, LUA_TFUNCTION);
lua_settop(L, 1);
luaL_buffinit(L,&b);
if (lua_dump(L, writer, &b) != 0)
if (lua_dump53(L, writer, &b, strip) != 0)
luaL_error(L, "unable to dump given function");
luaL_pushresult(&b);
return 1;
Expand Down
1 change: 1 addition & 0 deletions src/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,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_dump53) (lua_State *L, lua_Writer writer, void *data, int strip);

LUA_API void *lua_vcontext (lua_State *L);

Expand Down

0 comments on commit b984a49

Please sign in to comment.