A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

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

+64 -1
+42
apps/plugins/lua/include_lua/files.lua
··· 1 + rb = rb or {} 2 + rb.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 34 + end 35 + 36 + rb.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 42 + end
+1 -1
apps/plugins/lua/lua.make
··· 17 17 18 18 LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua 19 19 LUA_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 21 print.lua timer.lua playlist.lua pcm.lua sound.lua \ 22 22 rbcompat.lua rbsettings.lua poly_points.lua printtable.lua) 23 23
+19
apps/plugins/lua/rocklib.c
··· 637 637 638 638 /* DEVICE STRING / FILENAME MANIPULATION */ 639 639 640 + #if 0 /*See files.lua */ 640 641 RB_WRAP(strip_extension) 641 642 { 642 643 const char* filename = luaL_checkstring(L, -1); ··· 672 673 673 674 return 1; 674 675 } 676 + #endif 675 677 676 678 RB_WRAP(utf8encode) 677 679 { ··· 697 699 return 1; 698 700 } 699 701 702 + /* ROCKBOX SETTINGS / INFO */ 700 703 static int mem_read_write(lua_State *L, uintptr_t address, size_t maxsize, bool isstr_p) 701 704 { 702 705 if(isstr_p) /*pointer to string (**char)*/ ··· 844 847 return mem_read_write(L, address, maxsize, isstr_p); 845 848 } 846 849 850 + RB_WRAP(settings_save) 851 + { 852 + rb->settings_save(); 853 + return 0; 854 + } 855 + 847 856 #if 0 848 857 RB_WRAP(read_mem) 849 858 { ··· 906 915 return -1; 907 916 } 908 917 918 + RB_WRAP(show_logo) 919 + { 920 + rb->show_logo(); 921 + return 0; 922 + } 923 + 909 924 #define RB_FUNC(func) {#func, rock_##func} 910 925 #define RB_ALIAS(name, func) {name, rock_##func} 911 926 static const luaL_Reg rocklib[] = ··· 967 982 #endif 968 983 969 984 /* DEVICE STRING / FILENAME MANIPULATION */ 985 + #if 0 /*See files.lua */ 970 986 RB_FUNC(strip_extension), 971 987 RB_FUNC(create_numbered_filename), 988 + #endif 972 989 RB_FUNC(utf8encode), 973 990 RB_FUNC(strncasecmp), 974 991 ··· 977 994 RB_FUNC(global_settings), 978 995 RB_FUNC(audio_next_track), 979 996 RB_FUNC(audio_current_track), 997 + RB_FUNC(settings_save), 980 998 981 999 /* SPEAKING */ 982 1000 {"talk_number", rock_talk}, ··· 985 1003 986 1004 /* MISC */ 987 1005 RB_FUNC(restart_lua), 1006 + RB_FUNC(show_logo), 988 1007 989 1008 {NULL, NULL} 990 1009 };
+2
apps/plugins/lua/rocklib_aux.pl
··· 109 109 '^plugin_get_current_filename$', 110 110 '^plugin_release_audio_buffer$', 111 111 '^reload_directory$', 112 + '^settings_save$', 112 113 '^set_current_file$', 113 114 '^set_dirfilter$', 115 + '^show_logo$', 114 116 '^sleep$', 115 117 '^system_memory_guard$', 116 118 '^system_sound_play$',