[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: storing a lua closure in a C object, then calling it from C?
- From: "Jérôme VUARAND" <jerome.vuarand@...>
- Date: Sun, 21 May 2006 20:14:44 -0400
I thought I might have to something like this. I'm still not sure
about the difference between the registry and the environment, but
I'm new to Lua and will keep on reading the manual...
I'll try to give an explanation, but I may be wrong on some points
(real gurus should react if that's the case).
Both environment and registry are standard lua tables.
The registry is a global table that is normally only accessible
through C API. There is only one per Lua interpreter.
There may be several environment tables. The first outmost global
chunk creates the first global environment. It is then passed to all
subsequent created chunks (loaded lua files and created functions), so
that any chunk has a reference to an environment.You can change that
reference to point to another table, which becomes a new environment.
Initial chunk to environment linking is done at creation of chunk, not
at execution (that means at file loading, or function parsing). That's
the lexical scoping.
The problem with environments is that if you are in a C code that is
not called from Lua in any way, you are in no lexical scope and thus
you don't have a current environment (because no chunk is being
executed), and no access to any global variable, so you have to use
the registry to access stuff in Lua.