summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2019-09-27 20:08:58 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-09-28 03:15:15 +0200
commit01cccaf2d27dcd92a7a6d4b7f5658e780a6da68c (patch)
tree85e766c94edfb2a055a78c7a2d6750a0d1b46be1 /apps/plugins
parent4fb783582fa6d961160fea940ad417d099ec0732 (diff)
downloadrockbox-01cccaf2d27dcd92a7a6d4b7f5658e780a6da68c.tar.gz
rockbox-01cccaf2d27dcd92a7a6d4b7f5658e780a6da68c.zip
lua move strip_extension and create_numbered_filename out of main binary
rb.strip_extension and rb.create_numbered_filename have been moved to include_lua/files.lua to use simply add require('files') to your script Change-Id: I95af7b312c8614cb10da4b71b22714b3e282e08a
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/lua/include_lua/files.lua42
-rw-r--r--apps/plugins/lua/lua.make2
-rw-r--r--apps/plugins/lua/rocklib.c19
-rwxr-xr-xapps/plugins/lua/rocklib_aux.pl2
4 files changed, 64 insertions, 1 deletions
diff --git a/apps/plugins/lua/include_lua/files.lua b/apps/plugins/lua/include_lua/files.lua
new file mode 100644
index 0000000000..ccb36c5157
--- /dev/null
+++ b/apps/plugins/lua/include_lua/files.lua
@@ -0,0 +1,42 @@
1rb = rb or {}
2rb.create_numbered_filename = function (sPath, sPrefix, sSuffix, iNumLen, iNum)
3 iNum = iNum or -1
4 local dir_iter, dir_data = luadir.dir(sPath)
5 local status = true
6 local name, isdir, num
7 local name_pat = sPrefix .. '(%d+)' .. sSuffix
8 local file_pat
9 local max_num = iNum < 0 and -1 or iNum -- Number specified
10
11 if max_num < 0 then
12 max_num = 0 -- automatic numbering
13 repeat
14 status, name, isdir = pcall(dir_iter, dir_data)
15 if status then
16 if name and not isdir then
17 num = string.match(name, name_pat)
18 if (not iNumLen) and num then -- try to match existing zero padding
19 local s, e = string.find(num, "^0+")
20 if s and e then iNumLen = (e - s) end
21 end
22 num = tonumber(num)
23 if num and (num > max_num) then
24 max_num = num
25 end
26 end
27 end
28 until not status
29 end
30 max_num = max_num + 1
31 iNumLen = iNumLen or 0
32 file_pat = "%s/%s%0" .. iNumLen .. "d%s"
33 return string.format(file_pat, sPath, sPrefix, max_num, sSuffix), max_num
34end
35
36rb.strip_extension = function (sFileName)
37 sFileName = sFileName or ""
38 local ext = rb.strrchr(sFileName, string.byte("."));
39 local len = string.len(ext or "")
40 if len > 0 then sFileName = string.sub(sFileName, 1, -(len + 1)) end
41 return sFileName
42end
diff --git a/apps/plugins/lua/lua.make b/apps/plugins/lua/lua.make
index 5e46692f3f..ebdef1e24e 100644
--- a/apps/plugins/lua/lua.make
+++ b/apps/plugins/lua/lua.make
@@ -17,7 +17,7 @@ OTHER_SRC += $(LUA_SRC)
17 17
18LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua 18LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua
19LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua draw_floodfill.lua draw_poly.lua \ 19LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua draw_floodfill.lua draw_poly.lua \
20 draw_num.lua draw_text.lua image.lua image_save.lua lcd.lua math_ex.lua \ 20 draw_num.lua draw_text.lua files.lua image.lua image_save.lua lcd.lua math_ex.lua \
21 print.lua timer.lua playlist.lua pcm.lua sound.lua \ 21 print.lua timer.lua playlist.lua pcm.lua sound.lua \
22 rbcompat.lua rbsettings.lua poly_points.lua printtable.lua) 22 rbcompat.lua rbsettings.lua poly_points.lua printtable.lua)
23 23
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index e617f3e4bf..6b24984130 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -637,6 +637,7 @@ RB_WRAP(buttonlight_brightness_set)
637 637
638/* DEVICE STRING / FILENAME MANIPULATION */ 638/* DEVICE STRING / FILENAME MANIPULATION */
639 639
640#if 0 /*See files.lua */
640RB_WRAP(strip_extension) 641RB_WRAP(strip_extension)
641{ 642{
642 const char* filename = luaL_checkstring(L, -1); 643 const char* filename = luaL_checkstring(L, -1);
@@ -672,6 +673,7 @@ RB_WRAP(create_numbered_filename)
672 673
673 return 1; 674 return 1;
674} 675}
676#endif
675 677
676RB_WRAP(utf8encode) 678RB_WRAP(utf8encode)
677{ 679{
@@ -697,6 +699,7 @@ RB_WRAP(strncasecmp)
697 return 1; 699 return 1;
698} 700}
699 701
702 /* ROCKBOX SETTINGS / INFO */
700static int mem_read_write(lua_State *L, uintptr_t address, size_t maxsize, bool isstr_p) 703static int mem_read_write(lua_State *L, uintptr_t address, size_t maxsize, bool isstr_p)
701{ 704{
702 if(isstr_p) /*pointer to string (**char)*/ 705 if(isstr_p) /*pointer to string (**char)*/
@@ -844,6 +847,12 @@ RB_WRAP(audio_current_track)
844 return mem_read_write(L, address, maxsize, isstr_p); 847 return mem_read_write(L, address, maxsize, isstr_p);
845} 848}
846 849
850RB_WRAP(settings_save)
851{
852 rb->settings_save();
853 return 0;
854}
855
847#if 0 856#if 0
848RB_WRAP(read_mem) 857RB_WRAP(read_mem)
849{ 858{
@@ -906,6 +915,12 @@ RB_WRAP(restart_lua)
906 return -1; 915 return -1;
907} 916}
908 917
918RB_WRAP(show_logo)
919{
920 rb->show_logo();
921 return 0;
922}
923
909#define RB_FUNC(func) {#func, rock_##func} 924#define RB_FUNC(func) {#func, rock_##func}
910#define RB_ALIAS(name, func) {name, rock_##func} 925#define RB_ALIAS(name, func) {name, rock_##func}
911static const luaL_Reg rocklib[] = 926static const luaL_Reg rocklib[] =
@@ -967,8 +982,10 @@ static const luaL_Reg rocklib[] =
967#endif 982#endif
968 983
969 /* DEVICE STRING / FILENAME MANIPULATION */ 984 /* DEVICE STRING / FILENAME MANIPULATION */
985#if 0 /*See files.lua */
970 RB_FUNC(strip_extension), 986 RB_FUNC(strip_extension),
971 RB_FUNC(create_numbered_filename), 987 RB_FUNC(create_numbered_filename),
988#endif
972 RB_FUNC(utf8encode), 989 RB_FUNC(utf8encode),
973 RB_FUNC(strncasecmp), 990 RB_FUNC(strncasecmp),
974 991
@@ -977,6 +994,7 @@ static const luaL_Reg rocklib[] =
977 RB_FUNC(global_settings), 994 RB_FUNC(global_settings),
978 RB_FUNC(audio_next_track), 995 RB_FUNC(audio_next_track),
979 RB_FUNC(audio_current_track), 996 RB_FUNC(audio_current_track),
997 RB_FUNC(settings_save),
980 998
981 /* SPEAKING */ 999 /* SPEAKING */
982 {"talk_number", rock_talk}, 1000 {"talk_number", rock_talk},
@@ -985,6 +1003,7 @@ static const luaL_Reg rocklib[] =
985 1003
986 /* MISC */ 1004 /* MISC */
987 RB_FUNC(restart_lua), 1005 RB_FUNC(restart_lua),
1006 RB_FUNC(show_logo),
988 1007
989 {NULL, NULL} 1008 {NULL, NULL}
990}; 1009};
diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl
index 8454da2369..f53fc7bd61 100755
--- a/apps/plugins/lua/rocklib_aux.pl
+++ b/apps/plugins/lua/rocklib_aux.pl
@@ -109,8 +109,10 @@ my @forbidden_functions = ('^atoi$',
109 '^plugin_get_current_filename$', 109 '^plugin_get_current_filename$',
110 '^plugin_release_audio_buffer$', 110 '^plugin_release_audio_buffer$',
111 '^reload_directory$', 111 '^reload_directory$',
112 '^settings_save$',
112 '^set_current_file$', 113 '^set_current_file$',
113 '^set_dirfilter$', 114 '^set_dirfilter$',
115 '^show_logo$',
114 '^sleep$', 116 '^sleep$',
115 '^system_memory_guard$', 117 '^system_memory_guard$',
116 '^system_sound_play$', 118 '^system_sound_play$',