29 posts
Posted 18 August 2012 - 04:27 PM
have you ever wished you have object oriented possibilities in lua? well, its possible.
took me a bit to research, so i decided to leave a link in this very section
http://lua-users.org/wiki/ObjectOrientedProgrammingsure you dont have the full arsenal of full featured OOP languages and miss stuff like polymorphism. but the basics that make up OOP after all are all there.
happy coding
839 posts
Location
England
Posted 18 August 2012 - 04:56 PM
have you ever wished you have object oriented possibilities in lua? well, its possible.
took me a bit to research, so i decided to leave a link in this very section
http://lua-users.org...ntedProgrammingsure you dont have the full arsenal of full featured OOP languages and miss stuff like polymorphism. but the basics that make up OOP after all are all there.
happy coding
For anyone who has ever heard me say OO for lua isn't very clearly explained, this is the webpage/site I'm referring to. It's all there but it's not really written for someone who isn't already used to OO in lua.
445 posts
Posted 18 August 2012 - 07:15 PM
2 posts
Location
Maryland, USA
Posted 18 August 2012 - 10:07 PM
I'm going to stick with learning OOP with Python and staple the Lua syntax over the top of that conceptual knowledge later on. =-P
Edit: Now that I think about it… should this thread be elsewhere? OOP tutorials aren't quite an API or utility.
Edited on 18 August 2012 - 08:08 PM
496 posts
Location
Harlem, NY
Posted 19 August 2012 - 06:58 AM
You can find some OOP examples in use in the Redworks addon. If you have Redworks, just type MineDwarf.
Anyway, due to the content in the OP, thread will be moved to the General Section.
997 posts
Location
Wellington, New Zealand
Posted 19 August 2012 - 08:31 AM
How can't you have polymorphism?
Superclass = {}
function Superclass:create()
return setmetatable({}, {__index = Superclass})
end
function Superclass:callPrintStuff()
self:printStuff()
end
function Superclass:printStuff()
print("Superclass printStuff")
end
Subclass = {}
setmetatable(Subclass, {__index = Superclass})
function Subclass:create()
return setmetatable({}, {__index = Subclass})
end
function Subclass:printStuff()
print("Subclass printStuff")
end
local inst = Subclass:create()
Subclass:callPrintStuff() -- prints Subclass printStuff