Em 7 de novembro de 2023 00:56:31 BRT, "Родион Горковенко" <rodiongork@gmail.com> escreveu:
Hi Friends!
Regard the case - I'm redefining io.read(...) - for example to allow
3-rd party code run in web-page (with Lua compiled to JS), requesting
user to provide input data via pop-ups. To properly mock the original
function behavior, I would like it to return "nil" sometimes (say upon
reading number when
no digits were provided).
io.read = function(...)
res = {}
for _, typ in ipairs(table.pack(...)) do
val = someCodeWhichCallsPrompt()
if typ == '*n' then val = parseNumberWhimsically(val) end
table.insert(res, val)
end
return table.unpack(res)
end
The difficulty is that if "parseNumberWhimsically" may return "nil",
it won't be inserted into the table. I don't know whether "table.pack"
users some complicated magic for this or on contrary I'm missing
something obvious. Thanks in advance for any hints!
sincerely yours,
Rodion