diff options
Diffstat (limited to 'apps/plugins/lua')
-rw-r--r-- | apps/plugins/lua/rocklib.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 5166291cf5..1b928c229c 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -131,17 +131,17 @@ RB_WRAP(kbd_input) | |||
131 | char *buffer = luaL_prepbuffer(&b); | 131 | char *buffer = luaL_prepbuffer(&b); |
132 | 132 | ||
133 | if(input != NULL) | 133 | if(input != NULL) |
134 | rb->strlcpy(buffer, input, LUAL_BUFFERSIZE); | 134 | luaL_addstring(&b, input); |
135 | else | 135 | else |
136 | buffer[0] = '\0'; | 136 | buffer[0] = '\0'; |
137 | 137 | ||
138 | if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE)) | 138 | if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE)) |
139 | { | 139 | { |
140 | luaL_addsize(&b, strlen(buffer)); | 140 | luaL_addstring(&b, buffer); |
141 | luaL_pushresult(&b); | 141 | luaL_pushresult(&b); |
142 | } | 142 | } |
143 | else | 143 | else |
144 | lua_pushnil(L); | 144 | return 0; |
145 | 145 | ||
146 | return 1; | 146 | return 1; |
147 | } | 147 | } |
@@ -196,22 +196,32 @@ RB_WRAP(current_path) | |||
196 | return get_current_path(L, 1); | 196 | return get_current_path(L, 1); |
197 | } | 197 | } |
198 | 198 | ||
199 | static void fill_text_message(lua_State *L, struct text_message * message, | 199 | static const char ** get_table_items(lua_State *L, int pos, int *count) |
200 | int pos) | ||
201 | { | 200 | { |
202 | int i; | 201 | int i; |
203 | luaL_checktype(L, pos, LUA_TTABLE); | 202 | luaL_checktype(L, pos, LUA_TTABLE); |
204 | int n = luaL_getn(L, pos); | 203 | *count = lua_objlen(L, pos); |
204 | int n = *count; | ||
205 | 205 | ||
206 | const char **lines = (const char**) lua_newuserdata(L, n * sizeof(const char*)); | 206 | /* newuserdata will be pushed onto stack after args*/ |
207 | const char **items = (const char**) lua_newuserdata(L, n * sizeof(const char*)); | ||
207 | 208 | ||
208 | for(i=1; i<=n; i++) | 209 | for(i=1; i<= n; i++) |
209 | { | 210 | { |
210 | lua_rawgeti(L, pos, i); | 211 | lua_rawgeti(L, pos, i); /* Push item on the stack */ |
211 | lines[i-1] = luaL_checkstring(L, -1); | 212 | items[i-1] = lua_tostring(L, -1); |
212 | lua_pop(L, 1); | 213 | lua_pop(L, 1); /* Pop it */ |
213 | } | 214 | } |
214 | message->message_lines = lines; | 215 | |
216 | return items; | ||
217 | } | ||
218 | |||
219 | static inline void fill_text_message(lua_State *L, struct text_message * message, | ||
220 | int pos) | ||
221 | { | ||
222 | int n; | ||
223 | /* newuserdata will be pushed onto stack after args*/ | ||
224 | message->message_lines = get_table_items(L, pos, &n); | ||
215 | message->nb_lines = n; | 225 | message->nb_lines = n; |
216 | } | 226 | } |
217 | 227 | ||
@@ -238,24 +248,15 @@ RB_WRAP(do_menu) | |||
238 | struct menu_callback_with_desc menu_desc = {NULL, NULL, Icon_NOICON}; | 248 | struct menu_callback_with_desc menu_desc = {NULL, NULL, Icon_NOICON}; |
239 | struct menu_item_ex menu = {MT_RETURN_ID | MENU_HAS_DESC, {.strings = NULL}, | 249 | struct menu_item_ex menu = {MT_RETURN_ID | MENU_HAS_DESC, {.strings = NULL}, |
240 | {.callback_and_desc = &menu_desc}}; | 250 | {.callback_and_desc = &menu_desc}}; |
241 | int i, n, start_selected; | 251 | int n, start_selected; |
242 | const char **items, *title; | 252 | const char **items, *title; |
243 | 253 | ||
244 | title = luaL_checkstring(L, 1); | 254 | title = luaL_checkstring(L, 1); |
245 | luaL_checktype(L, 2, LUA_TTABLE); | ||
246 | start_selected = lua_tointeger(L, 3); | ||
247 | 255 | ||
248 | n = luaL_getn(L, 2); | 256 | start_selected = lua_tointeger(L, 3); |
249 | 257 | ||
250 | /* newuserdata will be pushed onto stack after args*/ | 258 | /* newuserdata will be pushed onto stack after args*/ |
251 | items = (const char**) lua_newuserdata(L, n * sizeof(const char*)); | 259 | items = get_table_items(L, 2, &n); |
252 | |||
253 | for(i=1; i<=n; i++) | ||
254 | { | ||
255 | lua_rawgeti(L, 2, i); /* Push item on the stack */ | ||
256 | items[i-1] = luaL_checkstring(L, -1); | ||
257 | lua_pop(L, 1); /* Pop it */ | ||
258 | } | ||
259 | 260 | ||
260 | menu.strings = items; | 261 | menu.strings = items; |
261 | menu.flags |= MENU_ITEM_COUNT(n); | 262 | menu.flags |= MENU_ITEM_COUNT(n); |