Lua: Add pluginlib_actions wrapper for lua scripts.

Scripts can now make use of PLA_* actions to be more target independant.

Change-Id: I1b9f69e07f41b2187ecc1bad25a2c20eaaef92b4
This commit is contained in:
Thomas Martitz 2012-01-27 00:05:20 +01:00
parent 6eeca7096d
commit c406f94592
3 changed files with 27 additions and 1 deletions

View file

@ -28,6 +28,12 @@ while(my $line = <STDIN>)
$actions[$i] = sprintf("\t%s = %d,\n", $1, $i); $actions[$i] = sprintf("\t%s = %d,\n", $1, $i);
$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*$/) elsif($line =~ /^\s*(CONTEXT_[^\s]+)(\s*=.*)?,\s*$/)
{ {
$contexts[$j] = sprintf("\t%s = %d,\n", $1, $j); $contexts[$j] = sprintf("\t%s = %d,\n", $1, $j);

View file

@ -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)/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 $(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 $(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 - $(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 -

View file

@ -28,6 +28,7 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "rocklib.h" #include "rocklib.h"
#include "lib/helper.h" #include "lib/helper.h"
#include "lib/pluginlib_actions.h"
/* /*
* http://www.lua.org/manual/5.1/manual.html#lua_CFunction * 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); SIMPLE_VOID_WRAPPER(backlight_brightness_use_setting);
#endif #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} #define R(NAME) {#NAME, rock_##NAME}
static const luaL_Reg rocklib[] = static const luaL_Reg rocklib[] =
{ {
@ -670,6 +689,7 @@ static const luaL_Reg rocklib[] =
R(backlight_brightness_set), R(backlight_brightness_set),
R(backlight_brightness_use_setting), R(backlight_brightness_use_setting),
#endif #endif
R(get_plugin_action),
{"new_image", rli_new}, {"new_image", rli_new},