lua-users home
lua-l archive

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


I'm basically in the same situation. I'm only interested in being able to access and deal with my custom C++ class instances from a lua script.
 
Currently I have been exploring LuaPlus, which is a very clean template library that makes embedding Lua pretty much a snap, almost too easy. However, I am still scratching my head as to how I am able to return objects to Lua and enable the Lua script to work with them. 

________________________________

From: lua-bounces@bazar2.conectiva.com.br on behalf of Ando Sonenblick
Sent: Sat 7/26/2003 5:37 PM
To: lua@bazar2.conectiva.com.br
Subject: Lua oop?


Gang,

I'm developing an animation engine that will have user level scripting implemented in lua (I'll be embedding lua into my c++ app).  I'm perusing tons of websites, reading up on the lua.org documentation and so on to learn lua, how to embed it, extend it, etc..  

One thing I am not finding any real info on is any object oriented programming aspects of lua.   As of now, I'm not needing inheritance, encapsulation, etc.  Well, instead of saying what I don't need, why don't I simply say what I do need, and hopefully someone can tell me if it'll be possible:

In my C++ code I have, say, a widget class:

class Widget
{
    long    aValue;

public:

    void    SetValue(long v) { aValue = v; };
    long    GetValue(void) { return aValue; };

};

Now, I want to make this object available for manipulation in a lua script.  So say the script is something like this:

function main(widget)            -- I need first to be able to pass things to a function (but I believe that the stack calls allow this easily enuf)

    widget:SetValue(10);         -- important to get the ":" operator to bind an object reference to a method
    print(widget:GetValue());   -- displays 10

end

So, that's my initial prime objective: having lua access my C/C++ objects in a clean OOP syntactic way.    I've seen some things like tolua and other C++ wrappers, but I'm looking for info on how they do what they do, not just getting a tool to do it.

So, can anyone give me some pointers here?

Thanks much,
Ando
-----------------
SpriTec Software
www.spritec.com


<<winmail.dat>>