我試圖訪問「自我」的一員,請參閱以下內容:訪問LUA自我成員得到了零
function BasePlayer:blah()
--do blah
end
function BasePlayer:ctor(tape) --constructor.
self.tape = tape --'tape' is a lua table, and assigned to 'self.tape'.
dump(self.tape) --i can dump table 'self.tape',obviously it's not nil.
self.coreLogic = function(dt) --callback function called every frame.
echoInfo("%s",self) --prints self 'userdata: 0x11640d20'.
echoInfo("%s",self.tape) -- Here is my question: why self.tape is nil??
self:blah() --even function too??
end
end
所以我的問題是,在我的回調函數「coreLogic」,爲什麼「self.tape」是零但是我自己是
vaild?
函數也不能調用。
我真的很困惑:S
純Lua中沒有這樣的事'classes'和'self'。在Lua中爲您提供的代碼示例'self'是一個全局表。您能否澄清一下,您可以使用哪種框架或庫? 相關問題:[德州儀器](http://stackoverflow.com/q/7353035/1150918),來自[Love2D]的樣本(http://stackoverflow.com/q/23275262/1150918),從[ Lua classlib](http://stackoverflow.com/q/14068944/1150918),...,...,... – Kamiccolo
@Kamiccolo冒號語法的隱式'self'參數是vanilla Lua的一部分。參見[參考手冊3.4.10節](http://www.lua.org/manual/5.2/manual.html#3.4.10):'冒號語法用於定義方法,即函數有一個隱含的額外參數self。 ' – ComicSansMS
@ComicSansMS,對不起,我的壞。錯誤的問題。然而,根據[tutorial](http://lua-users.org/wiki/ObjectOrientationTutorial),點擊語法用於建立關聯和方法關聯,會發生什麼bug? – Kamiccolo