diff options
author | William Wilgus <me.theuser@yahoo.com> | 2018-11-11 18:27:19 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2019-07-11 00:31:41 +0200 |
commit | c6fcb1cf45b249b059c2d53a062f9a6c7f449047 (patch) | |
tree | 229eacd12461605a8320eb7590ff83eea13538d6 /apps/plugins/lua/rocklib.c | |
parent | 42240f6990156fb907a7dce7258be2f1235fab44 (diff) | |
download | rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.tar.gz rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.zip |
lua inbinary strings
Allows saving of ram by reusing strings already stored in the binary
and storing a pointer instead of malloc and copy to get them inside
the lua state
Saves about 1.5K overall
Derivative of work by bogdanm
RAM optimizations: pseudo RO strings, functions in Flash
https://github.com/elua/elua/commit/d54659b5723bcd2b1e3900362398c72c18a9aa0b
Change-Id: I21d6dcfa32523877efd9f70fb0f88f2a02872649
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r-- | apps/plugins/lua/rocklib.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 9ad6411b2f..426dd079af 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #define LUA_LIB | 25 | #define LUA_LIB |
26 | 26 | ||
27 | #include "lua.h" | 27 | #include "lua.h" |
28 | #include "lstring.h" | ||
28 | 29 | ||
29 | #include "lauxlib.h" | 30 | #include "lauxlib.h" |
30 | #include "rocklib.h" | 31 | #include "rocklib.h" |
@@ -835,6 +836,7 @@ LUALIB_API int luaopen_rock(lua_State *L) | |||
835 | static const struct lua_int_reg* rlci = rlib_const_int; | 836 | static const struct lua_int_reg* rlci = rlib_const_int; |
836 | for (; rlci->name; rlci++) { | 837 | for (; rlci->name; rlci++) { |
837 | lua_pushinteger(L, rlci->value); | 838 | lua_pushinteger(L, rlci->value); |
839 | luaS_newlloc(L, rlci->name, TSTR_INBIN); | ||
838 | lua_setfield(L, -2, rlci->name); | 840 | lua_setfield(L, -2, rlci->name); |
839 | } | 841 | } |
840 | 842 | ||
@@ -853,7 +855,9 @@ LUALIB_API int luaopen_rock(lua_State *L) | |||
853 | 855 | ||
854 | static const struct lua_str_reg* rlcs = rlib_const_str; | 856 | static const struct lua_str_reg* rlcs = rlib_const_str; |
855 | for (; rlcs->name; rlcs++) { | 857 | for (; rlcs->name; rlcs++) { |
858 | luaS_newlloc(L, rlcs->value, TSTR_INBIN); | ||
856 | lua_pushstring(L, rlcs->value); | 859 | lua_pushstring(L, rlcs->value); |
860 | luaS_newlloc(L, rlcs->name, TSTR_INBIN); | ||
857 | lua_setfield(L, -2, rlcs->name); | 861 | lua_setfield(L, -2, rlcs->name); |
858 | } | 862 | } |
859 | 863 | ||