2013-08-22 68 views
3

我在Lua中有一個簡單的類實現。Lua類不工作

test = {} 
test.__index = test 

function test:new() 
    local o = {} 
    setmetatable(o, self) 
    return o 
end 

function test:setName(name) 
    self.name = name 
    print name 
end 

local name = test:new() 
name:setName("hello") 

我不斷收到這個錯誤,當我運行它:

盧阿:test.lua:12: '=' 附近會有 '名'

我不知道什麼或爲什麼發生這種情況,任何幫助將不勝感激。

回答

5

更改print nameprint(name)print只是一個常規函數,函數調用需要圓括號,除非它們是用字符串文字或表格文字的單個參數調用的。

+0

謝謝你最欣賞的人。 – chtombleson