Skip to content

Commit c08c870

Browse files
author
nitrocaster
committed
Use luabind::functor instead of object call and cast.
1 parent beb3312 commit c08c870

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

src/xrServerEntities/object_item_script.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
#include "pch_script.h"
1010
#include "object_item_script.h"
1111
#include "object_factory.h"
12+
#include "xrScriptEngine/Functor.hpp"
1213

1314
#ifndef NO_XR_GAME
1415
# include "attachable_item.h"
1516

1617
ObjectFactory::CLIENT_BASE_CLASS *CObjectItemScript::client_object () const
1718
{
18-
using namespace luabind::policy;
19-
ObjectFactory::CLIENT_SCRIPT_BASE_CLASS *object;
19+
ObjectFactory::CLIENT_SCRIPT_BASE_CLASS *object = nullptr;
2020
try {
21-
object = luabind::object_cast<ObjectFactory::CLIENT_SCRIPT_BASE_CLASS*>(m_client_creator(), adopt<0>());
21+
object = m_client_creator();
2222
}
2323
catch(...) {
2424
return (0);
@@ -31,39 +31,22 @@ ObjectFactory::CLIENT_BASE_CLASS *CObjectItemScript::client_object () const
3131

3232
ObjectFactory::SERVER_BASE_CLASS *CObjectItemScript::server_object (LPCSTR section) const
3333
{
34-
using namespace luabind::policy;
35-
typedef ObjectFactory::SERVER_SCRIPT_BASE_CLASS SERVER_SCRIPT_BASE_CLASS;
36-
typedef ObjectFactory::SERVER_BASE_CLASS SERVER_BASE_CLASS;
37-
SERVER_SCRIPT_BASE_CLASS *object;
34+
ObjectFactory::SERVER_BASE_CLASS *object = nullptr;
3835

3936
try {
40-
// XXX nitrocaster: why not call m_server_creator(section) with adopt policy?
41-
luabind::object *instance = 0;
42-
try {
43-
instance = xr_new<luabind::object>((luabind::object)(m_server_creator(section)));
44-
}
45-
catch(std::exception e) {
46-
Msg ("Exception [%s] raised while creating server object from section [%s]", e.what(),section);
47-
return (0);
48-
}
49-
catch(...) {
50-
Msg ("Exception raised while creating server object from section [%s]",section);
51-
return (0);
52-
}
53-
object = luabind::object_cast<ObjectFactory::SERVER_SCRIPT_BASE_CLASS*>(*instance, adopt<0>());
54-
xr_delete (instance);
37+
object = m_server_creator(section);
5538
}
5639
catch(std::exception e) {
57-
Msg ("Exception [%s] raised while casting and adopting script server object from section [%s]", e.what(),section);
58-
return (0);
40+
Msg ("Exception [%s] raised while creating server object from section [%s]", e.what(),section);
41+
return (0);
5942
}
6043
catch(...) {
61-
Msg ("Exception raised while creating script server object from section [%s]", section);
62-
return (0);
44+
Msg ("Exception raised while creating server object from section [%s]",section);
45+
return (0);
6346
}
6447

6548
R_ASSERT (object);
66-
SERVER_BASE_CLASS *o = object->init();
49+
ObjectFactory::SERVER_BASE_CLASS *o = object->init();
6750
R_ASSERT (o);
6851
return (o);
6952
}

src/xrServerEntities/object_item_script.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
#include "object_factory_space.h"
1212
#include "object_item_abstract.h"
13+
#include "xrScriptEngine/Functor.hpp"
1314

1415
class CObjectItemScript : public CObjectItemAbstract {
1516
protected:
1617
typedef CObjectItemAbstract inherited;
1718

1819
protected:
19-
mutable luabind::object m_client_creator;
20-
mutable luabind::object m_server_creator;
20+
mutable luabind::functor<ObjectFactory::CLIENT_BASE_CLASS *, luabind::policy::adopt<0>> m_client_creator;
21+
mutable luabind::functor<ObjectFactory::SERVER_BASE_CLASS *, luabind::policy::adopt<0>> m_server_creator;
2122

2223
public:
2324
CObjectItemScript (

0 commit comments

Comments
 (0)