4 ms·
> In Lua, nil is assuredly a value Please tell me how I save nil in a field of a table.
by aasasd 6y ago
> In Lua, nil is assuredly a value
Please tell me how I save nil in a field of a table.
- samatman 6y agolike so: local tab = { a = 1, b = 2 } -- now we set a to nil tab.a = nil -- let me prove it assert(tab.a == nil, "this won't print, because tab.a is in fact nil")
- aasasd 6y agoI see you already know perfectly well that this doesn't correspond to what people mean by saving fields in a table.
- samatman 6y agoYou seem to be frustrated that Lua doesn't work like one other programming language: Javascript. That's fine. Probably shouldn't use it. The nil handling is one of my favorite things about Lua, so let me offer you an alternative: instead of being grumpy about the language not working the way you'd like, instead embrace what it is, and work with it. Or don't, that's entirely your business.
- aasasd 6y agoOn the contrary, apparently you're unaware that a ton of languages and serialization formats have ‘null’. And there's nothing special about nil in Lua, it's just called ‘undefined’ in other dynamic languages (possibly with minor differences). Lua doesn't have a proper ‘null’. But yeah, this discussion is pointless since you're obviously not concerned either about the use-cases of exchanging data with languages that are not like C, or about keeping structures ‘schemaless’ in Lua code.