[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "auto-dofile with args"
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 4 Dec 2003 17:28:18 -0200
>Am I right, a drawback of this solution is that every function call is
>indirect now?
Ah yes, sorry. The code I posted does try to open a script for every time
a function with the given name does not exist. What is missing is
rawset(t,i,b)
and then there is no need for the cache (but also it won't be possible to
test timestamps).
So here is a simpler version:
local function f(t,i)
local a=loadfile(i..".lua")
if a==nil then return nil end
local b=function(...) ARG=arg return a() end
rawset(t,i,b)
return b
end
setmetatable(getfenv(),{__index=f})
Once a script with the given has been found, the corresponding global variable
will be set to the associated function and the __index metamethod will never
be called again for this name. To reload a script, you'll have to set the
corresponding global variable to nil.
>Or this question in other form: How "normal" function calls handled after
>"magic.lua"?
They're not affected at all; only "undefined" global variables are tested
as script names.
--lhf