Does locally caching a table also locally cache all its indexes?

I'm working on setting up application-wide variables, and I'm caching some global variables (and functions) that I use a lot. I'm not sure if locally caching a table ALSO locally caches all its indexes.

This seems like a dumb question, my first thought was "of course!", but then I found out all the global variables are stored in _G and I can't imagine that "local _G = _G" would cache every global variable in a single line, seems like that's too dangerous to allow.

Let's say I have a situation like this, I declare some global variables in my main.lua file:

1
2
3
4
gameVars = {}
gameVars.sfx = true
gameVars.currentLevel = 1
gameVars.playerName = "Default Player"

My understanding is you'd only need to local the main table.
When you access the property or function of a table, there's presumably a fixed 'cost' associated with getting said property or function from the table.
The speed difference comes in the actual getting of the table, either from the global or local space.
Its this part that we are altering to be as quick as possible, but once we have the table reference itself locally, accessing its properties or functions will be as quick as they can be.

Barry

views:1225 update:2011/10/5 21:23:48
corona forums © 2003-2011