[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: as so often before require()
- From: Markus Huber <pulse@...>
- Date: Mon, 17 Feb 2003 14:36:26 +0100 (GMT)
Main file: require(<File A>)
File A: print(_REQUIREDNAME) --> File A
require(<File B>)
print(_REQUIREDNAME) --> File B !
File B: print(_REQUIREDNAME) --> File B
I think in the whole scope of a required file _REQUIREDNAME should be
the same own name. I find this behaviour when testing the following
technic (this example shows not the _REQUIREDNAME problem):
Overload require and keep the functionality compatible:
_RELOAD={}
local Function=require
function require(File)
-- if a required file sets the _RELOAD[<File>] flag then
-- its loaded again with the next requiring of this file
if _RELOAD[File] then
_LOADED[File]=nil
end
Function(File)
end
Usage in a required file:
if <environment is correct> then
_RELOAD[_REQUIREDNAME]=nil
print('environment is correct --> do the job')
else
_RELOAD[_REQUIREDNAME]=true
print('environment is incorrect --> do nothing')
end
Its very simple to correct the problem with _REQUIREDNAME with Lua but
I think it should be corrected in C:
local Function=require
function require(File)
local Memorize=_REQUIREDNAME
Function(File)
_REQUIREDNAME=Memorize
end
--
Markus