I'm not very knowledgeable about what goes on underneath Lua's hood, so I'm hoping that someone who is, can clear something up for me.
It seems that no matter where I go, any discussion regarding pseudo namespaces/"static" classes in Lua, always boils down to something like this:
Code:
foo = {}
foo.a = "something"
foo.b = function() return "bob" end
I mean, basic - straightforward assignments.
But, see - I was playing around today, and noticed that it's possible to pull off a Javascript Module Pattern in Lua.
eg:
Code:
foo = (function()
local a="something";
function b()
return "bob";
end
return{
["a"] = a,
["b"] = b,
}
end)();
I mean obviously, for something as simple as the example, it's a bit overkill - but why isn't this a thing? Is there some performance hit involved? Or is it just a case of what people are used to?