lua-users home
lua-l archive

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

I've been playing with tolua 4.0a. In general, it does just as great a
job as tolua 3.2, but one change broke our project. In a way it is our
fault, because it relied on the undocumented data structures that
tolua exposed to lua. Nevertheless, I think that some information in
the data structures was genuinely useful, and I would like to suggest
an addition to the tolua API to expose the equivalent of that information.

We need specifically the information that the .tolua_itag table
provided: given the name of a class, what is the tag of its instance?
In our case, constructing a dummy instance of the class and finding
out via the tag() function is not an option. Alternatively, given the
tag of a class, returning the tag of the corresponding instance would
also work.

So, ideally I would like to see something like this:

tolua.instance_tag(classname) --> returns tag of instance or nil if
classname is not known to tolua.


tolua.instance_tag(classtag) --> returns tag of instance or nil if
classtag is not known to tolua.

Comments anyone?

(The rest of this message is quite technical - feel free to skip)

The reason why we need this information is that we have some objects
that act as proxies for others. Consider something like:

class A {
   int do_something();

class AProxy {
   AProxy(A *instance);

In lua, we must be able to do the following:

a_inst = A:new()
a_proxy = AProxy:new(a_inst)
result = a_proxy:do_something()  --> returns a_inst:do_something()

The way this works in our project is that we set up the gettable tag
method for the AProxy class to forward to the A class. Because we have
a lot of these kinds of classes lying around, this is far easier than
writing the bindings like this:

class A {
   int do_something();

class AProxy {
   int do_something();

This is prone to errors (incorrectly copying methods from A to
AProxy). It is also very tedious to set up, since some classes have a
lot of methods and multiple classes that can act as proxies. It is
less robust to additions to our class interfaces, which still
invariably happen from time to time. Worst of all, it amounts to an
enormous increase in code size of the generated bindings.

To set up the proxy mechanism, we used to look through all
tolua-registered classes, and for the ones that could act as proxies,
we recovered its instance tag, then registered the tag method. This is
where the request for tolua.instance_tag() comes in.

- Christian