Problem when passing a pointer to call_function.

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

Problem when passing a pointer to call_function.

by Teto-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I'm facing a "assertion failed: crep && your are trying to use an
unregistered type" policy.hpp line 192" when I tried to call a Lua
function from C++. I've done many tests and the matter happens when I
try to pass "loader" as a parameter of the lua function.

================================
template<class T>
bool
AddLoader(ILoader<T>* loader,std::string extensions){
        luabind::object obj =
luabind::globals(CGameEngine::GetInstance()->mScript.mLuaState)["AddLoader"];
        if(!(obj && luabind::type(obj) == LUA_TFUNCTION)) {
            return false;
        }

        bool ok = luabind::call_function<bool>(obj,loader,extensions);
}
================================

i'm using luabind 8.* .

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: Problem when passing a pointer to call_function.

by Thomas Nelson-10 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This is just a guess based on what you've sent, but have you exported an
ILoader<> of the appropriate type to Lua?  Remember that after the template
compiler finishes there is no relation between template expansions of
different types.  

If you have two types, say:
class Foo {}

class Bar {}

You would need something along the lines of:
module(pLState)
[
    class_<ILoader<Foo> >("LoaderFoo"),
    class_<ILoader<Bar> >("LoaderBar")
];

Alternately you could:
class ILoaderBase {}
template <T> class ILoader: public ILoaderBase {}

module(pLState)
[
    class_<ILoaderBase>("Loader")
];

> -----Original Message-----
> From: Teto
>
> Hello,
>
> I'm facing a "assertion failed: crep && your are trying to use an
> unregistered type" policy.hpp line 192" when I tried to call a Lua
> function from C++. I've done many tests and the matter happens when I
> try to pass "loader" as a parameter of the lua function.
>
> ================================
> template<class T>
> bool
> AddLoader(ILoader<T>* loader,std::string extensions)
> {
>     luabind::object obj = luabind::globals(
>         CGameEngine::GetInstance()->mScript.mLuaState)["AddLoader"];
>     if(!(obj && luabind::type(obj) == LUA_TFUNCTION))
>     {
>         return false;
>     }
>
>     bool ok = luabind::call_function<bool>(obj,loader,extensions);
> }
> ================================
>
> i'm using luabind 8.* .
>

--
Thomas Nelson  tdark@...  
--------------------------------------------------------------
"If you still have gas, you're not lost".
- French explorer Pierre Frontage.
(M.Frontage was so influential in the exploration of North America many
roads are still named after him.)




------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: Problem when passing a pointer to call_function.

by Teto-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Aug 4, 2009 at 6:15 AM, Thomas Nelson <tdark@...> wrote:
>
> This is just a guess based on what you've sent, but have you exported an
> ILoader<> of the appropriate type to Lua?

I thought I did but in fact I was registering a derived type . I have
been confused by the writing. I was registering CTextureLoader instead
of registering into lua ILoader<Ctexture> and - stupidity of mine -
thought they were the same whereas I define CTextureLoader by doing:
class CTextureLoader : public ILoader<Ctexture> { ... }

 I've solved the matter thx to your advice and thought of a new design
which works.

>
>  Remember that after the template
> compiler finishes there is no relation between template expansions of
> different types.
>
> If you have two types, say:
> class Foo {}
>
> class Bar {}
>
> You would need something along the lines of:
> module(pLState)
> [
>    class_<ILoader<Foo> >("LoaderFoo"),
>    class_<ILoader<Bar> >("LoaderBar")
> ];
>
> Alternately you could:
> class ILoaderBase {}
> template <T> class ILoader: public ILoaderBase {}
>
> module(pLState)
> [
>    class_<ILoaderBase>("Loader")
> ];
>
> > -----Original Message-----
> > From: Teto
> >
> > Hello,
> >
> > I'm facing a "assertion failed: crep && your are trying to use an
> > unregistered type" policy.hpp line 192" when I tried to call a Lua
> > function from C++. I've done many tests and the matter happens when I
> > try to pass "loader" as a parameter of the lua function.
> >
> > ================================
> > template<class T>
> > bool
> > AddLoader(ILoader<T>* loader,std::string extensions)
> > {
> >     luabind::object obj = luabind::globals(
> >         CGameEngine::GetInstance()->mScript.mLuaState)["AddLoader"];
> >     if(!(obj && luabind::type(obj) == LUA_TFUNCTION))
> >     {
> >         return false;
> >     }
> >
> >     bool ok = luabind::call_function<bool>(obj,loader,extensions);
> > }
> > ================================
> >
> > i'm using luabind 8.* .
> >
>
> --
> Thomas Nelson  tdark@...
> --------------------------------------------------------------
> "If you still have gas, you're not lost".
> - French explorer Pierre Frontage.
> (M.Frontage was so influential in the exploration of North America many
> roads are still named after him.)
>
>
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user