register pririty queue

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

register pririty queue

boldt
I'm using luabind 0.7 with vs 2003
I have the following definition:

#ifndef CORE_ENGINESTRUCT_HPP
#define CORE_ENGINESTRUCT_HPP

#include <queue>
#include <vector>
#include <luabind/object.hpp>

namespace Core {

        class Task {
        public:
                Task( float awakeTime_ , const luabind::object& coroutine_ ) :
mAwakeTime(awakeTime_) , mTask( corotine_ ){}
                ///the time that the task must be awaken at
                float mAwakeTime;
                ///the task, should be a lua coroutine
                luabind::object mTask;
        };

        struct TaskComparer {
                bool operator()( const Task& l_ , const Task& r_ ) const{
                        return l_.mAwakeTime < r_.mAwakeTime;
                }
        };
       

        ///should this be threadsafe
        typedef std::priority_queue< Task , std::vector<Task> , TaskComparer
> TaskQueue;


}

#endif


I try to register using luabind with

                luabind::module( state )[
                        luabind::class_<Core::Task>("Task")
                                .def( luabind::constructor<float,const luabind::object&>() )
                                .def_readonly("mAwakeTime" , &Core::Task::mAwakeTime )
                                .def_readonly("mCoroutine" , &Core::Task::mTask )
                ];

                luabind::module( state )[
                        luabind::class_<Core::TaskQueue>("TaskQueue")
                                .def( luabind::constructor<>() )
                                .def( "Push" , &Core::TaskQueue::push )
                                .def( "Pop" , &Core::TaskQueue::pop )
                                .def( "Empty" , &Core::TaskQueue::empty )
                                .def( "Top" , &Core::TaskQueue::top )
                ];

This almost goes fine, except for the last line ".def( "Top" ,
&Core::TaskQueue::top )
" which gives comiler errors like the following. I do not understand
whats the difference between top and the other functions. When I
remove the last line evrything compiles fine!

f:\projects\3diku\trunk\scripting\register.cpp(123): error C2780:
'luabind::class_<T> &luabind::class_<T>::def(const char
*,F,Default,const Policies &)' : expects 4 arguments - 2 provided
        with
        [
            T=Core::TaskQueue
        ]
f:\projects\3diku\trunk\scripting\register.cpp(123): error C2780:
'luabind::class_<T> &luabind::class_<T>::def(const char
*,F,DefaultOrPolicies)' : expects 3 arguments - 2 provided
        with
        [
            T=Core::TaskQueue
        ]
f:\projects\3diku\trunk\scripting\register.cpp(123): error C2780:
'luabind::class_<T>
&luabind::class_<T>::def(luabind::constructor<A0,A1,A2,A3,A4,A5,A6,A7,A8,A9>)'
: expects 1 arguments - 2 provided
        with
        [
            T=Core::TaskQueue
        ]
f:\projects\3diku\trunk\scripting\register.cpp(123): error C2780:
'luabind::class_<T>
&luabind::class_<T>::def(luabind::detail::operator_<Derived>)' :
expects 1 arguments - 2 provided
        with
        [
            T=Core::TaskQueue
        ]
f:\projects\3diku\trunk\scripting\register.cpp(123): error C2784:
'luabind::class_<T> &luabind::class_<T>::def(const char *,F)' : could
not deduce template argument for 'overloaded function type' from
'overloaded function type'
        with
        [
            T=Core::TaskQueue
        ]
f:\projects\3diku\trunk\scripting\register.cpp(123): error C2784:
'luabind::class_<T>
&luabind::class_<T>::def(luabind::constructor<A0,A1,A2,A3,A4,A5,A6,A7,A8,A9>,const
Policies &)' : could not deduce template argument for
'luabind::constructor<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>' from 'const
char [4]'
        with
        [
            T=Core::TaskQueue
        ]
f:\projects\3diku\trunk\scripting\register.cpp(123): error C2784:
'luabind::class_<T>
&luabind::class_<T>::def(luabind::detail::operator_<Derived>,const
Policies &)' : could not deduce template argument for
'luabind::detail::operator_<T1>' from 'const char [4]'
        with
        [
            T=Core::TaskQueue
        ]
f:\projects\3diku\trunk\scripting\register.cpp(123): error C2914:
'luabind::class_<T>::def' : cannot deduce template argument as
function argument is ambiguous
        with
        [
            T=Core::TaskQueue
        ]

Thanks, Niels


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: register pririty queue

Arvid Norberg-2

On May 2, 2006, at 00:15, Niels Boldt wrote:

> I'm using luabind 0.7 with vs 2003
> I have the following definition:
>
> #ifndef CORE_ENGINESTRUCT_HPP
> #define CORE_ENGINESTRUCT_HPP
>
> #include <queue>
> #include <vector>
> #include <luabind/object.hpp>
>
> namespace Core {
>
> class Task {
> public:
> Task( float awakeTime_ , const luabind::object& coroutine_ ) :
> mAwakeTime(awakeTime_) , mTask( corotine_ ){}
> ///the time that the task must be awaken at
> float mAwakeTime;
> ///the task, should be a lua coroutine
> luabind::object mTask;
> };
>
> struct TaskComparer {
> bool operator()( const Task& l_ , const Task& r_ ) const{
> return l_.mAwakeTime < r_.mAwakeTime;
> }
> };
>
>
> ///should this be threadsafe
> typedef std::priority_queue< Task , std::vector<Task> , TaskComparer
>> TaskQueue;
>
>
> }
>
> #endif
>
>
> I try to register using luabind with
>
> luabind::module( state )[
> luabind::class_<Core::Task>("Task")
> .def( luabind::constructor<float,const luabind::object&>() )
> .def_readonly("mAwakeTime" , &Core::Task::mAwakeTime )
> .def_readonly("mCoroutine" , &Core::Task::mTask )
> ];
>
> luabind::module( state )[
> luabind::class_<Core::TaskQueue>("TaskQueue")
> .def( luabind::constructor<>() )
> .def( "Push" , &Core::TaskQueue::push )
> .def( "Pop" , &Core::TaskQueue::pop )
> .def( "Empty" , &Core::TaskQueue::empty )
> .def( "Top" , &Core::TaskQueue::top )
> ];
>
> This almost goes fine, except for the last line ".def( "Top" ,
> &Core::TaskQueue::top )
> " which gives comiler errors like the following. I do not understand
> whats the difference between top and the other functions. When I
> remove the last line evrything compiles fine!

It looks like TaskQueue::top may be an overloaded function. If it is,  
you have to cast it to the function pointer type that has the  
signature of the overload you want to register.

If that's not it, you could make sure that LUABIND_MAX_ARITY is high  
enough (if the number of arguments of top is more than the default  
value you have to redefine it to a higher value).


--
Arvid Norberg




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Register with adopt policy

Josh Green-3
Hi everyone,

I know this is a rather noob question but! Here it is:

I'm trying to register function with luabind telling it that C++ will
adopt one of the parameters it is sending across.
The function I'm registering looks like this:

Event *scheduleEvent(long,Action*,bool);

The "Action*" is the one that will be adopted (nothing else is to be
adopted)

My registration looks like:

def("scheduleEvent",&scheduleEvent,adopy(_1))

I am getting errors that look
like:--------------------------------------------------------


luabind\detail\call.hpp(160) : error C2039: 'apply' : is not a member of
'luabind::detail::adopt_policy<N>::only_accepts_nonconst_pointers'
        with
        [
            N=2
        ]
luabind\adopt_policy.hpp(127) : see declaration of
'luabind::detail::adopt_policy<N>::only_accepts_nonconst_pointers'
        with
        [
            N=2
        ]
luabind\detail\call.hpp(407) : see reference to function template
instantiation 'int
luabind::detail::returns<T>::call<Scene,WrappedClass,Policies,A0,A1,A2>(
T (__thiscall Scene::* )(A0,A1,A2),WrappedClass *,lua_State *,const
Policies *)' being compiled
        with
        [
            T=IEvent *,
            WrappedClass=Scene,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>,
            A0=long,
            A1=Action *,
            A2=bool
        ]
luabind\class.hpp(208) : see reference to function template
instantiation 'int
luabind::detail::call<Scene,Class,Policies,IEvent*,long,Action*,bool>(R
(__thiscall Scene::* )(A0,A1,A2),WrappedClass *,lua_State *,const
Policies *)' being compiled
        with
        [
            Class=Scene,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>,
            R=IEvent *,
            A0=long,
            A1=Action *,
            A2=bool,
            WrappedClass=Scene
        ]
luabind\class.hpp(207) : while compiling class-template member function
'int luabind::detail::mem_fn_callback<Fn,Class,Policies>::operator
()(lua_State *) const'
        with
        [
            Fn=IEvent *(__thiscall Scene::* )(long,Action *,bool),
            Class=Scene,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>
        ]
luabind\class.hpp(1218) : see reference to class template instantiation
'luabind::detail::mem_fn_callback<Fn,Class,Policies>' being compiled
        with
        [
            Fn=IEvent *(__thiscall Scene::* )(long,Action *,bool),
            Class=Scene,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>
        ]
luabind\class.hpp(875) : see reference to function template
instantiation 'luabind::class_<T>
&luabind::class_<T>::virtual_def<F,DefaultOrPolicies>(const char *,const
F & ,const Policies &,luabind::detail::null_type,boost::mpl::true_)'
being compiled
        with
        [
            T=Scene,
            F=IEvent *(__thiscall Scene::* )(long,Action *,bool),
 
DefaultOrPolicies=luabind::detail::policy_cons<luabind::detail::adopt_po
licy<2>,luabind::detail::null_type>,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>
        ]
Scripting\Links\links - scenes.cpp(25) : see reference to function
template instantiation 'luabind::class_<T>
&luabind::class_<T>::def<IEvent*(__thiscall Scene::* )(long,Action
*,bool),luabind::detail::policy_cons<H,luabind::detail::null_type>>(cons
t char *,F,DefaultOrPolicies)' being compiled
        with
        [
            T=Scene,
            H=luabind::detail::adopt_policy<2>,
            F=IEvent *(__thiscall Scene::* )(long,Action *,bool),
 
DefaultOrPolicies=luabind::detail::policy_cons<luabind::detail::adopt_po
licy<2>,luabind::detail::null_type>
        ]
luabind\detail\call.hpp(163) : error C2039: 'converter_postcall' : is
not a member of
'luabind::detail::adopt_policy<N>::only_accepts_nonconst_pointers'
        with
        [
            N=2
        ]
luabind\adopt_policy.hpp(127) : see declaration of
'luabind::detail::adopt_policy<N>::only_accepts_nonconst_pointers'
        with
        [
            N=2
        ]

---------------------------------END Error
Listing------------------------------------------

From this it seems it wants some member to be a const pointer.... Now, I
can't make the Action* into const Action* because changes are made to
the Action object, would I need to change this to: Action const * ?

I'm at a loss here, This is using luabind 0.6 I believe too (is there a
version function I can use to retrieve the version of luabind?)

Thanks for your time

--Josh


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

RE: Register with adopt policy

Josh Green-3
Hey everyone, managed to figure it out..

I needed to use: Adopt(_3)
Perhaps we should have something in the doco saying you need to take
into account the class pointer as parameter "1" and that the parameters
are indexed starting at 1.

But, I've run into another related problem.

With the function I mentioned before. I am doing the following:

action = ScriptAction();
scheduleEvent(5000,action,false);

And luabind comes back complaining that the arguments supplied were:
Number, <Action>, boolean

And the candidates are:
Number, Action*,boolean

How can I get luabind to convert to the pointer version itself? I
thought it did that automatically?
Thanks

--Josh

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Josh
Green
Sent: Tuesday, 2 May 2006 10:25 PM
To: [hidden email]
Subject: [luabind] Register with adopt policy


Hi everyone,

I know this is a rather noob question but! Here it is:

I'm trying to register function with luabind telling it that C++ will
adopt one of the parameters it is sending across. The function I'm
registering looks like this:

Event *scheduleEvent(long,Action*,bool);

The "Action*" is the one that will be adopted (nothing else is to be
adopted)

My registration looks like:

def("scheduleEvent",&scheduleEvent,adopy(_1))

I am getting errors that look
like:--------------------------------------------------------


luabind\detail\call.hpp(160) : error C2039: 'apply' : is not a member of
'luabind::detail::adopt_policy<N>::only_accepts_nonconst_pointers'
        with
        [
            N=2
        ]
luabind\adopt_policy.hpp(127) : see declaration of
'luabind::detail::adopt_policy<N>::only_accepts_nonconst_pointers'
        with
        [
            N=2
        ]
luabind\detail\call.hpp(407) : see reference to function template
instantiation 'int
luabind::detail::returns<T>::call<Scene,WrappedClass,Policies,A0,A1,A2>(
T (__thiscall Scene::* )(A0,A1,A2),WrappedClass *,lua_State *,const
Policies *)' being compiled
        with
        [
            T=IEvent *,
            WrappedClass=Scene,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>,
            A0=long,
            A1=Action *,
            A2=bool
        ]
luabind\class.hpp(208) : see reference to function template
instantiation 'int
luabind::detail::call<Scene,Class,Policies,IEvent*,long,Action*,bool>(R
(__thiscall Scene::* )(A0,A1,A2),WrappedClass *,lua_State *,const
Policies *)' being compiled
        with
        [
            Class=Scene,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>,
            R=IEvent *,
            A0=long,
            A1=Action *,
            A2=bool,
            WrappedClass=Scene
        ]
luabind\class.hpp(207) : while compiling class-template member function
'int luabind::detail::mem_fn_callback<Fn,Class,Policies>::operator
()(lua_State *) const'
        with
        [
            Fn=IEvent *(__thiscall Scene::* )(long,Action *,bool),
            Class=Scene,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>
        ]
luabind\class.hpp(1218) : see reference to class template instantiation
'luabind::detail::mem_fn_callback<Fn,Class,Policies>' being compiled
        with
        [
            Fn=IEvent *(__thiscall Scene::* )(long,Action *,bool),
            Class=Scene,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>
        ]
luabind\class.hpp(875) : see reference to function template
instantiation 'luabind::class_<T>
&luabind::class_<T>::virtual_def<F,DefaultOrPolicies>(const char *,const
F & ,const Policies &,luabind::detail::null_type,boost::mpl::true_)'
being compiled
        with
        [
            T=Scene,
            F=IEvent *(__thiscall Scene::* )(long,Action *,bool),
 
DefaultOrPolicies=luabind::detail::policy_cons<luabind::detail::adopt_po
licy<2>,luabind::detail::null_type>,
 
Policies=luabind::detail::policy_cons<luabind::detail::adopt_policy<2>,l
uabind::detail::null_type>
        ]
Scripting\Links\links - scenes.cpp(25) : see reference to function
template instantiation 'luabind::class_<T>
&luabind::class_<T>::def<IEvent*(__thiscall Scene::* )(long,Action
*,bool),luabind::detail::policy_cons<H,luabind::detail::null_type>>(cons
t char *,F,DefaultOrPolicies)' being compiled
        with
        [
            T=Scene,
            H=luabind::detail::adopt_policy<2>,
            F=IEvent *(__thiscall Scene::* )(long,Action *,bool),
 
DefaultOrPolicies=luabind::detail::policy_cons<luabind::detail::adopt_po
licy<2>,luabind::detail::null_type>
        ]
luabind\detail\call.hpp(163) : error C2039: 'converter_postcall' : is
not a member of
'luabind::detail::adopt_policy<N>::only_accepts_nonconst_pointers'
        with
        [
            N=2
        ]
luabind\adopt_policy.hpp(127) : see declaration of
'luabind::detail::adopt_policy<N>::only_accepts_nonconst_pointers'
        with
        [
            N=2
        ]

---------------------------------END Error
Listing------------------------------------------

From this it seems it wants some member to be a const pointer.... Now, I
can't make the Action* into const Action* because changes are made to
the Action object, would I need to change this to: Action const * ?

I'm at a loss here, This is using luabind 0.6 I believe too (is there a
version function I can use to retrieve the version of luabind?)

Thanks for your time

--Josh


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services,
security? Get stuff done quickly with pre-integrated technology to make
your job easier Download IBM WebSphere Application Server v.1.0.1 based
on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user