[PATCH] doc: Lua: add prototype for get_cmdline

9 views
Skip to first unread message

Stefano Babic

unread,
Dec 9, 2025, 11:05:51 AM (12 days ago) Dec 9
to swup...@googlegroups.com, Stefano Babic
Signed-off-by: Stefano Babic <stefan...@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(+)

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`.
--
2.43.0

Storm, Christian

unread,
Dec 10, 2025, 7:08:32 AM (11 days ago) Dec 10
to swup...@googlegroups.com
Hi Stefano,

> Signed-off-by: Stefano Babic <stefan...@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

--
Dr. Christian Storm
Siemens AG, FT RPD CED
Friedrich-Ludwig-Bauer-Str. 3, 85748 Garching, Germany

Stefano Babic

unread,
Dec 10, 2025, 9:59:19 AM (11 days ago) Dec 10
to Storm, Christian, swup...@googlegroups.com
On 12/10/25 13:08, 'Storm, Christian' via swupdate wrote:
> Hi Stefano,
>
>> Signed-off-by: Stefano Babic <stefan...@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

Reply all
Reply to author
Forward
0 new messages