@@ -1098,7 +1098,19 @@ static int l_handler_wrapper(struct img_type *img, void *data,
lua_rawgeti(gL, LUA_REGISTRYINDEX, l_func_ref );
image2table(gL, img);
- if (LUA_OK != (res = lua_pcall(gL, 1, 1, 0))) {
+ switch (scriptfn) {
+ case PREINSTALL:
+ lua_pushstring(gL, "preinst");
+ break;
+ case POSTINSTALL:
+ lua_pushstring(gL, "postinst");
+ break;
+ default:
+ lua_pushnil(gL);
+ break;
+ }
+
+ if (LUA_OK != (res = lua_pcall(gL, 2, 1, 0))) {
ERROR("Error %d while executing the Lua callback: %s",
res, lua_tostring(gL, -1));
return -1;
@@ -293,7 +293,7 @@ In analogy to C handlers, the prototype for a Lua handler is
::
- function lua_handler(image)
+ function lua_handler(image, scriptfn)
...
end
@@ -306,6 +306,10 @@ underscores for the Lua domain to make them idiomatic, e.g.,
``installed-directly`` becomes ``installed_directly`` in the
Lua domain.
+For a script handler, ``scriptfn`` is either ``"preinst"`` or
+``"postinst"``. For other handlers it is ``nil``, and does not need
+to be declared as a parameter.
+
To register a Lua handler, the ``swupdate`` module provides the
``swupdate.register_handler()`` method that takes the handler's
name, the Lua handler function to be registered under that name,
Currently only the image parameter is passed to handlers written in Lua. Add the scriptfn parameter, so that it is possible to write useful script handlers. This converts the enumerated value to a string value of either "preinst" or "postinst", for consistency with the way package- provided scripts are called. Signed-off-by: Ben Hutchings <ben.hutchings_ext@softathome.com> --- corelib/lua_interface.c | 14 +++++++++++++- doc/source/handlers.rst | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-)