dreamtrek wrote:
Thanks for you help.and your English is very easy to understand.
I used Ruby for a year. So I'm used to OOP.
But I am a of lua beginner.So I dont know too much.
(I've translated the missing chinese bits with
google translator. I don't think
google translator is available in China)
I'm also a ruby programmer.
Lua is simpler than Ruby.
There are no classes. Only "tables".
In lua, tables are Arrays and Hashes.
Code: Select all
-- this is a comment
local array = { 'one', 'two', 'three' }
local hash = { a = 1, b = 2, c = 3 }
print(array[1]) -- prints 'one'
print(hash['a']) -- prints '1'
print(hash.a) -- this also prints '1'
-- functions can be defined like this:
function foo(bar)
print(bar)
end
-- and they can be used as variables
hash[d] = foo -- this is the function!
hash.d('this looks like a method!') -- invoking the function
Tables in lua can something similar to ruby's
method_missing for classes. For lua, it is named __index. __index is a metamethod. Metamethods are (a bit) complicated.
On MiddleClass, I created a special table called
Object, and a function called
class. You can use them to create classes without having to worry about metamethods.