diff mbox series

doc: Lua: add prototype for get_cmdline

Message ID 20251209160543.156001-1-stefano.babic@swupdate.org
State Accepted
Headers show
Series doc: Lua: add prototype for get_cmdline | expand

Commit Message

Stefano Babic Dec. 9, 2025, 4:05 p.m. UTC
Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---

As example, to get all parmspassed via kernel command line in a hook:

require ('swupdate')
function testcmdline(image)
	t = swupdate.get_cmdline()

        for k,l in pairs(t) do
              	swupdate.trace(\"==> \" .. tostring(k) .. \" = \" .. tostring(l))
        end

	return true, image
end ";



 handlers/swupdate.lua | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Storm, Christian Dec. 10, 2025, 12:08 p.m. UTC | #1
Hi Stefano,

> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
> ---
> 
> As example, to get all parmspassed via kernel command line in a hook:
> 
> require ('swupdate')
> function testcmdline(image)
> t = swupdate.get_cmdline()
> 
>        for k,l in pairs(t) do
>               swupdate.trace(\"==> \" .. tostring(k) .. \" = \" .. tostring(l))

do you actually need tostring() here since the C counterpart reads
	+ lua_pushstring(L, parms[index]);
	+ lua_pushstring(L, val);
	+ lua_settable(L, -3);
and hence it's always of type string? Not that it hurts, just wondering...


Kind regards,
  Christian
Stefano Babic Dec. 10, 2025, 2:59 p.m. UTC | #2
On 12/10/25 13:08, 'Storm, Christian' via swupdate wrote:
> Hi Stefano,
> 
>> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
>> ---
>>
>> As example, to get all parmspassed via kernel command line in a hook:
>>
>> require ('swupdate')
>> function testcmdline(image)
>> t = swupdate.get_cmdline()
>>
>>         for k,l in pairs(t) do
>>                swupdate.trace(\"==> \" .. tostring(k) .. \" = \" .. tostring(l))
> 
> do you actually need tostring() here since the C counterpart reads
> 	+ lua_pushstring(L, parms[index]);
> 	+ lua_pushstring(L, val);
> 	+ lua_settable(L, -3);
> and hence it's always of type string? Not that it hurts, just wondering...

No. it is not needed, and the code above does not flow into the project. 
It is just to show an example how to retrieve values from the table.

Regards,
Stefano
diff mbox series

Patch

diff --git a/handlers/swupdate.lua b/handlers/swupdate.lua
index d32f83b9..aaba4774 100644
--- a/handlers/swupdate.lua
+++ b/handlers/swupdate.lua
@@ -215,6 +215,10 @@  swupdate.set_bootenv = function(key, value) end
 --- @return string       # Bootloader environment key's value, empty if key absent
 swupdate.get_bootenv = function(key) end
 
+--- Get table with linux kernel command line
+--
+--- @return table       # Table with keys and value, for example t[root] return root device
+swupdate.get_cmdline = function() end
 
 --- @enum swupdate.HANDLER_MASK
 --- Lua equivalent of `HANDLER_MASK` as in `include/handler.h`.