lua-users home
lua-l archive

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

I use that for a library called Simple Lua Binder which wrapps C++
objects to lua. To support something like:

ObjectClass.method(object, ...)

I use the same metatable for both instances, and the table that
contains the "class Info", that's why I have __gc for both tables and
objects. In the previous release of lua 5.2 (alpha) tables didn't get
called on __gc, only objects, so I used that to know when an object is
no longer used in the luaState. Right now, I have an if to check if
the __gc gets called with an object, or a table (lua 5.2 beta)

But it's just a curiosity, it didn't affect too much.

The change from environments to no environments was much more worse,
but that was a long time ago.

On Wed, Jun 15, 2011 at 11:46 PM, Luiz Henrique de Figueiredo
<> wrote:
>> 2) the last update 5.2-beta introduce a funny behavior with __gc. Now
>> you need to setup a metatable with the __gc entry before the metatable
>> is used with an user_data (or it won't be called).
> Yes, but you only need to set the index not the value. In other words,
> you're free to set __gc=true and set the actual metamethod later.
>> And also now __gc is called for tables, which didn't happen before
>> (in my code I always try to pick a user data as first argument, and
>> suddenly a table appear where user_data used to be)
> Only if you do set __gc for tables of course.

  Jose L. Hidalgo Valiño (PpluX)
  ---- ----