Problems with custom converter

Szymon Gatner <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Hi,

recently I am having very rough time with code using luabind so I
finally decided to ask here.

In my code I have a class like this, color.h:

struct Color3b
{
  const static Color3b White;
  const static Color3b Black;

  Color3b() {}

  Color3b(Byte r_, Byte g_, Byte b_) : r(r_), g(g_), b(b_) {}

  Byte r, g, b;
};

then in some cpp file:

namespace luabind
{
  template <>
  struct default_converter<Color3b> : native_converter_base<Color3b>
  {
    static int compute_score(lua_State* L, int index)
    {
      return lua_type(L, index) == LUA_TTABLE ? 0 : -1;
    }

    Color3b from(lua_State* L, int index)
    {
      Color3b ret;

     //snip

      return ret;
    }

    void to(lua_State* L, Color3b const& color)
    {
      object obj = newtable(L);

      obj[1] = color.r;
      obj[2] = color.g;
      obj[3] = color.b;

      obj.push(L);
    }
  };

  template <>
  struct default_converter<Color3b const&>
    : default_converter<Color3b>
  {};
}

then later in same file:

Color3b color3b = luabind::object_cast<Color3b>(params["normal"]);

Problem is that this cast always results with exception "unable to
make cast". Program never enters compute_score() for provided
converter, in fact break point is marked invalid because this code
seem to be unused at all. I know that params["normal'] is a valid lua
object having needed 3 values inside
(in lua it is like: color = {1123, 123, 123}).

What is the possible reason for object_cast not to see this converter?
Why is compile-time expression object_cast<Color3b> not a compile
error if no proper converter/conversion trait is found?

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.