[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Unofficial FAQ Addition
- From: Dimiter 'malkia' Stanev <malkia@...>
- Date: Thu, 06 Oct 2011 11:30:17 -0700
What I'm doing is this:
Make a folder named "1", and put in there "1/a.lua" and "1/b.lua"
-- 1/a.lua
print("_G.arg[0] = [".._G.arg[0]..']')
print(" ... = [".. tostring(... and ... or "<null>") ..']')
and then
-- 1/b.lua
print("require('1/a')")
require( "1/a" )
print()
print("dofile('1/a')")
dofile( "1/a.lua" )
Experiment with it. So basically it boils down to _G.arg[0] and ...
... is only not null when a module was required. Here is what it prints
here:
E:\p\lua-testing\1>cd ..
E:\p\lua-testing>lua 1/a.lua
_G.arg[0] = [1/a.lua]
... = [<null>]
E:\p\lua-testing>lua 1/b.lua
require('1/a')
_G.arg[0] = [1/b.lua]
... = [1/a]
dofile('1/a')
_G.arg[0] = [1/b.lua]
... = [<null>]
E:\p\lua-testing>lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> dofile('1/a.lua')
_G.arg[0] = [<null>]
... = [<null>]
> dofile('1/b.lua')
require('1/a')
_G.arg[0] = [<null>]
... = [1/a]
dofile('1/a')
_G.arg[0] = [<null>]
... = [<null>]
> require('1/a')
> require('1/b')
require('1/a')
dofile('1/a')
_G.arg[0] = [<null>]
... = [<null>]
On 10/5/2011 10:36 AM, Rob Hoelz wrote:
Hello list,
I assume the maintainer of luafaq.org lurks this list, so I have a
question/answer I'd like added to the FAQ.
"How do I tell require to search relative to the current module?"
I've seen this question asked a dozen times on the list; it'd be nice
to be able to direct people to a consistent answer.
-Rob