summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lauxlib.c
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-11-11 18:27:19 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-07-11 00:31:41 +0200
commitc6fcb1cf45b249b059c2d53a062f9a6c7f449047 (patch)
tree229eacd12461605a8320eb7590ff83eea13538d6 /apps/plugins/lua/lauxlib.c
parent42240f6990156fb907a7dce7258be2f1235fab44 (diff)
downloadrockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.zip
rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.tar.gz
rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.tar.bz2
rockbox-c6fcb1cf45b249b059c2d53a062f9a6c7f449047.tar.xz
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/lauxlib.c')
-rw-r--r--apps/plugins/lua/lauxlib.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c
index 9597f63..5e7c159 100644
--- a/apps/plugins/lua/lauxlib.c
+++ b/apps/plugins/lua/lauxlib.c
@@ -11,10 +11,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "lstring.h" /* ROCKLUA ADDED */
/* This file uses only the official API of Lua.
** Any function declared here could be written as an application function.
+** Note ** luaS_newlloc breaks this guarantee ROCKLUA ADDED
*/
#define lauxlib_c
@@ -239,23 +241,36 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
}
+ /* ROCKLUA ADDED */
+static int libsize_storenames (lua_State *L, const char* libname, const luaL_Reg *l) {
+ int size = 0;
+ if (libname)
+ luaS_newlloc(L, libname, TSTR_INBIN);
+ for (; l->name; l++) {
+ size++;
+ luaS_newlloc(L, l->name, TSTR_INBIN);
+ }
+ return size;
+}
+
+
LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
const luaL_Reg *l) {
luaI_openlib(L, libname, l, 0);
}
-
+#if 0
static int libsize (const luaL_Reg *l) {
int size = 0;
for (; l->name; l++) size++;
return size;
}
-
+#endif
LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
const luaL_Reg *l, int nup) {
+ int size = libsize_storenames(L, libname, l);
if (libname) {
- int size = libsize(l);
/* check whether lib already exists */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
lua_getfield(L, -1, libname); /* get _LOADED[libname] */