lua-users home
lua-l archive

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


In my case, the objects are normally created by Lua, so GC means they have to be finalized. But they may also be created otherwise, in which case GC would not occur, but something else would then have to finalize them. I'll probably do the weak table approach. 

Sent from my new BlackBerry Z10

From: Coda Highland
Sent: Tuesday, February 12, 2013 5:17 PM
To: Lua mailing list
Reply To: Lua mailing list
Subject: Re: Userdata and luaL_ref

Yes, but this means that the Obj-C code has ownership of the object.
It seems that Marc's use case is that it's an object that's supposed
to be managed by Lua, and the C-side code needs to know how to handle
the object's destruction.

/s/ Adam

On Tue, Feb 12, 2013 at 11:32 AM, James Norton <jamesnorton@gmail.com> wrote:
> In my case (Objective C) I call luaL_unref in the dealloc method of my
> object class.
>
> --
> James Norton
> Sent with Sparrow
>
> On Tuesday, February 12, 2013 at 2:28 PM, Coda Highland wrote:
>
> That'll keep the object alive indefinitely, though.
>
> /s/ Adam
>
> On Tue, Feb 12, 2013 at 11:22 AM, James Norton <jamesnorton@gmail.com>
> wrote:
>
> I create a reference to the object in the registry using
>
> ref = luaL_ref(L, LUA_REGISTRYINDEX);
>
> Then I can retrieve it later using
>
> lua_rawgeti(L, LUA_REGISTRYINDEX,, ref);
>
> --
> James Norton
> Sent with Sparrow
>
> On Tuesday, February 12, 2013 at 1:57 PM, Marc Lepage wrote:
>
> Hi, I'm doing more with userdata and am just wondering, is it safe to push
> the address of a (full) userdata to keep a reference to it? And remove that
> reference in the userdata's __gc function?
>
> Basically, I want to store within the C userdata itself, a reference to the
> Lua object version of it. This is so that even if I pass it through C code
> (without Lua), I can later get back the Lua version of it, for additional
> processing.
>
> Or, is there a better way to turn the address of a (full) userdata, in C,
> back into its Lua object?
>
>