Skip to content

Commit

Permalink
Use luabind::functor instead of object call and cast.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Dec 13, 2015
1 parent beb3312 commit c08c870
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
37 changes: 10 additions & 27 deletions src/xrServerEntities/object_item_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
#include "pch_script.h"
#include "object_item_script.h"
#include "object_factory.h"
#include "xrScriptEngine/Functor.hpp"

#ifndef NO_XR_GAME
# include "attachable_item.h"

ObjectFactory::CLIENT_BASE_CLASS *CObjectItemScript::client_object () const
{
using namespace luabind::policy;
ObjectFactory::CLIENT_SCRIPT_BASE_CLASS *object;
ObjectFactory::CLIENT_SCRIPT_BASE_CLASS *object = nullptr;
try {
object = luabind::object_cast<ObjectFactory::CLIENT_SCRIPT_BASE_CLASS*>(m_client_creator(), adopt<0>());
object = m_client_creator();
}
catch(...) {
return (0);
Expand All @@ -31,39 +31,22 @@ ObjectFactory::CLIENT_BASE_CLASS *CObjectItemScript::client_object () const

ObjectFactory::SERVER_BASE_CLASS *CObjectItemScript::server_object (LPCSTR section) const
{
using namespace luabind::policy;
typedef ObjectFactory::SERVER_SCRIPT_BASE_CLASS SERVER_SCRIPT_BASE_CLASS;
typedef ObjectFactory::SERVER_BASE_CLASS SERVER_BASE_CLASS;
SERVER_SCRIPT_BASE_CLASS *object;
ObjectFactory::SERVER_BASE_CLASS *object = nullptr;

try {
// XXX nitrocaster: why not call m_server_creator(section) with adopt policy?
luabind::object *instance = 0;
try {
instance = xr_new<luabind::object>((luabind::object)(m_server_creator(section)));
}
catch(std::exception e) {
Msg ("Exception [%s] raised while creating server object from section [%s]", e.what(),section);
return (0);
}
catch(...) {
Msg ("Exception raised while creating server object from section [%s]",section);
return (0);
}
object = luabind::object_cast<ObjectFactory::SERVER_SCRIPT_BASE_CLASS*>(*instance, adopt<0>());
xr_delete (instance);
object = m_server_creator(section);
}
catch(std::exception e) {
Msg ("Exception [%s] raised while casting and adopting script server object from section [%s]", e.what(),section);
return (0);
Msg ("Exception [%s] raised while creating server object from section [%s]", e.what(),section);
return (0);
}
catch(...) {
Msg ("Exception raised while creating script server object from section [%s]", section);
return (0);
Msg ("Exception raised while creating server object from section [%s]",section);
return (0);
}

R_ASSERT (object);
SERVER_BASE_CLASS *o = object->init();
ObjectFactory::SERVER_BASE_CLASS *o = object->init();
R_ASSERT (o);
return (o);
}
Expand Down
5 changes: 3 additions & 2 deletions src/xrServerEntities/object_item_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

#include "object_factory_space.h"
#include "object_item_abstract.h"
#include "xrScriptEngine/Functor.hpp"

class CObjectItemScript : public CObjectItemAbstract {
protected:
typedef CObjectItemAbstract inherited;

protected:
mutable luabind::object m_client_creator;
mutable luabind::object m_server_creator;
mutable luabind::functor<ObjectFactory::CLIENT_BASE_CLASS *, luabind::policy::adopt<0>> m_client_creator;
mutable luabind::functor<ObjectFactory::SERVER_BASE_CLASS *, luabind::policy::adopt<0>> m_server_creator;

public:
CObjectItemScript (
Expand Down

0 comments on commit c08c870

Please sign in to comment.