• Advertisement
Sign in to follow this  

Lua issue (toLua++) [solved]

This topic is 3810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

EDIT: Sorry, false alarm! Turns out I'm not too good at keeping track of what is initialised when. Turns out 'hud' was newed after it was bound to Lua =( .. Fixed now. I'm having a problem with a Lua script:
console:println("Loading Border..")
b = Border:new()
console:println("Border made")
console:println("Border resized")
b:setPos(window:width()/2-32, window:height()/2-32)
console:println("Border moved")
console:println("Border added")

It gets up to "Border moved", so there's probably something wrong with hud:add(b). Here are the c++ class defs (hud is an instance of GUI): GUI:
// tolua_begin
class GUI {
    GUI(int width, int height);
    void draw();
    void add(Widget *w);
// tolua_end
    int m_width;
    int m_height;
    Game &m_game;
    Container m_root;
}; // tolua_export

// tolua_begin
class Border : public Widget {
    virtual void draw();
    void setCol(const Vector3f &col) { m_col = col; }
// tolua_end
    Vector3f m_col;
}; // tolua_export

EDIT: probably best if I show Widget as well:
// tolua_begin
class Widget {
    virtual ~Widget() {}
    virtual void draw() = 0;

    virtual void setSize(int w, int h) { m_size.x = w; m_size.y = h; }
    virtual void setSize(const Vector2f &size) { m_size = size; }
    virtual Vector2i &getSize() { return m_size; }

    virtual void setPos(int x, int y) { m_pos.x = x; m_pos.y = y; }
    virtual void setPos(const Vector2i &pos) { m_pos = pos; }
    virtual Vector2i &getPos() { return m_pos; }

    Vector2i getAbsPos() {
        if (m_parent)
            return m_pos + m_parent->getAbsPos();
        return m_pos;

    void setParent(Widget *parent){ m_parent = parent; }
// tolua_end
    Game &m_game;
    Vector2i m_pos;
    Vector2i m_size;
    Widget *m_parent;
}; // tolua_export

I guess this has something to do with me making a Border and GUI::add() requires a Widget, although from my understanding, this should have worked. I've also tried:

But that didn't help. I'm new to Lua so I'm not sure how to approach this, and I don't know how to read whatever error lua may have pushed. Thanks. =) [Edited by - DeathCarrot on September 19, 2007 4:49:01 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement