diff options
author | William Wilgus <me.theuser@yahoo.com> | 2019-08-05 00:03:08 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2019-08-08 07:11:30 +0200 |
commit | d61ea6c5eeef4343e40c0225f22ad39c994f84a9 (patch) | |
tree | 13a5e6261dda3fda33aa7ae743105fc3f2bc2e39 /apps/plugins/lua/lbaselib.c | |
parent | 1dabca6c267c2f8dfc8c0fb9269877856c00d4f1 (diff) | |
download | rockbox-d61ea6c5eeef4343e40c0225f22ad39c994f84a9.tar.gz rockbox-d61ea6c5eeef4343e40c0225f22ad39c994f84a9.zip |
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
Diffstat (limited to 'apps/plugins/lua/lbaselib.c')
-rw-r--r-- | apps/plugins/lua/lbaselib.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/apps/plugins/lua/lbaselib.c b/apps/plugins/lua/lbaselib.c index ad94984191..cb7b29a92a 100644 --- a/apps/plugins/lua/lbaselib.c +++ b/apps/plugins/lua/lbaselib.c | |||
@@ -19,6 +19,13 @@ | |||
19 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
20 | #include "lualib.h" | 20 | #include "lualib.h" |
21 | 21 | ||
22 | #ifdef LUA_OPTIMIZE_DEBUG_USER | ||
23 | #include "lobject.h" | ||
24 | #include "lstate.h" | ||
25 | #include "ldebug.h" | ||
26 | #include "lfunc.h" | ||
27 | #endif | ||
28 | |||
22 | 29 | ||
23 | 30 | ||
24 | 31 | ||
@@ -302,6 +309,70 @@ static int luaB_loadfile (lua_State *L) { | |||
302 | } | 309 | } |
303 | 310 | ||
304 | 311 | ||
312 | #ifdef LUA_OPTIMIZE_DEBUG_USER | ||
313 | /* stripdebug([level[, function]]). | ||
314 | * level: 1 don't discard debug | ||
315 | * 2 discard Local and Upvalue debug info | ||
316 | * 3 discard Local, Upvalue and lineno debug info. | ||
317 | * function: Function to be stripped as per setfenv except 0 not permitted. | ||
318 | * If no arguments then the current default setting is returned. | ||
319 | * If function is omitted, this is the default setting for future compiles | ||
320 | * The function returns an estimated integer count of the bytes stripped. | ||
321 | */ | ||
322 | static int luaB_stripdebug (lua_State *L) { | ||
323 | int level; | ||
324 | |||
325 | if (L->top == L->base) { | ||
326 | lua_pushlightuserdata(L, &luaG_stripdebug); | ||
327 | lua_gettable(L, LUA_REGISTRYINDEX); | ||
328 | if (lua_isnil(L, -1)) { | ||
329 | lua_pop(L, 1); | ||
330 | lua_pushinteger(L, LUA_OPTIMIZE_DEBUG); | ||
331 | } | ||
332 | return 1; | ||
333 | } | ||
334 | |||
335 | level = luaL_checkint(L, 1); | ||
336 | if ((level <= 0) || (level > 3)) luaL_argerror(L, 1, "must in range 1-3"); | ||
337 | |||
338 | if (L->top == L->base + 1) { | ||
339 | /* Store the default level in the registry if no function parameter */ | ||
340 | lua_pushlightuserdata(L, &luaG_stripdebug); | ||
341 | lua_pushinteger(L, level); | ||
342 | lua_settable(L, LUA_REGISTRYINDEX); | ||
343 | lua_settop(L,0); | ||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | if (level == 1) { | ||
348 | lua_settop(L,0); | ||
349 | lua_pushinteger(L, 0); | ||
350 | return 1; | ||
351 | } | ||
352 | |||
353 | if (!lua_isfunction(L, 2)) { | ||
354 | int scope = luaL_checkint(L, 2); | ||
355 | if (scope > 0) { | ||
356 | /* if the function parameter is a +ve integer then climb to find function */ | ||
357 | lua_Debug ar; | ||
358 | lua_pop(L, 1); /* pop level as getinfo will replace it by the function */ | ||
359 | if (lua_getstack(L, scope, &ar)) { | ||
360 | lua_getinfo(L, "f", &ar); | ||
361 | } | ||
362 | } | ||
363 | } | ||
364 | |||
365 | if(!lua_isfunction(L, 2) || lua_iscfunction(L, -1)) luaL_argerror(L, 2, "must be a Lua Function"); | ||
366 | // lua_lock(L); | ||
367 | Proto *f = clvalue(L->base + 1)->l.p; | ||
368 | // lua_unlock(L); | ||
369 | lua_settop(L,0); | ||
370 | lua_pushinteger(L, luaG_stripdebug(L, f, level, 16)); | ||
371 | return 1; | ||
372 | } | ||
373 | #endif | ||
374 | |||
375 | |||
305 | /* | 376 | /* |
306 | ** Reader for generic `load' function: `lua_load' uses the | 377 | ** Reader for generic `load' function: `lua_load' uses the |
307 | ** stack for internal stuff, so the reader cannot change the | 378 | ** stack for internal stuff, so the reader cannot change the |
@@ -482,6 +553,9 @@ static const luaL_Reg base_funcs[] = { | |||
482 | {"select", luaB_select}, | 553 | {"select", luaB_select}, |
483 | {"setfenv", luaB_setfenv}, | 554 | {"setfenv", luaB_setfenv}, |
484 | {"setmetatable", luaB_setmetatable}, | 555 | {"setmetatable", luaB_setmetatable}, |
556 | #ifdef LUA_OPTIMIZE_DEBUG_USER | ||
557 | {"stripdebug", luaB_stripdebug}, | ||
558 | #endif | ||
485 | {"tonumber", luaB_tonumber}, | 559 | {"tonumber", luaB_tonumber}, |
486 | {"tostring", luaB_tostring}, | 560 | {"tostring", luaB_tostring}, |
487 | {"type", luaB_type}, | 561 | {"type", luaB_type}, |