lua-users home
lua-l archive

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


Hi all,

I'm actually using loadfile to load a lua script file, then setfenv on
the result to provide it with a custom environment, and then run the
script by calling it (all this from Lua btw, not via the C api). This
works well for me, except when the script being called this way runs
its own scripts by means of dofile. Those scripts execute in the
regular global environment, rather than in the environment I provided.
Is this supposed to happen, in vanilla Lua 5.1? Or is it more likely
that the host application which executes my scripts replaces the
dofile function with a new implementation (I don't know if it does, I
didn't write it)?

One of the things I'm using this mechanism for, is to run scripts that
I did not write (and don't want to edit) on my own terms. In fact this
is when I discovered the dofile problem. Of course I could always
supply the custom environment with a dofile implementation of my own
that does what I want it to do, but I'm still curious whether my
problem is due to Lua's original dofile implementation or not. And if
so, whether anyone thinks that it needs fixing (and why not :-)

Cheers