Re: Its okey or not?
Javier Guerra Giraldez <[email protected]>
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <CAFkDaoTbJbfzT1j_xVe1pG-Jv-KmOaLKX2VECnsUvdb9xb9E_A@mail.gmail.com> |
On Mon, 9 Feb 2026 at 11:21, blogdron (BLOGDRON) <[email protected]> wrote: > This behavior is probably well-known, but I've never encountered it before. I > thought if a type received a nil, it would simply return a nil, but > sometimes there's literally nothing there, not a nil. Now I'm paranoid > about wrapping everything in parentheses, even if the function returns only > one value :D haha and/or if function return nothing im force wrote return > nil > i think you diagnosed it right: it boils down to the difference between nil and "no arguments". in this case it's a bit obscured because of the behaviour of string.byte() on empty strings. of course, it's mathematically pleasing that the number or return values is the number of bytes in the input string. and an empty string has 0 bytes. this helps a lot on the case where you want to pass the results to a vararg function, or store in a table. when passing to a function with a function with a required number of args... then yes, you get issues. similarly, since a variable (or a function argument) can't hold "nothing", the difference between `type()` and `type(x)` is almost a syntactic one; i guess that's the reason to raise an error instead of returning a `nil`,<errstring> pair. so, is there any way to make it easier for a "casual" user that doesn't want to go into the language design of Lua? i can't think of any right now. -- Javier -- You received this message because you are subscribed to the Google Groups "lua-l" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/lua-l/CAFkDaoTbJbfzT1j_xVe1pG-Jv-KmOaLKX2VECnsUvdb9xb9E_A%40mail.gmail.com.