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...
-------------------------------------------------- A
local module_name = 'foo'
local print = print
local setmetatable = setmetatable
local lib = {type = module_name}
lib.__index = lib
-- register lib in global namespace
_G[module_name] = lib
setfenv(1, lib)
function new(name)
local self = {name = name}
return setmetatable(self, lib)
end
function hello(self)
end
return lib
-------------------------------------------------- B
local module_name = 'foo'
local lib = {type = module_name}
lib.__index = lib
-- register lib in global namespace
_G[module_name] = lib
function lib.new(name)
local self = {name = name}
return setmetatable(self, lib)
end
function lib:hello()
end
return lib
--------------------------------------------------
Thanks for any feedback...
Gaspard