lua-users home
lua-l archive

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


Jonas Spiegel wrote:

At First, hi.
I'm new in this mailist, and i allready searched in the archived but i found nothing!
I want to call a funktion of a class, which was created in C++
But toLua, luabind and so can only created classes in LUA. But i can't get access to my classes which i defined in C++.
Is where a way to get access and call a C++ funktion of a class in Lua?
Here as example:
class foo
{
public:
    void call(void);
};
foo XY; now in Lua:
XY:call();
Is somewhere a way to do this?

At the moment I am doing this without toLua or other utilities:

For each C++ object which is visible on the Lua side I create
a Lua table, which contains a light userdata pointer to the
C++ object. To the table I also attach a metatable, with __index entry.

The __index then accesses C++ functions which I have registered
to the Lua side, and which use the actual C++ methods, like "call()"
in your example.

The Lua table is sort of extra package (directly using userdata pointer
might be enough), but it allows me to add additional data fields to
the object in the Lua side, and I like that.

As the metatable and the registered access functions are shared for
all objects of the specific class, they don't cause extra per object
penalty.

		Eero