lua-users home
lua-l archive

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

I've thought about this a few times - are there any common or useful use cases of metatables where the assumption that metatable functions are idempotent (that is, the program state is the same after calling the function once as it is after calling it twice), AND that they only modify the table they are associated with, would lead to incorrect semantics?

An obvious and trivial example is a metatable that counts accesses to a table, but this would usually be used for debugging/profiling rather than in production; I've not been able to think of any other examples.

Making this assumption would allow a compiler to cache the results of table accesses within a scope, invalidating them over function calls but not table accesses.

----- Original Message ----- From: "Mark Hamburg" <>
To: "Lua list" <>
Sent: Friday, August 31, 2007 4:53 PM
Subject: Re: Compiler Optimizations

* For almost everything else, the metatable semantics make optimization
almost impossible.