lua-users home
lua-l archive

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


> What impact would calling a metamethod have, that is called when a
> variable goes out of scope and that has said metamethod defined?
> Would the check for the presence of such a metamethod already
> introduce an inacceptable overhead?

"Inacceptable" is a broad term, but such check would need also an opcode
to invoke it. Even a no-op extra opcode inside a tight loop body that
happens to define a local variable seems a waste.

Moreover, once programmers learn that creating local variables inside
loops have a price, they will start to avoid doing that, even if the
real price is "acceptable". So, that probably would incentivise bad
programming practices, such as top-declaring all local variables.

-- Roberto