diff options
| author | William Wilgus <me.theuser@yahoo.com> | 2018-10-23 00:11:34 -0400 |
|---|---|---|
| committer | William Wilgus <me.theuser@yahoo.com> | 2018-10-24 06:05:53 +0200 |
| commit | df4cb9bafc66c3d88945b70389e0cb87cbcecf15 (patch) | |
| tree | 89a5798812480118f94b08299acd0f84f63951c1 /apps/plugins/lua | |
| parent | 948984309a3c1dd6b92f018926e9831083c803e3 (diff) | |
| download | rockbox-df4cb9bafc66c3d88945b70389e0cb87cbcecf15.zip rockbox-df4cb9bafc66c3d88945b70389e0cb87cbcecf15.tar.gz rockbox-df4cb9bafc66c3d88945b70389e0cb87cbcecf15.tar.bz2 rockbox-df4cb9bafc66c3d88945b70389e0cb87cbcecf15.tar.xz | |
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/plugins/lua')
| -rw-r--r-- | apps/plugins/lua/rocklib.c | 36 | ||||
| -rwxr-xr-x | apps/plugins/lua/rocklib_aux.pl | 2 |
2 files changed, 38 insertions, 0 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 82a03ab..64394b8 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -363,6 +363,39 @@ RB_WRAP(get_plugin_action) return 1; } +RB_WRAP(strip_extension) +{ + const char* filename = luaL_checkstring(L, -1); + const char* pos = rb->strrchr(filename, '.'); + if(pos != NULL) + lua_pushlstring (L, filename, pos - filename); + + return 1; +} + +RB_WRAP(create_numbered_filename) +{ + luaL_Buffer b; + luaL_buffinit(L, &b); + char *buffer = luaL_prepbuffer(&b); + buffer[0] = '\0'; + + const char * path = luaL_checkstring(L, 1); + const char * prefix = luaL_checkstring(L, 2); + const char * suffix = luaL_checkstring(L, 3); + int numberlen = luaL_optint(L, 4, -1); + + if(rb->create_numbered_filename(buffer, path, prefix, suffix, numberlen)) + { + luaL_addstring(&b, buffer); + luaL_pushresult(&b); + } + else + return 0; + + return 1; +} + #define RB_FUNC(func) {#func, rock_##func} static const luaL_Reg rocklib[] = { @@ -410,6 +443,9 @@ static const luaL_Reg rocklib[] = RB_FUNC(get_plugin_action), + RB_FUNC(strip_extension), + RB_FUNC(create_numbered_filename), + {NULL, NULL} }; #undef RB_FUNC diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl index f04457f..085a191 100755 --- a/apps/plugins/lua/rocklib_aux.pl +++ b/apps/plugins/lua/rocklib_aux.pl @@ -65,6 +65,8 @@ my @forbidden_functions = ('^open$', '^fdprintf$', '^read_line$', '^[a-z]+dir$', + '^strip_extension$', + '^create_numbered_filename$', '^s?+rand$', '^strl?+cpy$', '^strl?+cat$', |