Lua全局表在不同的文件中不同



我在Android上使用LuaJava的AndroLua端口,当我在文件a中定义全局表并尝试从文件B访问它时,缺少一些条目:

文件A:

Game = {
  name = "name"
}
function Game:init()
  self.score = 7
  self.player = "othername"
  require('B')
end

Game:init()方法是从java调用的。

文件B:

require('A')
print(Game.score) -- nil
print(Game.player) -- 'name'

为什么文件B不打印"7"one_answers"其他名称"?

文件a中存在语法错误:函数应以end结尾,而不是以}结尾。

你应该得到这样的错误消息:

error loading module 'A' from file './A.lua':
    ./A.lua:9: unexpected symbol near '}'

问题是文件B中的require('A')

最新更新