diff mbox series

[2/7] Lua: Publicize getversion()

Message ID 20220602091147.53323-2-christian.storm@siemens.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series [1/7] channel_curl: Map response code for file:// protocol | expand

Commit Message

Storm, Christian June 2, 2022, 9:11 a.m. UTC
Commit 0f38ff1 introduced swupdate.getversion() to
Lua handlers. Make it public so that Lua suricatta
modules can make use of it as well.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 corelib/lua_interface.c | 4 ++--
 include/lua_util.h      | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

Comments

Stefano Babic June 10, 2022, 9:30 a.m. UTC | #1
On 02.06.22 11:11, Christian Storm wrote:
> Commit 0f38ff1 introduced swupdate.getversion() to
> Lua handlers. Make it public so that Lua suricatta
> modules can make use of it as well.
> 
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
>   corelib/lua_interface.c | 4 ++--
>   include/lua_util.h      | 2 ++
>   2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
> index dd1be9e..b1ad514 100644
> --- a/corelib/lua_interface.c
> +++ b/corelib/lua_interface.c
> @@ -952,7 +952,7 @@ static void lua_push_enum(lua_State *L, const char *name, int value)
>   	lua_settable(L, -3);
>   }
>   
> -static int l_getversion(lua_State *L)
> +int lua_get_swupdate_version(lua_State *L)
>   {
>   	unsigned int version = 0, patchlevel = 0;
>   	/* Deliberately ignore sublevel and extraversion. */
> @@ -1002,7 +1002,7 @@ static const luaL_Reg l_swupdate[] = {
>           { "mount", l_mount },
>           { "umount", l_umount },
>           { "getroot", l_getroot },
> -        { "getversion", l_getversion },
> +        { "getversion", lua_get_swupdate_version },
>           { "progress", l_notify_progress },
>           { NULL, NULL }
>   };
> diff --git a/include/lua_util.h b/include/lua_util.h
> index 81da802..13cffc0 100644
> --- a/include/lua_util.h
> +++ b/include/lua_util.h
> @@ -34,6 +34,8 @@ int lua_notify_info(lua_State *L);
>   int lua_notify_warn(lua_State *L);
>   int lua_notify_debug(lua_State *L);
>   
> +int lua_get_swupdate_version(lua_State *L);
> +
>   #define lua_parser_exit(L) lua_close((lua_State *)L)
>   
>   #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501

Acked-by: Stefano Babic <sbabic@denx.de>

I have noted that the binding to Lua and which functions are exported is 
not documented at all. I have mayself to check inside the code to 
discover if a function is exported or not.

We should also improve doc/source/binding.rst, and introduce a 
description for all exported function, probably starting from the new ones.

Best regards,
Stefano
Storm, Christian June 10, 2022, 3:03 p.m. UTC | #2
Hi Stefano,

> On 02.06.22 11:11, Christian Storm wrote:
> > Commit 0f38ff1 introduced swupdate.getversion() to
> > Lua handlers. Make it public so that Lua suricatta
> > modules can make use of it as well.
> > 
> > Signed-off-by: Christian Storm <christian.storm@siemens.com>
> > ---
> >   corelib/lua_interface.c | 4 ++--
> >   include/lua_util.h      | 2 ++
> >   2 files changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
> > index dd1be9e..b1ad514 100644
> > --- a/corelib/lua_interface.c
> > +++ b/corelib/lua_interface.c
> > @@ -952,7 +952,7 @@ static void lua_push_enum(lua_State *L, const char *name, int value)
> >   	lua_settable(L, -3);
> >   }
> > -static int l_getversion(lua_State *L)
> > +int lua_get_swupdate_version(lua_State *L)
> >   {
> >   	unsigned int version = 0, patchlevel = 0;
> >   	/* Deliberately ignore sublevel and extraversion. */
> > @@ -1002,7 +1002,7 @@ static const luaL_Reg l_swupdate[] = {
> >           { "mount", l_mount },
> >           { "umount", l_umount },
> >           { "getroot", l_getroot },
> > -        { "getversion", l_getversion },
> > +        { "getversion", lua_get_swupdate_version },
> >           { "progress", l_notify_progress },
> >           { NULL, NULL }
> >   };
> > diff --git a/include/lua_util.h b/include/lua_util.h
> > index 81da802..13cffc0 100644
> > --- a/include/lua_util.h
> > +++ b/include/lua_util.h
> > @@ -34,6 +34,8 @@ int lua_notify_info(lua_State *L);
> >   int lua_notify_warn(lua_State *L);
> >   int lua_notify_debug(lua_State *L);
> > +int lua_get_swupdate_version(lua_State *L);
> > +
> >   #define lua_parser_exit(L) lua_close((lua_State *)L)
> >   #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501
> 
> Acked-by: Stefano Babic <sbabic@denx.de>
> 
> I have noted that the binding to Lua and which functions are exported is not
> documented at all. I have mayself to check inside the code to discover if a
> function is exported or not.
> 
> We should also improve doc/source/binding.rst, and introduce a description for
> all exported function, probably starting from the new ones.

Me too ;)

This is what "[PATCH 5/7] suricatta/lua: Add Lua interface specification"
is for with respect to suricatta Lua modules:
"An interface specification that details what functionality is
 available to suricatta Lua modules via SWUpdate's exported
 suricatta Lua module.

 It serves as reference, for mocking purposes, and type
 checking thanks to the EmmyLua annotations."

These two new "public" functions are documented there as they're
available to suricatta Lua modules.


With respect to Lua handlers, I did the same at [1]. Maybe it's about
time to update that and move it from there to the SWUpdate main repo?
I could prepare a patch...


What's missing then is an interface specification for the Lua IPC module
(bindings/lua_swupdate.c). I could as well prepare a patch for this...



I think suchlike interface specification/documentation in terms of code is
superior to burying it in doc/source/binding.rst as e.g. a Lua language
server such as [2] can pick it up and offer you linting, type checking,
documentation as well as code completion.... no need to read documentation ;)

What do you think?


Kind regards,
   Christian

[1] https://gitlab.com/cip-project/cip-sw-updates/swupdate-handler-roundrobin/-/blob/master/swupdate.lua
[2] https://github.com/sumneko/lua-language-server
Stefano Babic June 16, 2022, 6:42 a.m. UTC | #3
H Christian,

On 10.06.22 17:03, Christian Storm wrote:
> Hi Stefano,
> 
>> On 02.06.22 11:11, Christian Storm wrote:
>>> Commit 0f38ff1 introduced swupdate.getversion() to
>>> Lua handlers. Make it public so that Lua suricatta
>>> modules can make use of it as well.
>>>
>>> Signed-off-by: Christian Storm <christian.storm@siemens.com>
>>> ---
>>>    corelib/lua_interface.c | 4 ++--
>>>    include/lua_util.h      | 2 ++
>>>    2 files changed, 4 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
>>> index dd1be9e..b1ad514 100644
>>> --- a/corelib/lua_interface.c
>>> +++ b/corelib/lua_interface.c
>>> @@ -952,7 +952,7 @@ static void lua_push_enum(lua_State *L, const char *name, int value)
>>>    	lua_settable(L, -3);
>>>    }
>>> -static int l_getversion(lua_State *L)
>>> +int lua_get_swupdate_version(lua_State *L)
>>>    {
>>>    	unsigned int version = 0, patchlevel = 0;
>>>    	/* Deliberately ignore sublevel and extraversion. */
>>> @@ -1002,7 +1002,7 @@ static const luaL_Reg l_swupdate[] = {
>>>            { "mount", l_mount },
>>>            { "umount", l_umount },
>>>            { "getroot", l_getroot },
>>> -        { "getversion", l_getversion },
>>> +        { "getversion", lua_get_swupdate_version },
>>>            { "progress", l_notify_progress },
>>>            { NULL, NULL }
>>>    };
>>> diff --git a/include/lua_util.h b/include/lua_util.h
>>> index 81da802..13cffc0 100644
>>> --- a/include/lua_util.h
>>> +++ b/include/lua_util.h
>>> @@ -34,6 +34,8 @@ int lua_notify_info(lua_State *L);
>>>    int lua_notify_warn(lua_State *L);
>>>    int lua_notify_debug(lua_State *L);
>>> +int lua_get_swupdate_version(lua_State *L);
>>> +
>>>    #define lua_parser_exit(L) lua_close((lua_State *)L)
>>>    #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501
>>
>> Acked-by: Stefano Babic <sbabic@denx.de>
>>
>> I have noted that the binding to Lua and which functions are exported is not
>> documented at all. I have mayself to check inside the code to discover if a
>> function is exported or not.
>>
>> We should also improve doc/source/binding.rst, and introduce a description for
>> all exported function, probably starting from the new ones.
> 
> Me too ;)
> 
> This is what "[PATCH 5/7] suricatta/lua: Add Lua interface specification"
> is for with respect to suricatta Lua modules:
> "An interface specification that details what functionality is
>   available to suricatta Lua modules via SWUpdate's exported
>   suricatta Lua module.
> 
>   It serves as reference, for mocking purposes, and type
>   checking thanks to the EmmyLua annotations."
> 
> These two new "public" functions are documented there as they're
> available to suricatta Lua modules.
> 
> 
> With respect to Lua handlers, I did the same at [1]. Maybe it's about
> time to update that and move it from there to the SWUpdate main repo?

This would be nice.

> I could prepare a patch...

Thanks for it.

> 
> 
> What's missing then is an interface specification for the Lua IPC module
> (bindings/lua_swupdate.c). I could as well prepare a patch for this...
> 

aGAIN, THANKS.

> 
> 
> I think suchlike interface specification/documentation in terms of code is
> superior to burying it in doc/source/binding.rst as e.g. a Lua language
> server such as [2] can pick it up and offer you linting, type checking,
> documentation as well as code completion.... no need to read documentation ;)
> 
> What do you think?

But then we need at least a reference in the documentation to point to 
the right file. A newbie will just read the documentation (I hope !), 
and he cannot know that the interface is described somewhere else.

Best regards,
Stefano

> 
> 
> Kind regards,
>     Christian
> 
> [1] https://gitlab.com/cip-project/cip-sw-updates/swupdate-handler-roundrobin/-/blob/master/swupdate.lua
> [2] https://github.com/sumneko/lua-language-server
>
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index dd1be9e..b1ad514 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -952,7 +952,7 @@  static void lua_push_enum(lua_State *L, const char *name, int value)
 	lua_settable(L, -3);
 }
 
-static int l_getversion(lua_State *L)
+int lua_get_swupdate_version(lua_State *L)
 {
 	unsigned int version = 0, patchlevel = 0;
 	/* Deliberately ignore sublevel and extraversion. */
@@ -1002,7 +1002,7 @@  static const luaL_Reg l_swupdate[] = {
         { "mount", l_mount },
         { "umount", l_umount },
         { "getroot", l_getroot },
-        { "getversion", l_getversion },
+        { "getversion", lua_get_swupdate_version },
         { "progress", l_notify_progress },
         { NULL, NULL }
 };
diff --git a/include/lua_util.h b/include/lua_util.h
index 81da802..13cffc0 100644
--- a/include/lua_util.h
+++ b/include/lua_util.h
@@ -34,6 +34,8 @@  int lua_notify_info(lua_State *L);
 int lua_notify_warn(lua_State *L);
 int lua_notify_debug(lua_State *L);
 
+int lua_get_swupdate_version(lua_State *L);
+
 #define lua_parser_exit(L) lua_close((lua_State *)L)
 
 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501