lua-users home
lua-l archive

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


Anthony Howe <achowe+lua@snert.com> wrote:
>
> I have a related problem with function environments in 5.1. How to get
> function environments to inherit the environment of the caller and NOT
> that of where it was defined.

Your problems with 5.1 and 5.2 are basically the same. The non-locals that
a function has access to are determined when the closure is created, and
are not related to the call chain.

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.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Forth, Tyne, Dogger: West or southwest 7 to severe gale 9 backing south or
southwest 4 or 5, increasing 6 or 7 later. Moderate or rough. Rain or showers.
Good, occasionally poor.