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")
b:setSize(64,64)
console:println("Border resized")
b:setPos(window:width()/2-32, window:height()/2-32)
console:println("Border moved")
hud:add(b)
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 {
public:
GUI(int width, int height);
void draw();
void add(Widget *w);
// tolua_end
private:
int m_width;
int m_height;
Game &m_game;
Container m_root;
}; // tolua_export
Border:
// tolua_begin
class Border : public Widget {
public:
Border();
virtual void draw();
void setCol(const Vector3f &col) { m_col = col; }
// tolua_end
protected:
Vector3f m_col;
}; // tolua_export
EDIT: probably best if I show Widget as well:
// tolua_begin
class Widget {
public:
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
protected:
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:
hud:add(tolua.cast(b,"Widget"))
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]