lua-users home
lua-l archive

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

Thanks Tim for the thoughtful reply.

> 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.

Could you link an example of #3? I think it's equivalent to what I am
doing and maybe I can take some ideas for my code.

> Of these choices, #4 is the most efficient, since it places the state in upvalues

I am happy enough taking the table-lookup hit by default provided I
can easily switch to upvalues if profiling suggests this would be a
good idea.

This seems to be easy in my code: if there would be 5 functions that I
want to move to upvalues then I can write "local f1,f2,f3,f4,f5" at
the top of my source file and it will be done. (I think :-))

I resist making everything local mostly because I prefer to write my
source files with the callers first and the callees last. For me this
luxury is worth creating a little bit of extra performance profiling

I will have to revisit all of these issues soon when I want to deal
with dynamic code reloading as in Emacs/Erlang...