A question for the Lua experts
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 = {} 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() |
From what I have seen here it is just a case of what people are used to using.
|
Calling a function is one of the slowest things you can do in lua, and in your example you create a function which is only used to create a table and thrown away.
What do you gain by writing it this way? |
Quote:
Also like those so-called classes, you have the ability to control private or public methods/properties, as you only expose what you return. The question I guess, would be - would it be any slower than something like this? Code:
foo = {}; |
Lua supports OOP, see this:
http://lua-users.org/wiki/ObjectOrientedProgramming in particular you may be more interested in http://lua-users.org/wiki/ObjectOrie...losureApproach |
All times are GMT -6. The time now is 04:54 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI