[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ternary operator patch
- From: Wesley Smith <wesley.hoke@...>
- Date: Thu, 16 Sep 2010 09:19:09 -0700
> I call it 'pseudo' because it would be part of the grammar - only way
> one could get that late evaluation.
Or you could use loadstring:
format = string.format
function lazy_assert(cond, errmsg)
if(cond) then
return cond
else
local env = setmetatable({}, {__index = _G})
return nil, setfenv(loadstring(errmsg), env)()
end
end
x = 1
print(lazy_assert(x == 1, [[return format("bad equation %f == 1", x)]]))
print(lazy_assert(x == 2, [[return format("bad equation %f == 2", x)]]))
Of course, you can't use locals here, but if you could pass in an env
table or varargs somehow to lazy_assert it would be possible.
wes
- References:
- Re: Ternary operator patch, steve donovan
- Re: Ternary operator patch, Henk Boom
- Re: Ternary operator patch, steve donovan
- Re: Ternary operator patch, Geoff Leyland
- Re: Ternary operator patch, steve donovan
- Re: Ternary operator patch, Miles Bader
- Re: Ternary operator patch, David Kastrup
- Re: Ternary operator patch, Miles Bader
- Re: Ternary operator patch, David Kastrup
- Re: Ternary operator patch, Jonathan Castello
- Re: Ternary operator patch, Roberto Ierusalimschy
- Re: Ternary operator patch, Alexander Gladysh
- Re: Ternary operator patch, steve donovan
- Re: Ternary operator patch, Jeff Pohlmeyer
- Re: Ternary operator patch, steve donovan