[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Calling C++ class methods from Lua (newbie)
- From: Rici Lake <lua@...>
- Date: Sun, 16 Oct 2005 01:30:16 -0500
On 15-Oct-05, at 5:51 PM, David Given wrote:
...actually, a thought: if I were to run Lua in an environment managed
by a
*real* garbage collector, lik the Boehm libgc, would it be worth my
while to
disable Lua's own garbage collector? If so, how?
That's an interesting question.
First of all, if I had written Lua's garbage collector, I would have
taken
offence to your use of *real*. The Lua GC is a real garbage collector,
and
quite a reasonable one. It suffers from not being integrated with a
memory
allocator, perhaps, but the consequence is that it is fully portable.
Nonetheless, one might wish to integrate Lua's memory management with
the
memory management available in some external environment. This will
prove
to be tricky, because the Lua data structures used to support its
garbage
collection are also used for other purposes. So it would be necessary
to
disentangle some of the linked lists.
Beyond that, the Lua garbage collector performs some tasks which are
quite
specific to Lua's semantics. For example, the Boehm garbage collector
does
not really have any mechanism equivalent to Lua's weak tables, or even
any
mechanism which could easily be used to implement weak tables. And,
while
the Boehm collector can implement finalization, it does not do so in a
way
consistent with Lua's (arguably idiosyncratic) semantics, which could,
in
theory, be used to change, add or delete __gc metamethods during the
life
span of an object, something not normally contemplated by finalization
mechanisms.
That's not to say that it couldn't be done, of course.