Answered by
8 years ago Edited 8 years ago
When defining functions in any table (_G is a table too), you can do it in two main ways; either like this:
1 | _G.MyFunction = function () |
or like this:
1 | function _G.MyFunction() |
While this is not related to your specific case of _G, you can also do this:
1 | function MyTable:MyFunction() |
This will define the function in such a way that the first argument will always be refered to as self
, and if you later call the function like MyTable:MyFunction()
then the first argument will be the table itself. This can be used for OOP in Lua.