Topic: Classes in Lua (A little help)

I guess classes aren't a part of lua, but I found a tutorial on youtube that shows you how to fake it. And it fakes it really well:

https://www.youtube.com/watch?v=jq58moMWlT8

But! I modified his example a little, and I need suggestions on how to make it more authentic (If it can be any more authentic):

--New Person Class
function newPerson(name,age)
            local object = {}
           
            object.name = name
            object.age = age
           
            function object:sayName()
                print (object.name)
            end   
               
            return object
end

--Create Joe
local joe = newPerson("Joe",24)

--Create Bill
local bill = newPerson("Bill",25)

--Print Joe's name
print (joe.name)

--Make Bill say his name
bill:sayName()

Last edited by Tutorial Doctor (2013-08-23 05:57:45)

Re: Classes in Lua (A little help)

did you look at this exemple in the wiki ?
http://wiki.maratis3d.org/index.php?tit … ng_example

I made it to show how to create a class-like object.

Re: Classes in Lua (A little help)

anael wrote:

did you look at this exemple in the wiki ?
http://wiki.maratis3d.org/index.php?tit … ng_example

I made it to show how to create a class-like object.


Hehe. I guess I didn't read that part. Thank you!!