[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Using Lua to implement C++ methods.
- From: Ariel Manzur <listas@...>
- Date: Wed, 31 May 2006 20:47:24 -0400
On Tue, May 30, 2006 at 07:16:30PM -0600, mark gossage wrote:
[...]
> The OnClick() method which is to be implmneted in Lua is probably going to be the hard bit. Can any of the tolua for Luabind guru's out there provide any ideas on this?
There is a small example on how to add support for virtual methods with
tolua++ here:
http://lua-users.org/wiki/ImplementingVirtualMethodsWithToluapp
It's not a 'patch', so it can be used with an unmodified tolua++ binary.
You should be able to adapt any object system to use this for inheritance
from c++ objects..
> > Hello all,
> >
> > I'm new to Lua, but I think that it is an excellent scripting language
> > and would like to use it in combination with C++. I've read a good deal
> > of http://www.lua.org/pil/ ,
> > especially "Part IV. The C API", but
> > apparently due to my lack of experience with Lua, I've not been able to
> > my problem myself.
> >
> > The problem is that I have a simple hierarchy (a tree) of C++ objects,
> > as for example windows that can be found in a GUI system:
> > (For clarity, I'm just providing pseudo-code, it will probably not compile.)
> >
> > class Window
> > {
> > public:
> >
> > Window* Find(char* n); // Find a window with name "n" in the
> >
> > hierarchy tree of this window.
> >
> > void Draw(); // Draws this window on the screen -
> > implemented in C++.
> > void SomeMethod(float f); // Some helper method for demonstration
> > purposes, also implem. in C++.
> > void OnMouseClick(); // Some event handler - supposed to be
> > implemented by a Lua script!
> >
> > std::string name; // Name of this window, e.g. for
> > reference in Lua scripts.
> > int pos[2]; // The position of the top-left corner of
> > this window.
> > int size[2]; // The size of this window in pixels.
> > float back_col[3]; // The background color.
> > float text_col[3]; // The text / foreground color.
> > std::string text; // Text to be displayed in the window.
> >
> > Window* parent; // The parent of this window (may be NULL).
> > vector<Window*> children; // The sub-windows of this window (e.g.
> >
> > the buttons in a dialog).
> > };
> >
> >
>
>
Ariel.