0

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'?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • Thi is not working code. It has syntax error. And also you can not load neather A or B file because of loop. – moteus Apr 06 '15 at 12:16
  • Yes you are right, I'm calling the Game:init() method out of java so it is no loop –  Apr 06 '15 at 12:24
  • 1
    It should work `c.lua` `require "A" Game:init()` prints `7` and `othername` – moteus Apr 06 '15 at 12:28
  • So the problem is somewhere in the AndroLua implementation of the `require()` function :( –  Apr 06 '15 at 12:31
  • I just noticed that tostring(Game) returns a different table name in A and in B. This is strange... –  Apr 06 '15 at 12:38

2 Answers2

0

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 '}'
lhf
  • 70,581
  • 9
  • 108
  • 149
0

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