Lua global table different in different files

147 Views Asked by At

I use the AndroLua port of LuaJava on Android and when I define a global table in file A and try to access it from file B some entries are missing:

file A:

Game = {
  name = "name"
}

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

The Game:init() method is called from java.

file B:

require('A')

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

Why does file B not print '7' and 'othername'?

2

There are 2 best solutions below

0
On BEST ANSWER

There is a syntax error in file A: A function should end with end, not }.

You should have got an error message like this:

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

The problem was the require('A') in file B.