[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.1 / 5.2 threads
- From: Peter Cawley <lua@...>
- Date: Wed, 27 Apr 2011 17:32:53 +0100
On Wed, Apr 27, 2011 at 5:27 PM, Jim Whitehead II <email@example.com> wrote:
> On Wed, Apr 27, 2011 at 4:28 PM, Anthony Howe <firstname.lastname@example.org> wrote:
>> On 27/04/2011 16:57, Peter Cawley whispered from the shadows...:
>>> On Wed, Apr 27, 2011 at 3:53 PM, Anthony Howe <email@example.com> wrote:
>>>> In Lua 5.1 a thread has an environment and section 2.8 starts with
>>>> "Every value in Lua can have a metatable." So a thread can also have a
>>>> metatable in addition to an environment?
>>> If you continue reading 2.8, then you find the following:
>>> "Tables and full userdata have individual metatables (although
>>> multiple tables and userdata can share their metatables). Values of
>>> all other types share one single metatable per type; that is, there is
>>> one single metatable for all numbers, one for all strings, etc."
>> Yes. I had seen that but didn't think to apply it to a complex type like
>> a thread.
>>> So every thread can have a metatable, but the granularity for setting
>>> metatables on threads is such that if one thread has a metatable, then
>>> all threads have that metatable. As far as I'm aware, this hasn't
>>> changed between 5.1 and 5.2.
>> What about the master state (returned by luaL_newstate()) from which a
>> thread is derived? For the purpose of this question do they have the
>> same type and status a threads? or are they treated differently?
>> So if I change the metatable of a master state then all future
>> lua_State, master or thread, will share the same metatable?
> I'm not sure I understand your question. What would "changing the
> metatable" of the master state mean? The master state isn't a Lua
> value, so metatables don't really apply in the same way they do to
> other values.
The master state can be made into a Lua value by lua_pushthread (or
coroutine.running() in 5.2). For the purpose of this question, they
have the same type; a single metatable is shared between everything
which you can turn into a lua_State*.