[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: tested index patch (was: Undefined variables returning nil)
- From: Sven Olsen <sven2718@...>
- Date: Fri, 22 Mar 2013 00:11:59 -0700
“or” isn’t quite what is wanted here, is it? it would (undesirably) catch
object.name == false (as opposed to just nil).
Ok, now it's starting to look like I've got myself a fairly clean, simple patch.
table!.field
is syntax sugar for
_CHECKED(table.field,"table","field")
where _CHECKED is defined as:
function _CHECKED(v,tname,kname)
if v~=nil then
return v
end
error(string.format("%s is missing required field: %q",tname or "<_expression_>", kname),2)
end
In the case that there's no clear name string associated with the table, then we can make the syntax sugar pass nil as the second argument to checked. So, for example,
local a = (b or c)!.e
expands as:
local a =_CHECKED( (b or c).d, nil, "d" )
That's a limited semantic which seems to work fine in practice. You can't use "table!.value" as an lvalue, but that's probably not a big deal, as most of the use cases I can think of are reads.
-Sven