-
I'm currently working on a library which has multiple files that depend on each other. (not cyclically) Imagine:
How can I consistently load
For Note that I don't mean |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I'd set So, in the case of package.path = "lib/?.lua:" .. package.path
local foo = require "foo" |
Beta Was this translation helpful? Give feedback.
-
The current module name ( local function get_prefix(str)
local pos
while true do
local next = str:find(".", pos, true)
if not next then break end
pos = next + 1
end
if pos then return str:sub(1, pos - 1) else return "" end
end
local prefix = get_prefix(...) -- Will be something like "lib." or "".
local bar = require(prefix .. "bar") -- So will be "lib.bar" or "bar" |
Beta Was this translation helpful? Give feedback.
I'd set
package.path
inside your entrypoints, so thatlib
is always on the path. This way both your entrypoints and other libraries only need to dorequire "foo"
/require "bar"
.So, in the case of
main1.lua
, something like