Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate with .lua to a directory above

I have something like this.

/config.lua
/client/init.lua

How can I include the config.lua with include() or dofile()? Lg

like image 448
nn3112337 Avatar asked Dec 17 '13 17:12

nn3112337


People also ask

Where does Lua look for require?

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.

What is Lua_path?

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.


1 Answers

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.

like image 68
furq Avatar answered Sep 24 '22 21:09

furq