1

You know how when your making a class in python you do,

class className(object):
    def __init__(self):
        # INIT called first in a class

my question is how would you do this in lua? Is there even classes in lua? If so what in Lua is like the python function __init__() I'm just starting to learn Lua 5.1 and I noticed that i haven't run into classes. Is Luas table system used for making classes in Lua, for example.

function getName(name) return name end
local className -- class
className['getName'] = getName
className.getName('name')
greatwolf
  • 20,287
  • 13
  • 71
  • 105
user3103366
  • 65
  • 1
  • 9
  • Though I kinda like Lua better then python because of the tables, I like being able to do `func = {} func['name'] = 'name'` then calling `func.name` instead of python dict `func['name']` – user3103366 Mar 19 '14 at 18:12
  • Actually, `className.__new__` would be called before `className.__init__`. The former creates a new instance of the class and then the latter handles the initialization of that instance. –  Mar 19 '14 at 18:15
  • I forgot about `__new__` i've never felt the need to use it that might be why. – user3103366 Mar 19 '14 at 18:19

0 Answers0