lua-users home
lua-l archive

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


I am trying to do something with a metatable, but it is biting me. I have setup a number of helper functions, and an error maybe present there.

Here is what I am trying to ultimately do:

table A's metatable:
setcaption
getcaption

__newindex <-- for 'caption' would call setcaption
__index <-- for 'caption' would call getcaption


This is basically a property implementation.

Everything relevant would be here:
http://www.common-lisp.net/paste/display/1444 <-- Utility.c - helper functions
http://www.common-lisp.net/paste/display/1444#1 <-- Display.m - registration functions for Display module
http://www.common-lisp.net/paste/display/1444#2 <-- TicTacToe.lua - lua code

The output when run:
Registering redraw function: function: 0x334ed0
Register redraw
Size Requested: 640, 480
Table Registering with: 2
Installing metatable
Table Registering with: 3
Installing metatable
== table output ==
setsize function: 0x3338d0
getsize function: 0x325e60
__index function: 0x3595c0
__newindex function: 0x3580a0
==================
== table output ==
-------- at this point it complains saying the metatable is null.

The table output that it is printing here is
<x-tad-bigger>print_table(</x-tad-bigger><x-tad-bigger>d</x-tad-bigger><x-tad-bigger>) on line 145 of #2. (note option at bottom to show line numbers)

But all of those entries should be in the metatable.

See line 73/74 in #1, and refer to line 118 in main paste.

In main paste:
line 142, checks for metatable, and makes one (147) and installs __index (149) and __newindex (150) handlers. Ten it sets it as the metatable for table specified (parameter:table) (156).

Line 167 retrieves metatable, and installs a 'get' function (185) for the property - in the metatable. Installs a 'set' function (191) for the property. Installs the metatable again (195) because it seems picky without it.
</x-tad-bigger>

An important function used is AssignTable (52 main paste).

A check of this code makes me think that the stack level is fine.

Any help that people could give would be appreciated. Especially if there is something I am misunderstanding here.

- Jeff


"Reportedly, he remarked to one of his Christian missionary friends: 'What you teach us to do is admirable, but what you teach us to believe is foolish'."
- Referring to King Mongkut of Siam
http://en.wikipedia.org/wiki/Mongkut

Attachment: PGP.sig
Description: This is a digitally signed message part