[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Multiple functions: was the gc
- From: David Jones <drj@...>
- Date: Tue, 22 Aug 2006 08:48:54 +0100
On 22 Aug 2006, at 02:25, D Burgess wrote:
OK, David Jones was right (thank you) and I made an incredibly
silly assumption. If I might restate the problem:
I have a number of Lua threads that each have their own environment,
I have *a* function which will execute in each of the threads,
I wish to set the function environment (lua_setfenv()) of the function
to the thread environment.
How do I do this without doing a lua_load() for *each* thread?
Is there anyway (from C) having initially loaded the function to
create a separate closure for each thread?
I was going to spend some more time looking at this, but I see you've
made some progress before I found the time.
If the function you want to execute _is_ the entire script loaded by
lua_load then you can't do what you want. You must use lua_load to
get a fresh instance of the function (this is a small drawback in Lua
However, I think wrapping your scripts should work:
-- original script goes here
Then, you can lua_load the script once and lua_call it each time you
want a fresh function instance. That'll be dead fast.
If you don't want to edit all your scripts, you should be able to use
a custom loader to add the "return function(...)" prefix and the
David Jones wrote:
> Isn't this explained by there only being one function that is
> by all your threads?