I have something like this.
/config.lua
/client/init.lua
How can I include the config.lua
with include()
or dofile()
?
Lg
Lua offers a higher-level function to load and run libraries, called require . Roughly, require does the same job as dofile , but with two important differences. First, require searches for the file in a path; second, require controls whether a file has already been run to avoid duplicating the work.
Lua modules and packages - what you need to know As with most search paths, the LUA_PATH is actually a semicolon-separated collection of filesystem paths. Lua scans them in the order they are listed to find a module. If the module exists in multiple paths, the module found first wins and Lua stops searching.
You can (and probably should) do this with require
by adding ../?.lua
to package.path
, like so:
package.path = package.path .. ";../?.lua"
require "config"
See the require and package.path docs for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With