summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2019-09-06 19:24:26 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-09-07 03:10:59 +0200
commit267d04d2bd2a7681c8bbcfbb655612101440b765 (patch)
treea518b4c10244cc77a5eee636132031c5a542c00a /apps/plugins/lua/rocklib.c
parenta3cbd86a5193e5227344db360f45f114fda10aab (diff)
downloadrockbox-267d04d2bd2a7681c8bbcfbb655612101440b765.tar.gz
rockbox-267d04d2bd2a7681c8bbcfbb655612101440b765.zip
Lua add metadata and settings reading helper module
Adds example scripts for reading track metadata + dumping albumart and rockbox settings settings are now stored as a table of strings rather than a table of tables as it saves ~15 kb of ram without adding much complexity Change-Id: I611c312b2a60ab96e595e4710b17aedbd6c0689b
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 3c38440850..033975d7fe 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -640,8 +640,12 @@ RB_WRAP(strncasecmp)
640 return 1; 640 return 1;
641} 641}
642 642
643static int mem_read_write(lua_State *L, uintptr_t address, size_t maxsize) 643static int mem_read_write(lua_State *L, uintptr_t address, size_t maxsize, bool isstr_p)
644{ 644{
645 if(isstr_p) /*pointer to string (**char)*/
646 {
647 lua_settop(L, 2); /* no writes allowed */
648 }
645 intptr_t offset = (intptr_t) luaL_optnumber(L, 1, 0); 649 intptr_t offset = (intptr_t) luaL_optnumber(L, 1, 0);
646 size_t size = (size_t) luaL_optnumber(L, 2, maxsize); 650 size_t size = (size_t) luaL_optnumber(L, 2, maxsize);
647 size_t written; 651 size_t written;
@@ -716,6 +720,11 @@ static int mem_read_write(lua_State *L, uintptr_t address, size_t maxsize)
716 case LUA_TNIL: 720 case LUA_TNIL:
717 case LUA_TNONE: /* reader */ 721 case LUA_TNONE: /* reader */
718 { 722 {
723 if(isstr_p && mem)
724 {
725 lua_pushstring (L, *(char**) mem);
726 return 1;
727 }
719 luaL_Buffer b; 728 luaL_Buffer b;
720 luaL_buffinit(L, &b); 729 luaL_buffinit(L, &b);
721 while(size > 0) 730 while(size > 0)
@@ -746,32 +755,51 @@ RB_WRAP(global_status)
746{ 755{
747 const uintptr_t address = (uintptr_t) rb->global_status; 756 const uintptr_t address = (uintptr_t) rb->global_status;
748 const size_t maxsize = sizeof(struct system_status); 757 const size_t maxsize = sizeof(struct system_status);
749 return mem_read_write(L, address, maxsize); 758 /*const bool isstr_p = lua_toboolean(L, 4);*/
759 return mem_read_write(L, address, maxsize, false);
750} 760}
751 761
752RB_WRAP(global_settings) 762RB_WRAP(global_settings)
753{ 763{
754 const uintptr_t address = (uintptr_t) rb->global_settings; 764 const uintptr_t address = (uintptr_t) rb->global_settings;
755 const size_t maxsize = sizeof(struct user_settings); 765 const size_t maxsize = sizeof(struct user_settings);
756 return mem_read_write(L, address, maxsize); 766 /*const bool isstr_p = lua_toboolean(L, 4);*/
767 return mem_read_write(L, address, maxsize, false);
757} 768}
758 769
759RB_WRAP(audio_next_track) 770RB_WRAP(audio_next_track)
760{ 771{
761 lua_settop(L, 2); /* no writes allowed */ 772
762 const uintptr_t address = (uintptr_t) rb->audio_next_track(); 773 const uintptr_t address = (uintptr_t) rb->audio_next_track();
763 const size_t maxsize = sizeof(struct mp3entry); 774 const size_t maxsize = sizeof(struct mp3entry);
764 return mem_read_write(L, address, maxsize); 775 const bool isstr_p = lua_toboolean(L, 4);
776 lua_settop(L, 2); /* no writes allowed */
777 return mem_read_write(L, address, maxsize, isstr_p);
765} 778}
766 779
767RB_WRAP(audio_current_track) 780RB_WRAP(audio_current_track)
768{ 781{
769 lua_settop(L, 2); /* no writes allowed */ 782
770 const uintptr_t address = (uintptr_t) rb->audio_current_track(); 783 const uintptr_t address = (uintptr_t) rb->audio_current_track();
771 const size_t maxsize = sizeof(struct mp3entry); 784 const size_t maxsize = sizeof(struct mp3entry);
772 return mem_read_write(L, address, maxsize); 785 const bool isstr_p = lua_toboolean(L, 4);
786 lua_settop(L, 2); /* no writes allowed */
787 return mem_read_write(L, address, maxsize, isstr_p);
773} 788}
774 789
790#if 0
791RB_WRAP(read_mem)
792{
793 lua_settop(L, 2); /* no writes allowed */
794 const uintptr_t address = lua_tonumber(L, 1);
795 const size_t maxsize = luaL_optnumber(L, 2, strlen((char *)address));
796 luaL_argcheck(L, address > 0, 1, ERR_IDX_RANGE);
797 lua_pushnil(L);
798 lua_replace(L, -3);/* stk pos 1 is no longer offset it is starting address */
799 return mem_read_write(L, address, maxsize, false);
800}
801#endif
802
775RB_WRAP(restart_lua) 803RB_WRAP(restart_lua)
776{ 804{
777 /*close lua state, open a new lua state, load script @ filename */ 805 /*close lua state, open a new lua state, load script @ filename */