From 9b2f23319c5ac84927774fca02b99bbb98057ebd Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Mon, 3 May 2021 23:06:40 -0400 Subject: lua fix yellow and add temploader temp loader allows some lua requires to be loaded and later garbage collected unfortunately the module needs to be formatted in such a way to pass back a call table in order to keep the functions within from being garbage collected too early BE AWARE this bypasses the module loader which would allow code reuse so if you aren't careful this memory saving tool could spell disaster for free RAM if you load the same code multiple times Change-Id: I0b6f81e481b8c779edbd620c8403794f8353926f --- apps/plugins/lua/rocklib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'apps/plugins/lua/rocklib.c') diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 050fbc73b2..2672d446fc 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -153,7 +153,7 @@ RB_WRAP(kbd_input) const char *input = lua_tostring(L, 1); size_t layout_len; - const char *layout = lua_tolstring(L, 2, &layout_len); + const unsigned char *layout = lua_tolstring(L, 2, &layout_len); char *buffer = luaL_prepbuffer(&b); if(input != NULL) @@ -161,8 +161,12 @@ RB_WRAP(kbd_input) else buffer[0] = '\0'; - if(layout_len <= 1 || (unsigned short)layout[layout_len - 1] != 0xFFFE) + if(layout_len <= 2 || + layout[layout_len - 1] != 0xFE || + layout[layout_len - 2] != 0xFF) + { layout = NULL; + } if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE, (unsigned short *)layout)) { -- cgit v1.2.3