lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



> On May 4, 2019, at 8:04 PM, Soni They/Them L. <fakedme@gmail.com> wrote:
> 
> I often write code like:
> 
> local foo = t.foo
> if not foo then foo = whatever t.foo = foo end
> -- use foo here
> 
> but ideally I'd like to write it like:
> 
> if not t.foo then t.foo = whatever end
> local foo = t.foo
> 
> and still have the same performance (or better).
> 
> does lua do any optimizations related to this?
> 

Do you REALLY mean “if not foo…” ? Dont you actually want “if foo == nil …” ?

—Tim