lua-users home
lua-l archive

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


Ugh. If this is the only way to do it, I'll probably add a
table of weak keys and rewrite luaL_ref/luaL_unref to use
it. Sure feels like a big hack.

If you'll accept my $0.02, the current implementation of
ref/unref seems a big hack. The ability to associate C and
script objects is an awfully important feature for an
embedded language, but the current method (indices into
the registry) seems an afterthought. At the very least, a
dedicated table should be set aside for refs, freeing the
registry for application use, and support re-added for
unlocked refs.

All IMO, of course. I realize that this probably isn't a
big deal for people who only call C code from Lua, and
rarely Lua code from C.

Jason



it would seem that the ability
to associate C and Lua objects would be an important
function that should be built into the language,

Okay, I can do this but it seems a bit like a hack.


Actually
I will probably add a table of weak keys to Lua and hide it behind
the luaL_ref/luaL_unref methods. This really does seem like something that should be built into the language -- Lua being an
embedded language and all -- and not something hacked onto the
registry table, which I thought was supposed to be reserved for
my application's use.



Diego Nehab wrote:

I just discovered that unlocked refs are no longer supported
in the work3 release. I was using them to allow C++ objects to
keep track of the table which represented them in Lua. What's
the workaround to allow this in work3?

You can  have, for instance, a  locked reference  to a  table associating
your objects userdata with the corresponding object tables. Then set the
mode of this table to  weak keys so that  when your userdata is  collected,
the whole pair is removed  automatically from the table and  associated
object table will also be collected.