summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c36
1 files changed, 36 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