Pass int64

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Pass int64

Valery-8
Hello,

I have a class that gets __int64 as a parameter in the constructor. I am
trying to create it from lua, but get the error "FAIL: Test: no constructor
of 'RawData' matched the arguments (number)
 candidates are:
RawData(custom [__int64])"

Could anybody help?

.cpp
class RawData {
 public: RawData(__int64) {}
};
luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData")
 .def(luabind::constructor<__int64>())

.lua
x=RawData(10)

Thanks,
Valery.


------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Tom McCubbin-2
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.

luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData" )
    .def( luabind::constructor<int>() ); //...

That or derive and add a new signature for int.


On Tue, 2009-05-26 at 14:32 +0300, Valery wrote:
Hello,

I have a class that gets __int64 as a parameter in the constructor. I am 
trying to create it from lua, but get the error "FAIL: Test: no constructor 
of 'RawData' matched the arguments (number)
 candidates are:
RawData(custom [__int64])"

Could anybody help?

.cpp
class RawData {
 public: RawData(__int64) {}
};
luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData")
 .def(luabind::constructor<__int64>())

.lua
x=RawData(10)

Thanks,
Valery. 


------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Valery-8

Tom, Thanks,
 
Yes, your variant works. But what should I do if my class has get method like:
__int64 getSize();
 
.cpp
luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData" )
    .def( luabind::constructor<int>() )
    .def("getSize", &RawData::getSize)
 
.lua
RawData(10):getSize()
 
I get "you are trying to use an unregistered type".
 
I tryed something like the next, but I cannot use 'type'.
luabind::class_< __int64 > ("Int64")
 
Thanks,
Valery.
 
----- Original Message -----
Sent: Tuesday, May 26, 2009 3:51 PM
Subject: Re: [luabind] Pass int64

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.

luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData" )
    .def( luabind::constructor<int>() ); //...

That or derive and add a new signature for int.


On Tue, 2009-05-26 at 14:32 +0300, Valery wrote:
Hello,

I have a class that gets __int64 as a parameter in the constructor. I am 
trying to create it from lua, but get the error "FAIL: Test: no constructor 
of 'RawData' matched the arguments (number)
 candidates are:
RawData(custom [__int64])"

Could anybody help?

.cpp
class RawData {
 public: RawData(__int64) {}
};
luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData")
 .def(luabind::constructor<__int64>())

.lua
x=RawData(10)

Thanks,
Valery. 


------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com


_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Tom McCubbin-2
Hmmm....that's ugly.  Honestly, since lua uses ptrdiff_t for its integer type, depending on platform you may have data loss.  If you are on a 64 bit version of windows ( I assume windows as __int64 is a MS thing...and not ANSI, and not on linux, unix ) you should be ok.

However, it means you need to derive from the class RawData and overload the members to call the parent and use a variadic return type...something like:

class MyRawData : public RawData
{
   typedef RawData    parent;

MyRawData( ptrdiff_t v ) : parent(v) { }
//..
ptrdiff_t getSize() { return this->parent::getSize(); }

};

I'm sure there is a better/slicker way to achieve it, but this would be the long typed, least thought out approach ;)

-tom

On Tue, 2009-05-26 at 16:51 +0300, Valery wrote:

Tom, Thanks,
 
Yes, your variant works. But what should I do if my class has get method like:
__int64 getSize();
 
.cpp
luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData" )
    .def( luabind::constructor<int>() )
    .def("getSize", &RawData::getSize)
 
.lua
RawData(10):getSize()
 
I get "you are trying to use an unregistered type".
 
I tryed something like the next, but I cannot use 'type'.
luabind::class_< __int64 > ("Int64")
 
Thanks,
Valery.
 
----- Original Message -----
From: [hidden email]
To: [hidden email]
Sent: Tuesday, May 26, 2009 3:51 PM
Subject: Re: [luabind] Pass int64


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.

luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData" )
    .def( luabind::constructor<int>() ); //...

That or derive and add a new signature for int.


On Tue, 2009-05-26 at 14:32 +0300, Valery wrote:
Hello,

I have a class that gets __int64 as a parameter in the constructor. I am 
trying to create it from lua, but get the error "FAIL: Test: no constructor 
of 'RawData' matched the arguments (number)
 candidates are:
RawData(custom [__int64])"

Could anybody help?

.cpp
class RawData {
 public: RawData(__int64) {}
};
luabind::class_<RawData, boost::shared_ptr<RawData> >("RawData")
 .def(luabind::constructor<__int64>())

.lua
x=RawData(10)

Thanks,
Valery. 


------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com




_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
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 asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

James Porter-2
> I'm sure there is a better/slicker way to achieve it, but this would be the
> long typed, least thought out approach

Depending on the particulars, an easy way to address this would be to
recompile Lua with LUA_INTEGER #defined to __int64 in luaconf.h

- Jim

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Tom McCubbin-2
I really like that! 

Just make sure any binary modules are also recompiled w/ the new luaconf.h settings!

(you dog...I should have said that ;) )  nice

On Tue, 2009-05-26 at 14:53 -0500, James Porter wrote:
> I'm sure there is a better/slicker way to achieve it, but this would be the
> long typed, least thought out approach

Depending on the particulars, an easy way to address this would be to
recompile Lua with LUA_INTEGER #defined to __int64 in luaconf.h

- Jim

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Nikolas Bowe
Done correctly that is the best solution. Itll allow you to do arithmetic on 64 bit integers in lua.
Though there is a bit more to it than that.
lua_Number will need to be able to hold int64 values without loss.
which means youll need to either go with int64 as lua_Number (ie integer only lua)
or long double as lua_Number (non portable. no guarantee it can represent all 64 bit ints. eg http://msdn.microsoft.com/en-us/library/9cx8xs15.aspx).
or use askos lnum patch against lua and use int64 integers and leave non integers as doubles (my fave).

If you are really only ever pushing in "small" int64s (ie ones that are representable as ints)
Then you might be better off writing wrapper functions and registering those.
(and praying that you never really need the full int64 range)

On the other hand if you dont need to do calculations and cant/wont change lua to support int64 then there is another option:
On one of our platforms we work with an API that takes and returns 64 bit numbers.
We dont need to perform calculations on them, we just need to use them as opaque values.
So we added a luabind converter that wraps the 64 bit value in a user data.
works for us. downside is that it creates garbage any time we push 64 bit numbers into lua. but we dont do it often.


Cheers
Niki Bowe


Tom McCubbin wrote:
I really like that! 

Just make sure any binary modules are also recompiled w/ the new luaconf.h settings!

(you dog...I should have said that ;) )  nice

On Tue, 2009-05-26 at 14:53 -0500, James Porter wrote:
> I'm sure there is a better/slicker way to achieve it, but this would be the
> long typed, least thought out approach

Depending on the particulars, an easy way to address this would be to
recompile Lua with LUA_INTEGER #defined to __int64 in luaconf.h

- Jim

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
    

------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Valery-8

Thanks to all.
 
I think I do not need full LAU support for int64.
 
2Niki:
>>On one of our platforms we work with an API that takes and returns 64 bit numbers.
 
Could you provide the example of using that? I think that is exactly what I need.
 
Regards,
Valery
 
----- Original Message -----
Sent: Wednesday, May 27, 2009 7:28 AM
Subject: Re: [luabind] Pass int64

Done correctly that is the best solution. Itll allow you to do arithmetic on 64 bit integers in lua.
Though there is a bit more to it than that.
lua_Number will need to be able to hold int64 values without loss.
which means youll need to either go with int64 as lua_Number (ie integer only lua)
or long double as lua_Number (non portable. no guarantee it can represent all 64 bit ints. eg http://msdn.microsoft.com/en-us/library/9cx8xs15.aspx).
or use askos lnum patch against lua and use int64 integers and leave non integers as doubles (my fave).

If you are really only ever pushing in "small" int64s (ie ones that are representable as ints)
Then you might be better off writing wrapper functions and registering those.
(and praying that you never really need the full int64 range)

On the other hand if you dont need to do calculations and cant/wont change lua to support int64 then there is another option:
On one of our platforms we work with an API that takes and returns 64 bit numbers.
We dont need to perform calculations on them, we just need to use them as opaque values.
So we added a luabind converter that wraps the 64 bit value in a user data.
works for us. downside is that it creates garbage any time we push 64 bit numbers into lua. but we dont do it often.


Cheers
Niki Bowe


Tom McCubbin wrote:
I really like that! 

Just make sure any binary modules are also recompiled w/ the new luaconf.h settings!

(you dog...I should have said that ;) )  nice

On Tue, 2009-05-26 at 14:53 -0500, James Porter wrote:
> I'm sure there is a better/slicker way to achieve it, but this would be the
> long typed, least thought out approach

Depending on the particulars, an easy way to address this would be to
recompile Lua with LUA_INTEGER #defined to __int64 in luaconf.h

- Jim

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
    

------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Daniel Wallin
In reply to this post by Tom McCubbin-2
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.

--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Nikolas Bowe
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

James Porter-2
In reply to this post by Nikolas Bowe
Niki Bowe wrote:
> Done correctly that is the best solution. Itll allow you to do
> arithmetic on 64 bit integers in lua.
> Though there is a bit more to it than that.
> lua_Number will need to be able to hold int64 values without loss.
> which means youll need to either go with int64 as lua_Number (ie integer
> only lua)
> or long double as lua_Number (non portable. no guarantee it can
> represent all 64 bit ints.

Are you sure about this? Because that would imply that Lua 5.1 doesn't
work properly when compiled for a 64-bit platform since, by default,
LUA_INTEGER is #defined to ptrdiff_t. That seems like something the Lua
developers would have considered, but maybe not...

- Jim


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Nikolas Bowe

James Porter wrote:
Niki Bowe wrte:
  
Done correctly that is the best solution. Itll allow you to do 
arithmetic on 64 bit integers in lua.
Though there is a bit more to it than that.
lua_Number will need to be able to hold int64 values without loss.
which means youll need to either go with int64 as lua_Number (ie integer 
only lua)
or long double as lua_Number (non portable. no guarantee it can 
represent all 64 bit ints.
    

Are you sure about this? Because that would imply that Lua 5.1 doesn't 
work properly when compiled for a 64-bit platform since, by default, 
LUA_INTEGER is #defined to ptrdiff_t. That seems like something the Lua 
developers would have considered, but maybe not...

- Jim
  
Lua certainly works on 64 bit platforms.
It just doesnt do what you might expect. depending on what you expect.

The problem here is that lua_Number (by default) is set to double.
and internally lua values are represented by the following union
/*
** Union of all Lua values
*/
typedef union {
  GCObject *gc;
  void *p;
  lua_Number n;
  int b;
} Value;


Internally when you push an integer it casts it to lua_Number. (see the code for lua_pushinteger).
So if you want to be able to represent any 64 bit integer in lua you will have to do one of the things I suggested in a previous email.


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Valery-8
Hello,
 
2 Daniel Wallin:
Thanks for your sample. I am using LUA with 32 bit integers. Using your version of default_converter<int64>, I may read values as int64 in my cpp functions. Yes, this sample does not fully support __int64, but the sample is really useful for me.
 
2 Niki Bowe:
Thanks for your sample. This seems fully support __int64. I merged it with Daniel's sample (I use new luabind version) and the result worked for me.
But how to check that metatable is correct? I know this does not relates to luabind, but could you please provide a sample?
 
Thanks,
Valery.
 
----- Original Message -----
Sent: Monday, June 01, 2009 5:33 AM
Subject: Re: [luabind] Pass int64


James Porter wrote:
Niki Bowe wrte:
  
Done correctly that is the best solution. Itll allow you to do 
arithmetic on 64 bit integers in lua.
Though there is a bit more to it than that.
lua_Number will need to be able to hold int64 values without loss.
which means youll need to either go with int64 as lua_Number (ie integer 
only lua)
or long double as lua_Number (non portable. no guarantee it can 
represent all 64 bit ints.
    

Are you sure about this? Because that would imply that Lua 5.1 doesn't 
work properly when compiled for a 64-bit platform since, by default, 
LUA_INTEGER is #defined to ptrdiff_t. That seems like something the Lua 
developers would have considered, but maybe not...

- Jim
  
Lua certainly works on 64 bit platforms.
It just doesnt do what you might expect. depending on what you expect.

The problem here is that lua_Number (by default) is set to double.
and internally lua values are represented by the following union
/*
** Union of all Lua values
*/
typedef union {
  GCObject *gc;
  void *p;
  lua_Number n;
  int b;
} Value;


Internally when you push an integer it casts it to lua_Number. (see the code for lua_pushinteger).
So if you want to be able to represent any 64 bit integer in lua you will have to do one of the things I suggested in a previous email.


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Pass int64

Nikolas Bowe
Theres a few ways you can check it. if you dont need to resolve overloads you can just check if its a udata and leave it at that.
but if someone ever passes a different udata type (say another luabind object) then itll crash without much helpful information.
To be safer Id say to stash my metatable in the registry under a known fixed key and compare it against that.

I tried registering __int64 as a luabind::class_ and it didnt work.
but the alternative (and probably what Id do If we did this again) would be to make a light wrapper class and use that.
Its easier to work with than the converter method.
eg if you have register a function that takes __int64 params or returns them then you need to have your converter #included or you get the "tried to use an unregistered type" error at runtime.



Valery wrote:
Hello,
 
2 Daniel Wallin:
Thanks for your sample. I am using LUA with 32 bit integers. Using your version of default_converter<int64>, I may read values as int64 in my cpp functions. Yes, this sample does not fully support __int64, but the sample is really useful for me.
 
2 Niki Bowe:
Thanks for your sample. This seems fully support __int64. I merged it with Daniel's sample (I use new luabind version) and the result worked for me.
But how to check that metatable is correct? I know this does not relates to luabind, but could you please provide a sample?
 
Thanks,
Valery.
 
----- Original Message -----
Sent: Monday, June 01, 2009 5:33 AM
Subject: Re: [luabind] Pass int64


James Porter wrote:
Niki Bowe wrte:
  
Done correctly that is the best solution. Itll allow you to do 
arithmetic on 64 bit integers in lua.
Though there is a bit more to it than that.
lua_Number will need to be able to hold int64 values without loss.
which means youll need to either go with int64 as lua_Number (ie integer 
only lua)
or long double as lua_Number (non portable. no guarantee it can 
represent all 64 bit ints.
    

Are you sure about this? Because that would imply that Lua 5.1 doesn't 
work properly when compiled for a 64-bit platform since, by default, 
LUA_INTEGER is #defined to ptrdiff_t. That seems like something the Lua 
developers would have considered, but maybe not...

- Jim
  
Lua certainly works on 64 bit platforms.
It just doesnt do what you might expect. depending on what you expect.

The problem here is that lua_Number (by default) is set to double.
and internally lua values are represented by the following union
/*
** Union of all Lua values
*/
typedef union {
  GCObject *gc;
  void *p;
  lua_Number n;
  int b;
} Value;


Internally when you push an integer it casts it to lua_Number. (see the code for lua_pushinteger).
So if you want to be able to represent any 64 bit integer in lua you will have to do one of the things I suggested in a previous email.


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get

_______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user