lua-users home
lua-l archive

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


On Fri, Apr 8, 2011 at 5:04 PM, Anthony Howe <achowe+lua@snert.com> wrote:
> On 08/04/2011 21:16, Rob Hoelz whispered from the shadows...:
>> If you want C closures to share values, you could store a table as an
>> upvalue, store your values in there, and set the same table as an
>> upvalue for the closures.
>
> Ugh. One person says no. Another suggests the very thing I want to try
> that prompted the question.

I answered your simple question with a simple answer. If you are
unclear on a workaround or methodology, perhaps you should have asked
a different question?

> In 5.1 does...
>
>        lua_newtable(L);
>        lua_pushvalue(L, -1);
>        lua_pushcclosure(L, &foobar, 1);
>        lua_pushcclosure(L, &barblat, 1);
>
>        -- rinse & repeat
>
> Work?

Yes. In both versions.

> Can more than one C function share a single upvalue?

No. But two C functions can have two different upvalues that have the
*same value*.

-- 
- Patrick Donnelly