lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


but require also looks in the current working directory

I find a way to solve this

use require "..\\a\\a"  ok
while require "..\\a\\a.lua" error

very confuse about this.

----- Original Message ----- 
From: "HyperHacker" <hyperhacker@gmail.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, June 24, 2010 2:21 PM
Subject: Re: require vs dofile (lua 5.1.4 windows)


On Thu, Jun 24, 2010 at 00:13, mos <mmosquito@163.com> wrote:
> Hi!
> there are 2 files in 2 fold like:
> a
> a.lua
> b
> b.lua
>
> the b.lua use
> require "..\\a\\a.lua"
> will get a error can not find a.lua
>
> but use
> dofile("..\\a\\a.lua")
> will ok
>
> I don't konw why.
>
> Best Regard
> yujiang
>

require() looks in the paths in package.path and package.cpath, while
dofile() looks in the current working directory. See
http://www.lua.org/manual/5.1/manual.html#pdf-require

-- 
Sent from my toaster.