Skip to content

Commit 4a5e8ad

Browse files
Dumbeldornerzhul
authored andcommittedJun 19, 2017
C++11 cleanup on constructors (#6000)
* C++11 cleanup on constructors dir script
1 parent 4a78949 commit 4a5e8ad

40 files changed

+117
-180
lines changed
 

‎src/script/cpp_api/s_async.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ extern "C" {
3333
#include "porting.h"
3434
#include "common/c_internal.h"
3535

36-
/******************************************************************************/
37-
AsyncEngine::AsyncEngine() :
38-
initDone(false),
39-
jobIdCounter(0)
40-
{
41-
}
42-
4336
/******************************************************************************/
4437
AsyncEngine::~AsyncEngine()
4538
{

‎src/script/cpp_api/s_async.h

+10-16
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,18 @@ class AsyncEngine;
3939
// Data required to queue a job
4040
struct LuaJobInfo
4141
{
42-
LuaJobInfo() :
43-
serializedFunction(""),
44-
serializedParams(""),
45-
serializedResult(""),
46-
id(0),
47-
valid(false)
48-
{}
42+
LuaJobInfo() {};
4943

5044
// Function to be called in async environment
51-
std::string serializedFunction;
45+
std::string serializedFunction = "";
5246
// Parameter to be passed to function
53-
std::string serializedParams;
47+
std::string serializedParams = "";
5448
// Result of function call
55-
std::string serializedResult;
49+
std::string serializedResult = "";
5650
// JobID used to identify a job and match it to callback
57-
unsigned int id;
51+
unsigned int id = 0;
5852

59-
bool valid;
53+
bool valid = false;
6054
};
6155

6256
// Asynchronous working environment
@@ -68,15 +62,15 @@ class AsyncWorkerThread : public Thread, public ScriptApiBase {
6862
void *run();
6963

7064
private:
71-
AsyncEngine *jobDispatcher;
65+
AsyncEngine *jobDispatcher = nullptr;
7266
};
7367

7468
// Asynchornous thread and job management
7569
class AsyncEngine {
7670
friend class AsyncWorkerThread;
7771
typedef void (*StateInitializer)(lua_State *L, int top);
7872
public:
79-
AsyncEngine();
73+
AsyncEngine() {};
8074
~AsyncEngine();
8175

8276
/**
@@ -137,13 +131,13 @@ class AsyncEngine {
137131

138132
private:
139133
// Variable locking the engine against further modification
140-
bool initDone;
134+
bool initDone = false;
141135

142136
// Internal store for registred state initializers
143137
std::vector<StateInitializer> stateInitializers;
144138

145139
// Internal counter to create job IDs
146-
unsigned int jobIdCounter;
140+
unsigned int jobIdCounter = 0;
147141

148142
// Mutex to protect job queue
149143
std::mutex jobQueueMutex;

‎src/script/cpp_api/s_base.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ class ModNameStorer
7171
ScriptApiBase
7272
*/
7373

74-
ScriptApiBase::ScriptApiBase() :
75-
m_luastackmutex(),
76-
m_gamedef(NULL)
74+
ScriptApiBase::ScriptApiBase()
7775
{
7876
#ifdef SCRIPTAPI_LOCK_DEBUG
7977
m_lock_recursion_count = 0;
@@ -111,14 +109,6 @@ ScriptApiBase::ScriptApiBase() :
111109

112110
lua_pushstring(m_luastack, porting::getPlatformName());
113111
lua_setglobal(m_luastack, "PLATFORM");
114-
115-
// m_secure gets set to true inside
116-
// ScriptApiSecurity::initializeSecurity(), if neccessary.
117-
// Default to false otherwise
118-
m_secure = false;
119-
120-
m_environment = NULL;
121-
m_guiengine = NULL;
122112
}
123113

124114
ScriptApiBase::~ScriptApiBase()

‎src/script/cpp_api/s_base.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ScriptApiBase {
119119

120120
std::recursive_mutex m_luastackmutex;
121121
std::string m_last_run_mod;
122-
bool m_secure;
122+
bool m_secure = false;
123123
#ifdef SCRIPTAPI_LOCK_DEBUG
124124
int m_lock_recursion_count;
125125
std::thread::id m_owning_thread;
@@ -128,11 +128,11 @@ class ScriptApiBase {
128128
private:
129129
static int luaPanic(lua_State *L);
130130

131-
lua_State* m_luastack;
131+
lua_State *m_luastack = nullptr;
132132

133-
IGameDef* m_gamedef;
134-
Environment* m_environment;
135-
GUIEngine* m_guiengine;
133+
IGameDef *m_gamedef = nullptr;
134+
Environment *m_environment = nullptr;
135+
GUIEngine *m_guiengine = nullptr;
136136
};
137137

138138
#endif /* S_BASE_H_ */

‎src/script/lua_api/l_areastore.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,19 @@ int LuaAreaStore::l_from_file(lua_State *L)
300300
return deserialization_helper(L, o->as, is);
301301
}
302302

303-
LuaAreaStore::LuaAreaStore()
303+
LuaAreaStore::LuaAreaStore() : as(AreaStore::getOptimalImplementation())
304304
{
305-
this->as = AreaStore::getOptimalImplementation();
306305
}
307306

308307
LuaAreaStore::LuaAreaStore(const std::string &type)
309308
{
310309
#if USE_SPATIAL
311310
if (type == "LibSpatial") {
312-
this->as = new SpatialAreaStore();
311+
as = new SpatialAreaStore();
313312
} else
314313
#endif
315314
{
316-
this->as = new VectorAreaStore();
315+
as = new VectorAreaStore();
317316
}
318317
}
319318

‎src/script/lua_api/l_areastore.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LuaAreaStore : public ModApiBase
4949
static int l_from_file(lua_State *L);
5050

5151
public:
52-
AreaStore *as;
52+
AreaStore *as = nullptr;
5353

5454
LuaAreaStore();
5555
LuaAreaStore(const std::string &type);

‎src/script/lua_api/l_camera.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#include "content_cao.h"
55
#include "camera.h"
66

7-
LuaCamera::LuaCamera(Camera *m)
7+
LuaCamera::LuaCamera(Camera *m) : m_camera(m)
88
{
9-
m_camera = m;
109
}
1110

1211
void LuaCamera::create(lua_State *L, Camera *m)

‎src/script/lua_api/l_camera.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class LuaCamera : public ModApiBase
2626
static int l_get_look_horizontal(lua_State *L);
2727
static int l_get_aspect_ratio(lua_State *L);
2828

29-
Camera *m_camera;
29+
Camera *m_camera = nullptr;
3030

3131
public:
3232
LuaCamera(Camera *m);

‎src/script/lua_api/l_itemstackmeta.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
class ItemStackMetaRef : public MetaDataRef
2929
{
3030
private:
31-
ItemStack *istack;
31+
ItemStack *istack = nullptr;
3232

3333
static const char className[];
3434
static const luaL_Reg methods[];

‎src/script/lua_api/l_localplayer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121
#include "l_internal.h"
2222
#include "script/common/c_converter.h"
2323

24-
LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m)
24+
LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m)
2525
{
26-
m_localplayer = m;
2726
}
2827

2928
void LuaLocalPlayer::create(lua_State *L, LocalPlayer *m)

‎src/script/lua_api/l_localplayer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class LuaLocalPlayer : public ModApiBase
6767

6868
static int l_get_movement(lua_State *L);
6969

70-
LocalPlayer *m_localplayer;
70+
LocalPlayer *m_localplayer = nullptr;
7171

7272
public:
7373
LuaLocalPlayer(LocalPlayer *m);

‎src/script/lua_api/l_minimap.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include "minimap.h"
2525
#include "settings.h"
2626

27-
LuaMinimap::LuaMinimap(Minimap *m)
27+
LuaMinimap::LuaMinimap(Minimap *m) : m_minimap(m)
2828
{
29-
m_minimap = m;
3029
}
3130

3231
void LuaMinimap::create(lua_State *L, Minimap *m)

‎src/script/lua_api/l_minimap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class LuaMinimap : public ModApiBase
4848
static int l_set_shape(lua_State *L);
4949
static int l_get_shape(lua_State *L);
5050

51-
Minimap *m_minimap;
51+
Minimap *m_minimap = nullptr;
5252

5353
public:
5454
LuaMinimap(Minimap *m);

‎src/script/lua_api/l_nodemeta.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,12 @@ bool NodeMetaRef::handleFromTable(lua_State *L, int table, Metadata *_meta)
171171

172172
NodeMetaRef::NodeMetaRef(v3s16 p, ServerEnvironment *env):
173173
m_p(p),
174-
m_env(env),
175-
m_is_local(false)
174+
m_env(env)
176175
{
177176
}
178177

179178
NodeMetaRef::NodeMetaRef(Metadata *meta):
180-
m_meta(meta),
181-
m_is_local(true)
179+
m_meta(meta)
182180
{
183181
}
184182

‎src/script/lua_api/l_nodemeta.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class NodeMetadata;
3434
class NodeMetaRef : public MetaDataRef {
3535
private:
3636
v3s16 m_p;
37-
ServerEnvironment *m_env;
38-
Metadata *m_meta;
39-
bool m_is_local;
37+
ServerEnvironment *m_env = nullptr;
38+
Metadata *m_meta = nullptr;
39+
bool m_is_local = false;
4040

4141
static const char className[];
4242
static const luaL_Reg methodsServer[];

‎src/script/lua_api/l_nodetimer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class NodeTimerRef : public ModApiBase
2929
{
3030
private:
3131
v3s16 m_p;
32-
ServerEnvironment *m_env;
32+
ServerEnvironment *m_env = nullptr;
3333

3434
static const char className[];
3535
static const luaL_Reg methods[];

‎src/script/lua_api/l_object.h

+18-17
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,29 @@ class RemotePlayer;
3333
*/
3434

3535
class ObjectRef : public ModApiBase {
36-
private:
37-
ServerActiveObject *m_object;
38-
39-
static const char className[];
40-
static const luaL_Reg methods[];
4136
public:
37+
ObjectRef(ServerActiveObject *object);
38+
39+
~ObjectRef();
40+
41+
// Creates an ObjectRef and leaves it on top of stack
42+
// Not callable from Lua; all references are created on the C side.
43+
static void create(lua_State *L, ServerActiveObject *object);
44+
45+
static void set_null(lua_State *L);
46+
47+
static void Register(lua_State *L);
48+
4249
static ObjectRef *checkobject(lua_State *L, int narg);
4350

4451
static ServerActiveObject* getobject(ObjectRef *ref);
4552
private:
53+
ServerActiveObject *m_object = nullptr;
54+
55+
static const char className[];
56+
static const luaL_Reg methods[];
57+
58+
4659
static LuaEntitySAO* getluaobject(ObjectRef *ref);
4760

4861
static PlayerSAO* getplayersao(ObjectRef *ref);
@@ -319,18 +332,6 @@ class ObjectRef : public ModApiBase {
319332
// get_nametag_attributes(self)
320333
static int l_get_nametag_attributes(lua_State *L);
321334

322-
public:
323-
ObjectRef(ServerActiveObject *object);
324-
325-
~ObjectRef();
326-
327-
// Creates an ObjectRef and leaves it on top of stack
328-
// Not callable from Lua; all references are created on the C side.
329-
static void create(lua_State *L, ServerActiveObject *object);
330-
331-
static void set_null(lua_State *L);
332-
333-
static void Register(lua_State *L);
334335
};
335336

336337
#endif /* L_OBJECT_H_ */

‎src/script/lua_api/l_settings.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3232

3333
LuaSettings::LuaSettings(Settings *settings, const std::string &filename) :
3434
m_settings(settings),
35-
m_filename(filename),
36-
m_is_own_settings(false),
37-
m_write_allowed(true)
35+
m_filename(filename)
3836
{
3937
}
4038

‎src/script/lua_api/l_settings.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class LuaSettings : public ModApiBase
5757
// to_table(self) -> {[key1]=value1,...}
5858
static int l_to_table(lua_State *L);
5959

60-
Settings *m_settings;
60+
Settings *m_settings = nullptr;
6161
std::string m_filename;
62-
bool m_is_own_settings;
63-
bool m_write_allowed;
62+
bool m_is_own_settings = false;
63+
bool m_write_allowed = true;
6464

6565
public:
6666
LuaSettings(Settings *settings, const std::string &filename);

‎src/script/lua_api/l_storage.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ModApiStorage : public ModApiBase
3838
class StorageRef : public MetaDataRef
3939
{
4040
private:
41-
ModMetadata *m_object;
41+
ModMetadata *m_object = nullptr;
4242

4343
static const char className[];
4444
static const luaL_Reg methods[];

‎src/script/lua_api/l_vmanip.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -365,22 +365,17 @@ int LuaVoxelManip::l_get_emerged_area(lua_State *L)
365365
return 2;
366366
}
367367

368-
LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm)
368+
LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) : vm(mmvm), is_mapgen_vm(is_mg_vm)
369369
{
370-
this->vm = mmvm;
371-
this->is_mapgen_vm = is_mg_vm;
372370
}
373371

374-
LuaVoxelManip::LuaVoxelManip(Map *map)
372+
LuaVoxelManip::LuaVoxelManip(Map *map) : vm(new MMVManip(map))
375373
{
376-
this->vm = new MMVManip(map);
377-
this->is_mapgen_vm = false;
378374
}
379375

380376
LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2)
381377
{
382-
this->vm = new MMVManip(map);
383-
this->is_mapgen_vm = false;
378+
vm = new MMVManip(map);
384379

385380
v3s16 bp1 = getNodeBlockPos(p1);
386381
v3s16 bp2 = getNodeBlockPos(p2);

0 commit comments

Comments
 (0)
Please sign in to comment.