[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5 getglobals
- From: "Peter Hill" <corwin@...>
- Date: Mon, 24 Feb 2003 12:18:42 +0800
Peter Hill:
> Why does "setglobals" not work on C-functions? Is this deliberate (seems
> unlikely) or due to some implementation problem?
Roberto Ierusalimschy:
> It is deliberate. All C functions share a common environment table
> (new name for the old "table of globals", as they are not globals).
> A "setglobals" for a C function would change the environment of all
> C functions, but would not affect Lua functions (as they have their
> independent environments). This is difficult to explain, and does not
> seem very useful.
So it is basically an implementation limitiation (rather than a 'design
feature').
I'm not sure how often one might want to set the globals of a C function
(and in practice one could always just wrap it in a Lua function) but the
limitation does cause Lua to behave in a non-intuitive & unpredicable
fashion.
Afaik, one can't test in Lua5 whether a function is native Lua or C... and I
find it rather unsettling that if someone chose to replace a Lua function
with a compiled version then the behaviour of my program might completely
change.
These new function-globals seems to be a very powerful & useful addition to
Lua :-) ... but this non-homogeneity in behaviour seems to unnecessarily add
complexity to the system's behaviour. How expensive would it be to
homogenise it?
*cheers*
Peter Hill.
Ki: Contractors... high-paid leeches stealing our work.
Fooker: If you think of them as disposable employees, you'll feel much
better...