adding new primitive types to luabind

View: New views
4 Messages — Rating Filter:   Alert me  

adding new primitive types to luabind

by Ilya Martynov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I've just started using luabind for my project and run into the following issue. C++ API I'm trying to expose to lua uses 64 bit integer type which luabind cannot use unless I specially register this type as a class. But if I register it as a class I have to convert lua numbers to this class explicitly in my lua code. Ideally I want to be able to add somehow it as a native type so that luabind would be able to resolve calls like "c_func_with_64bit_int_parameter(1234)" automatically without explicit conversion. Basically I want to be able to use this type in the same way as other numeric types which are supported by luabind natively (i.e. int and double). Is it possible at all?

--
Ilya Martynov, ilya@...
CTO IPonWEB (UK) Ltd


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: adding new primitive types to luabind

by Ilia Trendafilov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

There was a discussion on the same topic some time ago:
http://sourceforge.net/mailarchive/forum.php?thread_name=gvqije%24736%241%40ger.gmane.org&forum_name=luabind-user

On Thu, Oct 29, 2009 at 5:14 PM, Ilya Martynov <ilya@...> wrote:

> Hello,
>
> I've just started using luabind for my project and run into the following
> issue. C++ API I'm trying to expose to lua uses 64 bit integer type which
> luabind cannot use unless I specially register this type as a class. But if
> I register it as a class I have to convert lua numbers to this class
> explicitly in my lua code. Ideally I want to be able to add somehow it as a
> native type so that luabind would be able to resolve calls like
> "c_func_with_64bit_int_parameter(1234)" automatically without explicit
> conversion. Basically I want to be able to use this type in the same way as
> other numeric types which are supported by luabind natively (i.e. int and
> double). Is it possible at all?
>
> --
> Ilya Martynov, ilya@...
> CTO IPonWEB (UK) Ltd
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> luabind-user mailing list
> luabind-user@...
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: adding new primitive types to luabind

by Daniel Wallin-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ilya Martynov wrote:

> Hello,
>
> I've just started using luabind for my project and run into the following
> issue. C++ API I'm trying to expose to lua uses 64 bit integer type which
> luabind cannot use unless I specially register this type as a class. But if
> I register it as a class I have to convert lua numbers to this class
> explicitly in my lua code. Ideally I want to be able to add somehow it as a
> native type so that luabind would be able to resolve calls like
> "c_func_with_64bit_int_parameter(1234)" automatically without explicit
> conversion. Basically I want to be able to use this type in the same way as
> other numeric types which are supported by luabind natively (i.e. int and
> double). Is it possible at all?

Yes, it is possible. Please see test/test_user_defined_converter.cpp or
the "Adding converters for user defined types" section in the
documentation. It boils down to specializing
luabind::default_converter<> for your type.

--
Daniel Wallin

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: adding new primitive types to luabind

by Ilya Martynov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Tue, Nov 3, 2009 at 11:27 AM, Daniel Wallin <daniel@...> wrote:
Ilya Martynov wrote:
> Hello,
>
> I've just started using luabind for my project and run into the following
> issue. C++ API I'm trying to expose to lua uses 64 bit integer type which
> luabind cannot use unless I specially register this type as a class. But if
> I register it as a class I have to convert lua numbers to this class
> explicitly in my lua code. Ideally I want to be able to add somehow it as a
> native type so that luabind would be able to resolve calls like
> "c_func_with_64bit_int_parameter(1234)" automatically without explicit
> conversion. Basically I want to be able to use this type in the same way as
> other numeric types which are supported by luabind natively (i.e. int and
> double). Is it possible at all?

Yes, it is possible. Please see test/test_user_defined_converter.cpp or
the "Adding converters for user defined types" section in the
documentation. It boils down to specializing
luabind::default_converter<> for your type.



Aha, thanks. I initially was looking into documentation on http://www.rasterbar.com/products/luabind/docs.html but it seems to be outdated and doesn't have this section.

--
Ilya Martynov, ilya@...
CTO IPonWEB (UK) Ltd


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user