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:

[lua]gameVars = {}
gameVars.sfx = true
gameVars.currentLevel = 1
gameVars.playerName = “Default Player”[/lua]

Then in another module I have this:

[lua]local gameVars = gameVars

print ( gameVars.playerName ) – is gameVars.playerName local or global?[/lua]

So is caching “gameVars” as a local enough, or do I have to cache EACH of its indexes individually as local, like this:

[lua]local gameVars.sfx
local gameVars.currentLevel
local gameVars.playerName

print ( gameVars.playerName ) – gameVars.playerName is definitely local here[/lua]
The same situation applies (I think) for external libraries:

[lua]local enemyLib = require “enemyLib”

enemyLib.spawnEnemy() – is this a local or a global function call?[/lua]

I can’t seem to find any documentation on this and I’m not sure how to test for it… [import]uid: 49372 topic_id: 9407 reply_id: 309407[/import]

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 [import]uid: 46639 topic_id: 9407 reply_id: 34412[/import]