lua-users home
lua-l archive

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


On Wed, Apr 27, 2011 at 4:28 PM, Anthony Howe <achowe+lua@snert.com> wrote:
> On 27/04/2011 16:57, Peter Cawley whispered from the shadows...:
>> On Wed, Apr 27, 2011 at 3:53 PM, Anthony Howe <achowe+lua@snert.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.

If you change the metatable for all coroutines in a given state, then
all coroutines in that state will indeed share the same metatable. If
your question is something other than that, it's not entirely clear to
me.

- Jim