lua-users home
lua-l archive

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


> 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