From c406f945924412f4c472413b578e396036e63626 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Fri, 27 Jan 2012 00:05:20 +0100 Subject: Lua: Add pluginlib_actions wrapper for lua scripts. Scripts can now make use of PLA_* actions to be more target independant. Change-Id: I1b9f69e07f41b2187ecc1bad25a2c20eaaef92b4 --- apps/plugins/lua/action_helper.pl | 6 ++++++ apps/plugins/lua/lua.make | 2 +- apps/plugins/lua/rocklib.c | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/plugins/lua/action_helper.pl b/apps/plugins/lua/action_helper.pl index eb66c2b01e..f225952bf9 100755 --- a/apps/plugins/lua/action_helper.pl +++ b/apps/plugins/lua/action_helper.pl @@ -28,6 +28,12 @@ while(my $line = ) $actions[$i] = sprintf("\t%s = %d,\n", $1, $i); $i++; } + elsif($line =~ /^\s*(PLA_[^\s]+)(\s*=.*)?,\s*$/) + { + # PLA_* begins at LAST_ACTION_PLACEHOLDER+1, thus i+1 + $actions[$i] = sprintf("\t%s = %d,\n", $1, $i+1); + $i++; + } elsif($line =~ /^\s*(CONTEXT_[^\s]+)(\s*=.*)?,\s*$/) { $contexts[$j] = sprintf("\t%s = %d,\n", $1, $j); diff --git a/apps/plugins/lua/lua.make b/apps/plugins/lua/lua.make index f4dd7710c9..9e2db62e39 100644 --- a/apps/plugins/lua/lua.make +++ b/apps/plugins/lua/lua.make @@ -33,7 +33,7 @@ endif $(LUA_BUILDDIR)/lua.rock: $(LUA_OBJ) $(LUA_BUILDDIR)/actions.lua $(LUA_BUILDDIR)/buttons.lua $(LUA_BUILDDIR)/rocklib_aux.o $(LUA_BUILDDIR)/actions.lua: $(LUA_OBJ) $(LUA_SRCDIR)/action_helper.pl - $(call PRINTS,GEN $(@F))$(CC) $(PLUGINFLAGS) $(INCLUDES) -E $(APPSDIR)/action.h | $(LUA_SRCDIR)/action_helper.pl > $(LUA_BUILDDIR)/actions.lua + $(call PRINTS,GEN $(@F))$(CC) $(PLUGINFLAGS) $(INCLUDES) -E $(APPSDIR)/plugins/lib/pluginlib_actions.h | $(LUA_SRCDIR)/action_helper.pl > $(LUA_BUILDDIR)/actions.lua $(LUA_BUILDDIR)/buttons.lua: $(LUA_OBJ) $(LUA_SRCDIR)/button_helper.pl $(SILENT)$(CC) $(INCLUDES) -dM -E -include button-target.h - < /dev/null | $(LUA_SRCDIR)/button_helper.pl | $(HOSTCC) -fno-builtin $(INCLUDES) -x c -o $(LUA_BUILDDIR)/button_helper - diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 8e1ab19941..809b269b47 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -28,6 +28,7 @@ #include "lauxlib.h" #include "rocklib.h" #include "lib/helper.h" +#include "lib/pluginlib_actions.h" /* * http://www.lua.org/manual/5.1/manual.html#lua_CFunction @@ -613,6 +614,24 @@ RB_WRAP(backlight_brightness_set) SIMPLE_VOID_WRAPPER(backlight_brightness_use_setting); #endif +RB_WRAP(get_plugin_action) +{ + static const struct button_mapping *m1[] = { pla_main_ctx }; + int timeout = luaL_checkint(L, 1); + int btn; +#ifdef HAVE_REMOTE_LCD + static const struct button_mapping *m2[] = { pla_main_ctx, pla_remote_ctx }; + bool with_remote = luaL_optint(L, 2, 0); + if (with_remote) + btn = pluginlib_getaction(timeout, m2, 2); + else +#endif + btn = pluginlib_getaction(timeout, m1, 1); + + lua_pushinteger(L, btn); + return 1; +} + #define R(NAME) {#NAME, rock_##NAME} static const luaL_Reg rocklib[] = { @@ -670,6 +689,7 @@ static const luaL_Reg rocklib[] = R(backlight_brightness_set), R(backlight_brightness_use_setting), #endif + R(get_plugin_action), {"new_image", rli_new}, -- cgit v1.2.3