AmericanNero
Seasoned veteran member
- Joined
- Oct 13, 2020
- RedCents
- 4,709¢
Hardcoding your Lua project name (package) into require statements can make it difficult to update filepaths and cause the module finder to not find your libs.
You can avoid hardcoding your Lua project / package name into your requires using the following example:
local _PACKAGE = (...):match("^(.+)[%./][^%./]+") or ""
require(_PACKAGE..'lib/mylib')
Likewise, if you have another directory level to traverse in a lib file, you can repeat the sequence above. In this way you can freely embed nested requires without having to type them out and correct them should they change. This is useful when comparing multiple versions of the code.
The solution to this issue, which is getting into the Lua code here, was gleaned from: https://github.com/tanema/behaviourtree.lua/blob/master/lib/behaviour_tree.lua
You can avoid hardcoding your Lua project / package name into your requires using the following example:
local _PACKAGE = (...):match("^(.+)[%./][^%./]+") or ""
require(_PACKAGE..'lib/mylib')
Likewise, if you have another directory level to traverse in a lib file, you can repeat the sequence above. In this way you can freely embed nested requires without having to type them out and correct them should they change. This is useful when comparing multiple versions of the code.
The solution to this issue, which is getting into the Lua code here, was gleaned from: https://github.com/tanema/behaviourtree.lua/blob/master/lib/behaviour_tree.lua
Last edited:

