mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 10:37:38 -04:00
lua LCD (Lua Compact Debug) patch
LCD developed 9/2015 by Terry Ellison We've already discarded the ldebug module from lua it only makes sense to discard the debug info as well adds 1.5 K to the binary saves 8 Kb on the base state once scripts start getting called i've seen 10-50Kb savings but it all depends on what exactly you are running Change-Id: Ibb74f344df1c4c96380ec6c98b010a810e9ae9cc
This commit is contained in:
parent
1dabca6c26
commit
d61ea6c5ee
13 changed files with 373 additions and 6 deletions
|
@ -19,6 +19,13 @@
|
|||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
#ifdef LUA_OPTIMIZE_DEBUG_USER
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
#include "ldebug.h"
|
||||
#include "lfunc.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -302,6 +309,70 @@ static int luaB_loadfile (lua_State *L) {
|
|||
}
|
||||
|
||||
|
||||
#ifdef LUA_OPTIMIZE_DEBUG_USER
|
||||
/* stripdebug([level[, function]]).
|
||||
* level: 1 don't discard debug
|
||||
* 2 discard Local and Upvalue debug info
|
||||
* 3 discard Local, Upvalue and lineno debug info.
|
||||
* function: Function to be stripped as per setfenv except 0 not permitted.
|
||||
* If no arguments then the current default setting is returned.
|
||||
* If function is omitted, this is the default setting for future compiles
|
||||
* The function returns an estimated integer count of the bytes stripped.
|
||||
*/
|
||||
static int luaB_stripdebug (lua_State *L) {
|
||||
int level;
|
||||
|
||||
if (L->top == L->base) {
|
||||
lua_pushlightuserdata(L, &luaG_stripdebug);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
lua_pushinteger(L, LUA_OPTIMIZE_DEBUG);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
level = luaL_checkint(L, 1);
|
||||
if ((level <= 0) || (level > 3)) luaL_argerror(L, 1, "must in range 1-3");
|
||||
|
||||
if (L->top == L->base + 1) {
|
||||
/* Store the default level in the registry if no function parameter */
|
||||
lua_pushlightuserdata(L, &luaG_stripdebug);
|
||||
lua_pushinteger(L, level);
|
||||
lua_settable(L, LUA_REGISTRYINDEX);
|
||||
lua_settop(L,0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (level == 1) {
|
||||
lua_settop(L,0);
|
||||
lua_pushinteger(L, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!lua_isfunction(L, 2)) {
|
||||
int scope = luaL_checkint(L, 2);
|
||||
if (scope > 0) {
|
||||
/* if the function parameter is a +ve integer then climb to find function */
|
||||
lua_Debug ar;
|
||||
lua_pop(L, 1); /* pop level as getinfo will replace it by the function */
|
||||
if (lua_getstack(L, scope, &ar)) {
|
||||
lua_getinfo(L, "f", &ar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!lua_isfunction(L, 2) || lua_iscfunction(L, -1)) luaL_argerror(L, 2, "must be a Lua Function");
|
||||
// lua_lock(L);
|
||||
Proto *f = clvalue(L->base + 1)->l.p;
|
||||
// lua_unlock(L);
|
||||
lua_settop(L,0);
|
||||
lua_pushinteger(L, luaG_stripdebug(L, f, level, 16));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Reader for generic `load' function: `lua_load' uses the
|
||||
** stack for internal stuff, so the reader cannot change the
|
||||
|
@ -482,6 +553,9 @@ static const luaL_Reg base_funcs[] = {
|
|||
{"select", luaB_select},
|
||||
{"setfenv", luaB_setfenv},
|
||||
{"setmetatable", luaB_setmetatable},
|
||||
#ifdef LUA_OPTIMIZE_DEBUG_USER
|
||||
{"stripdebug", luaB_stripdebug},
|
||||
#endif
|
||||
{"tonumber", luaB_tonumber},
|
||||
{"tostring", luaB_tostring},
|
||||
{"type", luaB_type},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue