Not. This is not at all how it works.
The Lua interpreter provides one global table, usually called _G, unless you are doing something strange.
function printthis() print(var) end
This means that in reality
_G.printthis = function() _G.print(_G.var); end
And your code is basically equal
local module = _G.require("module") local var = "I should be global?" _G.printthis()
But when you call printthis - where did _G.var set up? Nowhere. Thus, the nil variable, like all other table calls, where there is nothing in this key.
This may be inconvenient, but in the long run it is a much better idea to pass arguments than instead of global variables. As soon as you come to change something about the program, it is completely impossible to make any changes, since the logic has no structure, and you can not imagine what happens when you do not read every line of code and do not understand it immediately. In addition, you can use only each key in one place, because it is a global table, so I am sure that no one wants to use "var" as a variable name, and you do not mind that your code is silent, because you got the global name is incorrect.
Puppy source share