Just wondered what is the difference between the two global variables below.
[lua]a = 1
_G.a = 1[/lua] [import]uid: 62706 topic_id: 32214 reply_id: 332214[/import]
Just wondered what is the difference between the two global variables below.
[lua]a = 1
_G.a = 1[/lua] [import]uid: 62706 topic_id: 32214 reply_id: 332214[/import]
_G is a global table with a member named “a”. “a” is just a global variable. While they both become available everywhere, using the _G clearly tells anyone reading your code that you intentionally wanted that variable to be global. A loose “a” might have intended to be local. _G.a will be a bit more efficient too since Lua only has to look up one variable instead of multiple.
[import]uid: 19626 topic_id: 32214 reply_id: 128277[/import]
Thank you Rob, explained it perfectly! [import]uid: 62706 topic_id: 32214 reply_id: 128282[/import]
_G is a global table with a member named “a”. “a” is just a global variable. While they both become available everywhere, using the _G clearly tells anyone reading your code that you intentionally wanted that variable to be global. A loose “a” might have intended to be local. _G.a will be a bit more efficient too since Lua only has to look up one variable instead of multiple.
[import]uid: 19626 topic_id: 32214 reply_id: 128277[/import]
Thank you Rob, explained it perfectly! [import]uid: 62706 topic_id: 32214 reply_id: 128282[/import]