problem on using shared_ptr

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

problem on using shared_ptr

cloudage
i have a class which uses shared_ptr: 
class Entity:public boost::enable_shared_from_this<Entity>
public:
  typedef boost::shared_ptr<Entity> Ptr;  
...
...
}
 
and i registed it like this:
 
 module(context,"sys")
  [
  class_<Entity,Entity::Ptr>("Entity")
 ...
 ...
  ];
 
and also i have a little script as: 
function ProcessUpdate(sender)
  prient("update!");
end
 
now i pass a Entity::Ptr as a parameter to a lua function: 
void Server::LuaLogic::ProcessUpdate( Entity::Ptr sender )
{
  _mutContext.lock();
  lua_State *l = _l->Lock();
  int idx=lua_gettop(l);
  
  try
  {
    luabind::object pu = luabind::globals(l)["ProcessUpdate"];
 
    if(luabind::type(pu)==LUA_TFUNCTION)
    {
     pu(sender);
    }  
  }
 catch (luabind::error* e)
 {
    const char* what = e->what();
 }
 
lua_settop(l,idx);
 
 _l->Unlock();
 _mutContext.unlock();
}
 
and after(or during) the "pu(sender);",my debuger noticed me a luabind::error,in object.hpp at line 1156,and i can`t catch it at all so i don`t understand what happend.
 
any help please?

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: problem on using shared_ptr

Nigel Atkinson-2
It's strange that you can not catch the exception.  That line (1156) is
the end of the method in the object class that does the call to lua, so
perhaps if you use your debugger to step line by line from "pu(sender)"
onwards.  Does it print "update" ? or not get that far?

That's what I would do.  Then if you have no luck, perhaps try with
ordinary raw pointers, and see what changes.

In your Lua script, do you have "print" or "prient" like you have in
your email?

Nigel

On Tue, 2010-03-02 at 16:47 +0800, [hidden email] wrote:

> i have a class which uses shared_ptr:
>         class Entity:public boost::enable_shared_from_this<Entity>
>         {
>         public:
>           typedef boost::shared_ptr<Entity> Ptr;  
>         ...
>         ...
>         }
>          
>         and i registed it like this:
>          
>          module(context,"sys")
>           [
>           class_<Entity,Entity::Ptr>("Entity")
>          ...
>          ...
>           ];
>  
> and also i have a little script as:
>         function ProcessUpdate(sender)
>           prient("update!");
>         end
>  
> now i pass a Entity::Ptr as a parameter to a lua function:
>         void Server::LuaLogic::ProcessUpdate( Entity::Ptr sender )
>         {
>           _mutContext.lock();
>           lua_State *l = _l->Lock();
>           int idx=lua_gettop(l);
>          
>           try
>           {
>             luabind::object pu = luabind::globals(l)["ProcessUpdate"];
>          
>             if(luabind::type(pu)==LUA_TFUNCTION)
>             {
>              pu(sender);
>             }  
>           }
>          catch (luabind::error* e)
>          {
>             const char* what = e->what();
>          }
>          
>         lua_settop(l,idx);
>          
>          _l->Unlock();
>          _mutContext.unlock();
>         }
>  
> and after(or during) the "pu(sender);",my debuger noticed me a
> luabind::error,in object.hpp at line 1156,and i can`t catch it at all
> so i don`t understand what happend.
>  
> any help please?
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user



------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: problem on using shared_ptr

Daniel Wallin
In reply to this post by cloudage
On Tue, Mar 02, 2010 at 04:47:33PM +0800, [hidden email] wrote:
[...]
> and also i have a little script as:
>
> function ProcessUpdate(sender)
>   prient("update!");
    ^^^^^^
This typo is the only real error I can find in your code, except for
catching the exception the wrong way.

[...]

>   try
>   {
>     luabind::object pu = luabind::globals(l)["ProcessUpdate"];
>
>     if(luabind::type(pu)==LUA_TFUNCTION)
>     {
>      pu(sender);
>     }
>   }
>  catch (luabind::error* e)

This should be:

  catch (luabind::error const& e)

>  {
>     const char* what = e->what();
>  }

and to get a useful error message after catching the exception, you need
to get it from the Lua stack:

  char const* msg = lua_tostring(L, -1);

If you change your code like that you will get a more descriptive error.

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

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user