lua-users home
lua-l archive

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



"Environment table" certainly sounds like a much better term than multiple sets of "globals".
Thanks - hopefully that's used in the upcoming 5.0 book as well?

-ak


Edelleenlähetetyn viestin alku:

Lähettäjä: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Päiväys: perjantai, 21. helmikuuta 2003  22:33:22 +0200
Vastaanottaja: Multiple recipients of list <lua-l@tecgraf.puc-rio.br>
Aihe: Vastaus: Lua 5 getglobals
Vastaus: lua-l@tecgraf.puc-rio.br

Why does "setglobals" not work on C-functions? Is this deliberate (seems
unlikely) or due to some implementation problem?

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.

Another question is why C functions do not have independent
environments, like Lua functions. Very few C functions use globals, and
they can use other tables as easily as they use globals. If some C
functions whant an independent environment, they can share a table
via upvalues.

-- Roberto