Message ID | 20171013073945.30454-1-christian.storm@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | Lua: make handler mask enum available to Lua | expand |
On 13/10/2017 09:39, Christian Storm wrote: > Commit ff12cd6 "handlers: associate each handler with a mask" > introduced handler masks to designate handlers to particular > types. Make this enum available for Lua handler registration. > > Per default, a Lua handler will be registered as ANY_HANDLER. > The optional 3rd argument to l_register_handler() allows to > specify otherwise. > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > corelib/lua_interface.c | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c > index df9efaa..e66f9c8 100644 > --- a/corelib/lua_interface.c > +++ b/corelib/lua_interface.c > @@ -400,6 +400,19 @@ static int luaopen_swupdate(lua_State *L) { > lua_push_enum(L, "SUBPROCESS", SUBPROCESS); > lua_settable(L, -3); > > +#ifdef CONFIG_HANDLER_IN_LUA > + /* export the handler mask enum */ > + lua_pushstring(L, "HANDLER_MASK"); > + lua_newtable (L); > + lua_push_enum(L, "IMAGE_HANDLER", IMAGE_HANDLER); > + lua_push_enum(L, "FILE_HANDLER", FILE_HANDLER); > + lua_push_enum(L, "SCRIPT_HANDLER", SCRIPT_HANDLER); > + lua_push_enum(L, "BOOTLOADER_HANDLER", BOOTLOADER_HANDLER); > + lua_push_enum(L, "PARTITION_HANDLER", PARTITION_HANDLER); > + lua_push_enum(L, "ANY_HANDLER", ANY_HANDLER); > + lua_settable(L, -3); > +#endif > + > return 1; > } > > @@ -483,13 +496,19 @@ static int l_register_handler( lua_State *L ) { > lua_pop(L, 2); > return 0; > } else { > + unsigned int mask = ANY_HANDLER; > + if (lua_isnumber(L, 3)) { > + mask = luaL_checknumber(L, 3); > + lua_pop(L, 1); > + } > const char *handler_desc = luaL_checkstring(L, 1); > /* store the callback function in registry */ > *l_func_ref = luaL_ref (L, LUA_REGISTRYINDEX); > /* cleanup stack */ > lua_pop (L, 1); > + > register_handler(handler_desc, l_handler_wrapper, > - ANY_HANDLER, l_func_ref); > + mask, l_func_ref); > return 0; > } > } > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
On 13/10/2017 09:39, Christian Storm wrote: > Commit ff12cd6 "handlers: associate each handler with a mask" > introduced handler masks to designate handlers to particular > types. Make this enum available for Lua handler registration. > > Per default, a Lua handler will be registered as ANY_HANDLER. > The optional 3rd argument to l_register_handler() allows to > specify otherwise. > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > corelib/lua_interface.c | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c > index df9efaa..e66f9c8 100644 > --- a/corelib/lua_interface.c > +++ b/corelib/lua_interface.c > @@ -400,6 +400,19 @@ static int luaopen_swupdate(lua_State *L) { > lua_push_enum(L, "SUBPROCESS", SUBPROCESS); > lua_settable(L, -3); > > +#ifdef CONFIG_HANDLER_IN_LUA > + /* export the handler mask enum */ > + lua_pushstring(L, "HANDLER_MASK"); > + lua_newtable (L); > + lua_push_enum(L, "IMAGE_HANDLER", IMAGE_HANDLER); > + lua_push_enum(L, "FILE_HANDLER", FILE_HANDLER); > + lua_push_enum(L, "SCRIPT_HANDLER", SCRIPT_HANDLER); > + lua_push_enum(L, "BOOTLOADER_HANDLER", BOOTLOADER_HANDLER); > + lua_push_enum(L, "PARTITION_HANDLER", PARTITION_HANDLER); > + lua_push_enum(L, "ANY_HANDLER", ANY_HANDLER); > + lua_settable(L, -3); > +#endif > + > return 1; > } > > @@ -483,13 +496,19 @@ static int l_register_handler( lua_State *L ) { > lua_pop(L, 2); > return 0; > } else { > + unsigned int mask = ANY_HANDLER; > + if (lua_isnumber(L, 3)) { > + mask = luaL_checknumber(L, 3); > + lua_pop(L, 1); > + } > const char *handler_desc = luaL_checkstring(L, 1); > /* store the callback function in registry */ > *l_func_ref = luaL_ref (L, LUA_REGISTRYINDEX); > /* cleanup stack */ > lua_pop (L, 1); > + > register_handler(handler_desc, l_handler_wrapper, > - ANY_HANDLER, l_func_ref); > + mask, l_func_ref); > return 0; > } > } > Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index df9efaa..e66f9c8 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -400,6 +400,19 @@ static int luaopen_swupdate(lua_State *L) { lua_push_enum(L, "SUBPROCESS", SUBPROCESS); lua_settable(L, -3); +#ifdef CONFIG_HANDLER_IN_LUA + /* export the handler mask enum */ + lua_pushstring(L, "HANDLER_MASK"); + lua_newtable (L); + lua_push_enum(L, "IMAGE_HANDLER", IMAGE_HANDLER); + lua_push_enum(L, "FILE_HANDLER", FILE_HANDLER); + lua_push_enum(L, "SCRIPT_HANDLER", SCRIPT_HANDLER); + lua_push_enum(L, "BOOTLOADER_HANDLER", BOOTLOADER_HANDLER); + lua_push_enum(L, "PARTITION_HANDLER", PARTITION_HANDLER); + lua_push_enum(L, "ANY_HANDLER", ANY_HANDLER); + lua_settable(L, -3); +#endif + return 1; } @@ -483,13 +496,19 @@ static int l_register_handler( lua_State *L ) { lua_pop(L, 2); return 0; } else { + unsigned int mask = ANY_HANDLER; + if (lua_isnumber(L, 3)) { + mask = luaL_checknumber(L, 3); + lua_pop(L, 1); + } const char *handler_desc = luaL_checkstring(L, 1); /* store the callback function in registry */ *l_func_ref = luaL_ref (L, LUA_REGISTRYINDEX); /* cleanup stack */ lua_pop (L, 1); + register_handler(handler_desc, l_handler_wrapper, - ANY_HANDLER, l_func_ref); + mask, l_func_ref); return 0; } }
Commit ff12cd6 "handlers: associate each handler with a mask" introduced handler masks to designate handlers to particular types. Make this enum available for Lua handler registration. Per default, a Lua handler will be registered as ANY_HANDLER. The optional 3rd argument to l_register_handler() allows to specify otherwise. Signed-off-by: Christian Storm <christian.storm@siemens.com> --- corelib/lua_interface.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)