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

我在安卓上使用 AndroLua 的 LuaJava 移植版,在文件 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' 和 'othername'?

点赞
用户107090
用户107090

文件 A 中存在语法错误:一个函数应该以 end 结束,而不是 }

您应该收到像这样的错误消息:

error loading module 'A' from file './A.lua':
    ./A.lua:9: unexpected symbol near '}'
2015-04-06 12:14:32
用户88888888
用户88888888

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

2015-04-06 13:21:08