If I have a table defined in the main.lua file that isn’t local, how can I reference it in other lua files?
in C, assembler, etc, you have externals where you re-define the table / label / structure as an external object.
What is the correct way to do it in Corona?
Thanks!
Stu [import]uid: 99429 topic_id: 37177 reply_id: 67177[/import]
If I have a global table in my main file along the lines of
myTable = {"hello"}
and want to reference it in another file I usually just write:
[code]
if myTable[1] == “hello” then
[/code] [import]uid: 23649 topic_id: 37177 reply_id: 145422[/import]
tetu
March 8, 2013, 6:46pm
3
_G.tableName
[import]uid: 6459 topic_id: 37177 reply_id: 145423[/import]
Thanks tetu!
It works now… Have you seen the docs for (globals) in Corona?
says NOTHING about using _G.tableName to reference external (global) tables.
This had me stumped all morning.
Stu [import]uid: 99429 topic_id: 37177 reply_id: 145425[/import]
_G is a standard feature of lua itself
Here’s the doc page for it (Corona’s page )
Keep in mind that you only have to declare _G; once it’s set you don’t have to refer to it with the _G in place (it’s somewhat interchangeable with the non-_G form.) [import]uid: 41884 topic_id: 37177 reply_id: 145437[/import]
If I have a global table in my main file along the lines of
myTable = {"hello"}
and want to reference it in another file I usually just write:
[code]
if myTable[1] == “hello” then
[/code] [import]uid: 23649 topic_id: 37177 reply_id: 145422[/import]
tetu
March 8, 2013, 6:46pm
7
_G.tableName
[import]uid: 6459 topic_id: 37177 reply_id: 145423[/import]
Thanks tetu!
It works now… Have you seen the docs for (globals) in Corona?
says NOTHING about using _G.tableName to reference external (global) tables.
This had me stumped all morning.
Stu [import]uid: 99429 topic_id: 37177 reply_id: 145425[/import]
_G is a standard feature of lua itself
Here’s the doc page for it (Corona’s page )
Keep in mind that you only have to declare _G; once it’s set you don’t have to refer to it with the _G in place (it’s somewhat interchangeable with the non-_G form.) [import]uid: 41884 topic_id: 37177 reply_id: 145437[/import]