News for hackers. Stuff that matters.
Re:Fengari – Lua for the Browser by _huayra_ on Sunday February 20, 2022 @10:01AM (#30406202)
iirc, one other confusing element is that tables (hash tables? I don't remember what they're called) return null when a lookup is done for a nonexistent key.

This is not necessarily a bad choice. Exceptions and such can be a real pain. However, accidentally getting a null value because you didn't check and then have it propagate much further in your program is extremely difficult to debug. Instead of blowing up at the site of the bad lookup, you only see the distant effects of it (e.g. put the null value into another table, which gets put in another table, and then is attempted to be called as a function, etc).

Re:Fengari – Lua for the Browser by boardwaalk on Sunday February 20, 2022 @10:47AM (#30406574)
It even does this for globals (which are just another table), so there’s never an “undefined variable” error (even though there really is).

It’s pretty unfortunate. You can mitigate it using meta tables though.

Re:Fengari – Lua for the Browser by otikik on Sunday February 20, 2022 @06:40PM (#30410344)
Give Teal [1] a look. It’s basically typescript for Lua

https://github.com/teal-language/tl

Re:Fengari – Lua for the Browser by naasking on Sunday February 20, 2022 @12:05PM (#30407179)
Storing a null value is a legitimate operation. How do you distinguish "never stored a value under key K", and "stored null under key K"?
Re:Fengari – Lua for the Browser by scgtrp on Sunday February 20, 2022 @12:30PM (#30407370)
I'm pretty sure you're agreeing with them. Current Lua does this, which is wonky:

    > t = {}
    > t['a'] = nil
    > t['a']
    nil
    > t['b']
    nil