summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-10-23 00:11:34 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2018-10-24 06:05:53 +0200
commitdf4cb9bafc66c3d88945b70389e0cb87cbcecf15 (patch)
tree89a5798812480118f94b08299acd0f84f63951c1 /apps
parent948984309a3c1dd6b92f018926e9831083c803e3 (diff)
downloadrockbox-df4cb9bafc66c3d88945b70389e0cb87cbcecf15.tar.gz
rockbox-df4cb9bafc66c3d88945b70389e0cb87cbcecf15.zip
Lua fix strip_extension and create_numbered_filename
Both of these functions modified the string in the lua stack per lua manual: 'When a C function receives a string argument from Lua, there are only two rules that it must observe: Not to pop the string from the stack while accessing it and never to modify the string' strip_extension will still work with old parameters and is thus backwards compatible strip_extension("filename") create_numbered_filename has changed slightly and IS NOT backwards compatible create_numbered_filename(path, prefix, suffix, [number]) (number defaults to -1) Change-Id: I34cf7e2f6f691f33d5ac2b2e995855a171fb99b3
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/lua/rocklib.c36
-rwxr-xr-xapps/plugins/lua/rocklib_aux.pl2
2 files changed, 38 insertions, 0 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 82a03ab6b4..64394b8728 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -363,6 +363,39 @@ RB_WRAP(get_plugin_action)
363 return 1; 363 return 1;
364} 364}
365 365
366RB_WRAP(strip_extension)
367{
368 const char* filename = luaL_checkstring(L, -1);
369 const char* pos = rb->strrchr(filename, '.');
370 if(pos != NULL)
371 lua_pushlstring (L, filename, pos - filename);
372
373 return 1;
374}
375
376RB_WRAP(create_numbered_filename)
377{
378 luaL_Buffer b;
379 luaL_buffinit(L, &b);
380 char *buffer = luaL_prepbuffer(&b);
381 buffer[0] = '\0';
382
383 const char * path = luaL_checkstring(L, 1);
384 const char * prefix = luaL_checkstring(L, 2);
385 const char * suffix = luaL_checkstring(L, 3);
386 int numberlen = luaL_optint(L, 4, -1);
387
388 if(rb->create_numbered_filename(buffer, path, prefix, suffix, numberlen))
389 {
390 luaL_addstring(&b, buffer);
391 luaL_pushresult(&b);
392 }
393 else
394 return 0;
395
396 return 1;
397}
398
366#define RB_FUNC(func) {#func, rock_##func} 399#define RB_FUNC(func) {#func, rock_##func}
367static const luaL_Reg rocklib[] = 400static const luaL_Reg rocklib[] =
368{ 401{
@@ -410,6 +443,9 @@ static const luaL_Reg rocklib[] =
410 443
411 RB_FUNC(get_plugin_action), 444 RB_FUNC(get_plugin_action),
412 445
446 RB_FUNC(strip_extension),
447 RB_FUNC(create_numbered_filename),
448
413 {NULL, NULL} 449 {NULL, NULL}
414}; 450};
415#undef RB_FUNC 451#undef RB_FUNC
diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl
index f04457f189..085a191ee3 100755
--- a/apps/plugins/lua/rocklib_aux.pl
+++ b/apps/plugins/lua/rocklib_aux.pl
@@ -65,6 +65,8 @@ my @forbidden_functions = ('^open$',
65 '^fdprintf$', 65 '^fdprintf$',
66 '^read_line$', 66 '^read_line$',
67 '^[a-z]+dir$', 67 '^[a-z]+dir$',
68 '^strip_extension$',
69 '^create_numbered_filename$',
68 '^s?+rand$', 70 '^s?+rand$',
69 '^strl?+cpy$', 71 '^strl?+cpy$',
70 '^strl?+cat$', 72 '^strl?+cat$',