Luabind: Passing C++ objects

Started by
13 comments, last by dw9 15 years, 1 month ago
I've found my problem. GetId was returning a unsigned long long. Aparently I can't do that. I Really want it to be unsigned long long, and I can fit my design in order to not need to call the unsigned long long functions inside lua. Or I could make those unsigned long long on simple unsigned integers (long long was just to be shure [lol]).

But,is there a way to use unsigned long long integer with lua?


Thank you for you help.
Advertisement
isn't unsigned long long a 64 bit unsigned value? Hmm perhaps wrapping it in a struct called something say big_num_64 and just binding that with Luabind? Alittle trouble but then u can return big_num_64 from Lua without any problems.

Good Luck!

-ddn
Quote:Original post by ddn3
isn't unsigned long long a 64 bit unsigned value? Hmm perhaps wrapping it in a struct called something say big_num_64 and just binding that with Luabind? Alittle trouble but then u can return big_num_64 from Lua without any problems.

Good Luck!

-ddn


Sure, i think I could do that. But I still will be unable to get those values from inside lua, like print it on the the screen with print, or do some calculation. Maybe this solve part of the problem, if there is no other solution, I think I could live with it.

And yes, it is a 64 bits unsigned value (A very big number).
You can provide meta methods for the object to allow you to print, add, sub, div etc it like a number (but only against its own type I think).

see:

http://www.lua.org/pil/13.html

-ddn
Quote:Original post by Escarab
I've found my problem. GetId was returning a unsigned long long. Aparently I can't do that. I Really want it to be unsigned long long, and I can fit my design in order to not need to call the unsigned long long functions inside lua. Or I could make those unsigned long long on simple unsigned integers (long long was just to be shure [lol]).

But,is there a way to use unsigned long long integer with lua?


Lua stores all numbers as double. Unless your integers are too big to be stored as double, you can specialize luabind::default_converter<> for unsigned long long. Something like this should work:
namespace luabind {template <>struct default_converter<unsigned long long>  : native_converter_base<unsigned long long>{    static int compute_score(lua_State* L, int index)    {        return lua_type(L, index) == LUA_TNUMBER ? 0 : -1;    }    unsigned long long from(lua_State* L, int index)    {        return static_cast<unsigned long long>(lua_tonumber(L, index));    }    void to(lua_State* L, unsigned long long value)    {        lua_pushnumber(L, static_cast<lua_Number>(value));    }};template <>struct default_converter<unsigned long long const>  : default_converter<unsigned long long>{};template <>struct default_converter<unsigned long long const&>  : default_converter<unsigned long long>{};} // namespace luabind

This topic is closed to new replies.

Advertisement