在Lua(Corona)中引用父类的参考。

在我的game.lua文件中,有这个函数:

function new()

    local obj = display.newGroup();

    currentLevel = Level.new(1);
    currentLevel.game = obj; //也尝试过 currentLevel.game = self;

    function obj:replay()
            print("game - replay")
    end

    return obj;

end

在Level.lua文件中,我尝试调用game.lua中的replay函数:

game = {};
...
game:replay();

但我得到这个错误: 尝试调用方法'replay' (一个空值)

如何在level.lua中保持对game.lua的引用?

原文链接 https://stackoverflow.com/questions/6034474

点赞
stackoverflow用户169828
stackoverflow用户169828

你是不是想说 game = new() 而不是 game = {}? 如果你用 {} 创建 game,那么它就是一个空表。

2011-05-17 21:47:16