Jump to content

_G = GLOBAL


Recommended Posts

I always use

_G = GLOBAL

Because GLOBAL._G == GLOBAL
i.e. _G == _G._G
So _G always defined and works fine irrespective of, whether the GLOBAL variable is defined.

My question is about "local" statement.
Is there difference for optimization between

_G = GLOBAL

and

local _G = GLOBAL

I noticed that I can get variables of local "global space" of other mods by using

local env = _G.ModManager:GetMod("modname").env

But there are only "globals", not "locals". E.g. I can use env.x if and only if there is global definition (x=5), and I can't use env.x if there is only local definition (local x=5).
So there is some difference. But is there difference for optimization?

I read some lua optimization tips. They said that local variables are very fast. But I'm not sure about variable in local global space (environment of the mod). It seems that they are in the same scope. Only difference that locals are invisible for accessing from outside. That's it. So is there any real difference for optimization? Does anybody know?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...