3

I'm trying to expose two classes to Lua using LuaBridge. These classes are Sprite and Texture that look something like this:

class Texture
{
public:
    Texture(const std::string& filename);
    ...
}

class Sprite
{
public:
    Sprite(Texture& texture);
    ...
}

Now, I try to bind these to Lua like this:

lua_State* L = ...;
luabridge::getGlobalNamespace(L)
    .beginClass<Texture>("Texture") // No ctor exposed, just the class
    .endClass()
    .beginClass<Sprite>("Sprite")
    .addConstructor<void(*)(Texture&)>() // This causes the error
    .endClass();

However, this produces the following compile error:

C2664: cannot convert argument 1 from 'const Texture' to 'Texture &'

Why do I get this error and how can I fix it?

manabreak
  • 5,415
  • 7
  • 39
  • 96
  • this is probably just a side effect of the metaprogramming in LuaBridge. You could either try LuaBind as an alternative, or change your constructor to use a `Texture const&` and make a copy, or write small wrappers that would be passed wrapped in `RefCountedPtr`s for lifetime management – Dmitry Ledentsov Dec 10 '14 at 13:25
  • @DmitryLedentsov For now, I've used `RefCountedPtr` to bypass this problem. It works "for now", but I'd like to find out why the parameter has to be `const` as well. :) – manabreak Dec 10 '14 at 14:22

0 Answers0