[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.1 upvalues
- From: Anthony Howe <achowe+lua@...>
- Date: Sat, 09 Apr 2011 09:19:39 +0200
On 09/04/2011 00:59, Robert G. Jakabosky whispered from the shadows...:
> That code should be:
>
> lua_newtable(L);
> lua_pushvalue(L, -1);
> lua_pushcclosure(L, &foobar, 1);
> lua_pushvalue(L, -2);
> lua_pushcclosure(L, &barblat, 1);
> lua_remove(L, -3);
Ok. Thanks.
> Like others have said they can shared the same value, but not the same 'local'
> storage of that value. As long as you don't try to store a new value in the
> upvalue of one C closure and expect the other C closure to see the new value.
I was thinking along those lines, but the above example works too.
The upvalue solution should work for C functions called by Lua that need
a context. I presume that upvalues/C closures are tied the Lua thread state?
> Lua closures can share the same 'local' storage for an upvalue:
> local shared_storage = 123
Q: When loading a Lua script into a master state, do Lua threads a) get
a copy of local variables, b) get their own version of those local
variables (copy by value, not by reference) such that two threads can
have a variable by the same name, but assign different values?
--
Anthony C Howe Skype: SirWumpus SnertSoft
Twitter: SirWumpus BarricadeMX & Milters
http://snert.com/ http://nanozen.info/ http://snertsoft.com/