lua-users home
lua-l archive

dofile() like require()

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


Why is the LUA_PATH behaviour of dofile() not equivalent to require()?
I don't like to switch between two ways of accessing files e.g:
require( 'Lib/Lua/Library.lua')
 dofile('/usr/local/apache/htdocs/'..'Lib/Lua/Test/dofile/Dummy.lua')
I think its easier to understand, better to read, less errors...
require('Lib/Lua/Library.lua')
 dofile('Lib/Lua/Test/dofile/Dummy.lua')
I have done it and don't see negative aspects. Please let me know why do
you think this should not be done. By the way: I like the very
interesting Receiver() function mechanism.
 do
 local Flag,Vararg
 local Receiver=function(Intercept,...) Flag,Vararg = Intercept,arg end
 local Function=dofile
 function dofile(File)
 Receiver(pcall(Function,File))
 if Flag==false then
 local Path,Argument = LUA_PATH
 if type(Path)~='string' then
 Path=os.getenv('LUA_PATH') or './?.lua'
 end
 for Path in string.gfind(Path,'[^;]+') do
 Argument=string.gsub(Path,'%?',File)
 Receiver(pcall(Function,Argument))
 if Flag then break end
 end
 end
 return(unpack(Vararg))
 end
 end
--
Markus

AltStyle によって変換されたページ (->オリジナル) /