lua-users home
lua-l archive

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


Hello Carsten,

One possible and usually quite painless method is to consider a tool to do the binding for you. Luabind, tolua++ and SWIG can all produce bindings from C++ - Lua, you could try them as a comparison.
(Personally I use SWIG, but I am also the maintianer for the Lua bindings, so I am biased).

If you want to DIY, this a quite viable under Lua, you will need to use a UserData, the stuff in http://www.lua.org/pil/28.1.html is exactly where you should be looking.
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?

Hope this is a useful pointer to you.

Regards,
Mark Gossage

> 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).
> };
> 
>