lua-users home
lua-l archive

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


I'm still trying to find a suitable solution to my previous questions in
"Q: Lua 5.2 thread environments..." thread.

Q: Essentially how to force Lua application & library functions to
inherit the environment of the thread or caller (not the environment of
where it was defined).
Ideally I need this to work in 5.1 and 5.2.

One reply from Tony Finch suggested:
> It sounds to me that you would be better off using an OO style, defining
> methods that act on a context object. Each thread is associated with a
> particular object. This will save you the effort of re-creating all the
> closures when spawning a thread, at the cost of an extra argument in each
> function call.

I just don't see it. The C layer creates the client context (object),
but the call-backs (the methods that act on the context) are defined in
the Lua master state at start-up; I would have to attach all those
methods to each new context (add to the fact that call-backs are
optional, so I had to attach the call backs conditionally). Also I still
do not see how "app. library" and other supporting functions defined in
the master state inherit thread or caller environment with the OO
suggestion. Those supporting functions may have nothing directly to do
with the object, they just want the client context info. And as third
parties would be writing scripts, I can't know what to attach to the
context object.

Essentially the thread IS the object (as I see it) and any members or
methods added to the thread instance should be inherited by all the
functions (methods) from its super class (the master state).

In 5.1 I can almost get this to work partially with environments, while
in 5.2 alpha documentation, section 8.1 "Threads do not have individual
environments. All threads share a single fixed environment." - which
seems to destroy the idea of the thread being an object / sub-class of
the master state.

-- 
Anthony C Howe            Skype: SirWumpus                  SnertSoft
                        Twitter: SirWumpus      BarricadeMX & Milters
http://snert.com/      http://nanozen.info/     http://snertsoft.com/