|
If i understand correctly, the problem is really how to maintain distinct state across multiple instances (one per card). In Lua there are several possibilities, some of which you have clearly tried out: 1. Use a table to maintain the state, and pass to functions as necessary. 2. As above, but make the functions methods and use the ":" syntactic sugar. 3. In Lua 5.2, you can manipulate _ENV so that each function thinks it is the only device (this is just a variation on #1 with tricky playing with globals). 4. Use upvalues and closures with a factory. Of these choices, #4 is the most efficient, since it places the state in upvalues, which are much more efficient to access than globals or tables (which are really the same thing). In fact, an upvalue is nearly as efficient as a local. It is also more readable in that you can access the state as if only one card exists in the methods, but maintain as many state instances as you make calls to the factory. Make sense? --Tim On Apr 6, 2013, at 8:12 AM, Luke Gorrie <lukego@gmail.com> wrote:
|