Re: Pass int64
Niki Bowe <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Daniel Wallin wrote:
> Tom McCubbin wrote:
>
>> If the constructor is not explicit (not marked as so below), why not try
>> and change your luabind::constructor<>() to take an int, and let the
>> compiler do its 1 allowed conversion step. At runtime luabind doesn't
>> have the smarts to map a number to __int64 in looking up the constructor
>> would be my guess as to why you have the problem.
>>
>
> You can customize the native converters by providing a specialization of
> luabind::default_converter<>. See:
>
> test/test_user_defined_converter.cpp
>
> Something like:
>
> namespace luabind {
>
> template <>
> struct default_converter<__int64>
> : native_converter_base<__int64>
> {
> static int compute_score(lua_State* L, int index)
> {
> return default_converter<int>::compute_score(L, index);
> }
>
> __int64 from(lua_State* L, int index)
> {
> return (__int64)lua_tonumber(L, index);
> }
>
> void to(lua_State* L, __int64 value)
> {
> lua_pushnumber(L, value);
> }
> };
>
> } // namespace luabind
>
> Should do it.
>
>
This wont work for all possible int64s.
We are using an old version of luabind, where the converter syntax was
different
for us its something like
namespace luabind {
namespace converters {
yes_t is_user_defined(by_value<int64>);
yes_t is_user_defined(by_const_reference<int64>);
void convert_cpp_to_lua(lua_State* L, const int64& id)
{
int64* udata = (int64*)lua_newuserdata(L, sizeof(id));
*udata = id;
luaL_getmetatable(L, INT64_MT_NAME);
lua_setmetatable(L, -2);
}
int64 convert_lua_to_cpp(lua_State* L, by_value<int64>, int index)
{
int64* udata = (int64*)lua_touserdata(L, index);
return *udata;
}
int64 convert_lua_to_cpp(lua_State* L,
by_const_reference<int64>, int index)
{
return convert_lua_to_cpp(L, by_value<int64>(), index);
}
int match_lua_to_cpp(lua_State* L, by_value<int64>, int index)
{
if (lua_type(L, index) == LUA_TUSERDATA) {
// TODO check metatable is correct one
return 0;
}
return -1;
}
int match_lua_to_cpp(lua_State* L, by_const_reference<int64>,
int index)
{
return match_lua_to_cpp(L, by_value<int64>(), index);
}
}
}
given an appropriately setup metatable stored under INT64_MT_NAME.
On the other hand you probably could just register int64 as a class.
register a copy ctor (and maybe some other operators) and it should
allow you to copy values into lua, and pass the values to funcs that
take int64s.
I seem to recall we had some problem with this, but i cant recall what
it was.
something like
module(L)
[
class_<int64>("int64")
.def(constructor<int64>())
];
might work...
if so you could probably register the other operators and then be able
to work with int64s in normal lua.
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user