[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: AW: questions about Simple Cpp Binding
- From: Robert Kücken <robert.kuecken@...>
- Date: Mon, 4 Aug 2003 19:51:48 +0200
-----Ursprüngliche Nachricht-----
Von: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]Im Auftrag von Peter Shook
Gesendet: Montag, 4. August 2003 16:37
An: Lua list
Betreff: Re: questions about Simple Cpp Binding
Hi Robert,
The first table is the table of methods, then luaL_newmetatable creates
another table that is the metatable and puts it in the Lua Registry.
The end result is something like:
Lua Registry = {
...
Account = {
__metatable = <the method table>
__index = <the method table>
__gc = <the C function LuaAccount::gc_account>
}
...
}
<the method table> = {
deposit = <the C function LuaAccount::deposit>
withdraw = <the C function LuaAccount::withdraw>
balance = <the C function LuaAccount::balance>
}
It's okay to drop the tables off the stack once the structure is built
because they are rooted in the Registry. Some of the later examples
also add the method table to the globals so that you can add methods
written in a Lua script.
The __metatable field is returned by getmetatable in Lua scripts.
It isn't necessary. The __index field is the important one.
See http://lua-users.org/lists/lua-l/2003-07/msg00103.html and the
associated thread.
- Peter
Thanks very much, now I understand it. Good to have the mailing list. ;-)
bye
robert