I am trying to store different functions开发者_JAVA百科 in a table, but somehow it won't work the way I thought it would. Here is my 'code'
fn_table = { aFun1=print, aFun2=self:getSpeedLevel, aFun3=.... }
The problem now is that I can do this with the built in functions like print, assert and so on but it wont work with the other functions I've got.
I get the error: "... function arguments expected near '}'
Is it possible to store these function as well?
aFun2 = self:getSpeedLevel is a syntax error and that is what Lua complains about. Try aFun2 = getSpeedLevel or aFun2 = self.getSpeedLevel (assuming that self is a table). The Object-Oriented Programming chapter in the PiL book has more examples of functions being stored in tables.
加载中,请稍侯......
精彩评论