In python i could do something like
Code: Select all
import mainMenu.py as M
Code: Select all
M.draw()
Code: Select all
import mainMenu.py as M
Code: Select all
M.draw()
Yep, you can use the "module" keyword:Dola wrote:I know i could make each file a table with a lot of functions inside and require it normally but is there a more elegant way of doing this?
Code: Select all
local base = _G
module("api")
function foo()
math.random(1, 100)
-- error, "math" is undefined
end
function bar()
base.math.random(1, 100)
-- the proper way to access "math"
end
It is.Nixola wrote:Isn't the module function deprecated?
Code: Select all
local m = {}
function m.draw()
....
end
...
return m
Code: Select all
local foo = require 'somemodule'
foo.draw()
That is unfortunate, yes. However, if you write the module yourself, you can make it well written. If it's a 3rd party library, you should probably use one that's well written anyway.T-Bone wrote:The problem there is that it assumes that the module you are importing is well written.
Users browsing this forum: No registered users and 2 guests