How does require().method() appear to be - local or global value?
I have actually a file similar to this. I want to include this file into another one, and call the method setRelation(params).
[lua]local Superparents = {}
function Superparents.setRelation( params )
–code
end
return Superparents[/lua]
I have tried to included the above file like this:
[lua]require(“Superparents”).setRelation( Child1, “RootClass” )[/lua]
AND like this:
[lua]local sp = require(“Superparents”)
sp.setRelation( Child1, “RootClass” )[/lua]
…both variations worked, but which one appears to be created locally (local table) and which one globally (global accessible table)? Which one would you prefer?
I’ve digged into the _G variable, but didn’t found my answer, because I saw both times the same happening. It was both times included in _G and looked like so: Superparents { setRelation = "function ..." } [import]uid: 73502 topic_id: 19307 reply_id: 319307[/import]
@Peach: I know that)) I mean I know how I can create a local or global variable that holds my file.
I want the above example to be local. So local sp = require("Superparents") would do that job. But I wanted to know if require("Superparents") is local too? Or is it global?
In other words … is that sp = require "Superparents" equal to that require("Superparents").setRelation( Child1, "RootClass" )??? Are they both global?
thank you [import]uid: 73502 topic_id: 19307 reply_id: 74540[/import]
It’s in the first post
[lua]local Superparents = {}
function Superparents.setRelation( params )
–code
end
return Superparents[/lua]
I just wanted to know If i can use require(“file”) without assigning it to a variable (not to local not to global, just not assigning at all). Actually that is possible, since it works. But how is that require() treated/handled then by LUA? as global or local include? I mean are those methods from aboves code example global or local then? [import]uid: 73502 topic_id: 19307 reply_id: 74556[/import]