[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: extending lua load path
- From: Duncan Cross <duncan.cross@...>
- Date: Mon, 14 Nov 2011 17:56:44 +0000
On Mon, Nov 14, 2011 at 4:47 PM, Oliver Mueller
> I have a lua interpreter embedded in my program and want to execute
> some scripts.
> The scripts are located in folder "scripts". One script requires
> another like this:
> 1.script ("scripts/myscript.lua"):
> 2.script ("scripts/base.lua"):
> Now when I call my executable from within the "script" directory,
> everything is fine since "." is in the Lua load path.
> "executable myscript.lua"
> But when I call it from anywhere else, the require "base" is not found:
> "executable scripts/myscript.lua"
> run-error - [string "script/myscript.lua"]:1: module 'base' not found..
> In ruby I can resolve this issue by adding the directory of the
> myscript.lua file to the load path:
> $:.unshift File.dirname(__FILE__)
> Can anybody tell me how I this is done in Lua?
The load paths are taken from package.path - it is a
semicolon-separated string, where a question mark is used to
interpolate the package name. So, to look for modules inside the
'scripts/' folder, do this before any calls to require():
package.path = package.path .. ';scripts/?.lua'