lua-users home
lua-l archive

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

2011/8/13 Gaspard Bucher <>:
> Related to performance and LuaJit friendliness, is it better to
> have all globals as up-values (A) or to load them from _G on
> runtime (B) ? Is there still another way ?
> I like the fact that method 'A' highlights code dependencies
> but I do not know what this implies...
> [...]
> Thanks for any feedback...

There is a semantic difference. If you keep local references, any
further re-assignement of the globals won't get into your code. For
example imagine that you want to replace the print function with
another one that logs in a file. If your module was loaded prior to
the modification, and keeps a local reference, it will still use the
old print function.

Even on a module level (only keep local references to other modules),
this can prevent the host application for properly doing dynamic
module update (ie. reload an updated module source without restarting
the app), because your code keeps a reference to the old module

These are just examples of what you need to take care when doing such
"optimizations", they are not always benign.