lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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