diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/cpp_api/s_async.cpp | 7 | ||||
-rw-r--r-- | src/script/cpp_api/s_async.h | 26 | ||||
-rw-r--r-- | src/script/cpp_api/s_base.cpp | 12 | ||||
-rw-r--r-- | src/script/cpp_api/s_base.h | 10 | ||||
-rw-r--r-- | src/script/lua_api/l_areastore.cpp | 7 | ||||
-rw-r--r-- | src/script/lua_api/l_areastore.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_camera.cpp | 3 | ||||
-rw-r--r-- | src/script/lua_api/l_camera.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_itemstackmeta.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_localplayer.cpp | 3 | ||||
-rw-r--r-- | src/script/lua_api/l_localplayer.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_minimap.cpp | 3 | ||||
-rw-r--r-- | src/script/lua_api/l_minimap.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_nodemeta.cpp | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_nodemeta.h | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_nodetimer.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_object.h | 35 | ||||
-rw-r--r-- | src/script/lua_api/l_settings.cpp | 4 | ||||
-rw-r--r-- | src/script/lua_api/l_settings.h | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_storage.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.cpp | 11 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.h | 4 |
22 files changed, 61 insertions, 96 deletions
diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 722359066..5cca5fc03 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -34,13 +34,6 @@ extern "C" { #include "common/c_internal.h" /******************************************************************************/ -AsyncEngine::AsyncEngine() : - initDone(false), - jobIdCounter(0) -{ -} - -/******************************************************************************/ AsyncEngine::~AsyncEngine() { diff --git a/src/script/cpp_api/s_async.h b/src/script/cpp_api/s_async.h index 45f935d0a..94b55db6e 100644 --- a/src/script/cpp_api/s_async.h +++ b/src/script/cpp_api/s_async.h @@ -39,24 +39,18 @@ class AsyncEngine; // Data required to queue a job struct LuaJobInfo { - LuaJobInfo() : - serializedFunction(""), - serializedParams(""), - serializedResult(""), - id(0), - valid(false) - {} + LuaJobInfo() {}; // Function to be called in async environment - std::string serializedFunction; + std::string serializedFunction = ""; // Parameter to be passed to function - std::string serializedParams; + std::string serializedParams = ""; // Result of function call - std::string serializedResult; + std::string serializedResult = ""; // JobID used to identify a job and match it to callback - unsigned int id; + unsigned int id = 0; - bool valid; + bool valid = false; }; // Asynchronous working environment @@ -68,7 +62,7 @@ public: void *run(); private: - AsyncEngine *jobDispatcher; + AsyncEngine *jobDispatcher = nullptr; }; // Asynchornous thread and job management @@ -76,7 +70,7 @@ class AsyncEngine { friend class AsyncWorkerThread; typedef void (*StateInitializer)(lua_State *L, int top); public: - AsyncEngine(); + AsyncEngine() {}; ~AsyncEngine(); /** @@ -137,13 +131,13 @@ protected: private: // Variable locking the engine against further modification - bool initDone; + bool initDone = false; // Internal store for registred state initializers std::vector<StateInitializer> stateInitializers; // Internal counter to create job IDs - unsigned int jobIdCounter; + unsigned int jobIdCounter = 0; // Mutex to protect job queue std::mutex jobQueueMutex; diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 4d7461c5b..aaf26a9c3 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -71,9 +71,7 @@ public: ScriptApiBase */ -ScriptApiBase::ScriptApiBase() : - m_luastackmutex(), - m_gamedef(NULL) +ScriptApiBase::ScriptApiBase() { #ifdef SCRIPTAPI_LOCK_DEBUG m_lock_recursion_count = 0; @@ -111,14 +109,6 @@ ScriptApiBase::ScriptApiBase() : lua_pushstring(m_luastack, porting::getPlatformName()); lua_setglobal(m_luastack, "PLATFORM"); - - // m_secure gets set to true inside - // ScriptApiSecurity::initializeSecurity(), if neccessary. - // Default to false otherwise - m_secure = false; - - m_environment = NULL; - m_guiengine = NULL; } ScriptApiBase::~ScriptApiBase() diff --git a/src/script/cpp_api/s_base.h b/src/script/cpp_api/s_base.h index ed056db31..38ee9901b 100644 --- a/src/script/cpp_api/s_base.h +++ b/src/script/cpp_api/s_base.h @@ -119,7 +119,7 @@ protected: std::recursive_mutex m_luastackmutex; std::string m_last_run_mod; - bool m_secure; + bool m_secure = false; #ifdef SCRIPTAPI_LOCK_DEBUG int m_lock_recursion_count; std::thread::id m_owning_thread; @@ -128,11 +128,11 @@ protected: private: static int luaPanic(lua_State *L); - lua_State* m_luastack; + lua_State *m_luastack = nullptr; - IGameDef* m_gamedef; - Environment* m_environment; - GUIEngine* m_guiengine; + IGameDef *m_gamedef = nullptr; + Environment *m_environment = nullptr; + GUIEngine *m_guiengine = nullptr; }; #endif /* S_BASE_H_ */ diff --git a/src/script/lua_api/l_areastore.cpp b/src/script/lua_api/l_areastore.cpp index b81985a7f..1e30e704e 100644 --- a/src/script/lua_api/l_areastore.cpp +++ b/src/script/lua_api/l_areastore.cpp @@ -300,20 +300,19 @@ int LuaAreaStore::l_from_file(lua_State *L) return deserialization_helper(L, o->as, is); } -LuaAreaStore::LuaAreaStore() +LuaAreaStore::LuaAreaStore() : as(AreaStore::getOptimalImplementation()) { - this->as = AreaStore::getOptimalImplementation(); } LuaAreaStore::LuaAreaStore(const std::string &type) { #if USE_SPATIAL if (type == "LibSpatial") { - this->as = new SpatialAreaStore(); + as = new SpatialAreaStore(); } else #endif { - this->as = new VectorAreaStore(); + as = new VectorAreaStore(); } } diff --git a/src/script/lua_api/l_areastore.h b/src/script/lua_api/l_areastore.h index 8292e7712..9cb6249d0 100644 --- a/src/script/lua_api/l_areastore.h +++ b/src/script/lua_api/l_areastore.h @@ -49,7 +49,7 @@ private: static int l_from_file(lua_State *L); public: - AreaStore *as; + AreaStore *as = nullptr; LuaAreaStore(); LuaAreaStore(const std::string &type); diff --git a/src/script/lua_api/l_camera.cpp b/src/script/lua_api/l_camera.cpp index 862384198..ef842a222 100644 --- a/src/script/lua_api/l_camera.cpp +++ b/src/script/lua_api/l_camera.cpp @@ -4,9 +4,8 @@ #include "content_cao.h" #include "camera.h" -LuaCamera::LuaCamera(Camera *m) +LuaCamera::LuaCamera(Camera *m) : m_camera(m) { - m_camera = m; } void LuaCamera::create(lua_State *L, Camera *m) diff --git a/src/script/lua_api/l_camera.h b/src/script/lua_api/l_camera.h index 04921ad03..c4a0f877c 100644 --- a/src/script/lua_api/l_camera.h +++ b/src/script/lua_api/l_camera.h @@ -26,7 +26,7 @@ private: static int l_get_look_horizontal(lua_State *L); static int l_get_aspect_ratio(lua_State *L); - Camera *m_camera; + Camera *m_camera = nullptr; public: LuaCamera(Camera *m); diff --git a/src/script/lua_api/l_itemstackmeta.h b/src/script/lua_api/l_itemstackmeta.h index 4ef64a91e..6e841d2dc 100644 --- a/src/script/lua_api/l_itemstackmeta.h +++ b/src/script/lua_api/l_itemstackmeta.h @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class ItemStackMetaRef : public MetaDataRef { private: - ItemStack *istack; + ItemStack *istack = nullptr; static const char className[]; static const luaL_Reg methods[]; diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index 7ec4eaa62..7f932cbca 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -21,9 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "l_internal.h" #include "script/common/c_converter.h" -LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) +LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m) { - m_localplayer = m; } void LuaLocalPlayer::create(lua_State *L, LocalPlayer *m) diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h index e56ec808f..e618e6be5 100644 --- a/src/script/lua_api/l_localplayer.h +++ b/src/script/lua_api/l_localplayer.h @@ -67,7 +67,7 @@ private: static int l_get_movement(lua_State *L); - LocalPlayer *m_localplayer; + LocalPlayer *m_localplayer = nullptr; public: LuaLocalPlayer(LocalPlayer *m); diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index afb3766fb..be981c884 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -24,9 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "minimap.h" #include "settings.h" -LuaMinimap::LuaMinimap(Minimap *m) +LuaMinimap::LuaMinimap(Minimap *m) : m_minimap(m) { - m_minimap = m; } void LuaMinimap::create(lua_State *L, Minimap *m) diff --git a/src/script/lua_api/l_minimap.h b/src/script/lua_api/l_minimap.h index ba702b0b1..d4fbf6330 100644 --- a/src/script/lua_api/l_minimap.h +++ b/src/script/lua_api/l_minimap.h @@ -48,7 +48,7 @@ private: static int l_set_shape(lua_State *L); static int l_get_shape(lua_State *L); - Minimap *m_minimap; + Minimap *m_minimap = nullptr; public: LuaMinimap(Minimap *m); diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 5dfa6d52e..aa8d1c453 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -171,14 +171,12 @@ bool NodeMetaRef::handleFromTable(lua_State *L, int table, Metadata *_meta) NodeMetaRef::NodeMetaRef(v3s16 p, ServerEnvironment *env): m_p(p), - m_env(env), - m_is_local(false) + m_env(env) { } NodeMetaRef::NodeMetaRef(Metadata *meta): - m_meta(meta), - m_is_local(true) + m_meta(meta) { } diff --git a/src/script/lua_api/l_nodemeta.h b/src/script/lua_api/l_nodemeta.h index dd4260ff9..72d26ef36 100644 --- a/src/script/lua_api/l_nodemeta.h +++ b/src/script/lua_api/l_nodemeta.h @@ -34,9 +34,9 @@ class NodeMetadata; class NodeMetaRef : public MetaDataRef { private: v3s16 m_p; - ServerEnvironment *m_env; - Metadata *m_meta; - bool m_is_local; + ServerEnvironment *m_env = nullptr; + Metadata *m_meta = nullptr; + bool m_is_local = false; static const char className[]; static const luaL_Reg methodsServer[]; diff --git a/src/script/lua_api/l_nodetimer.h b/src/script/lua_api/l_nodetimer.h index ae362d8b3..df77ed98f 100644 --- a/src/script/lua_api/l_nodetimer.h +++ b/src/script/lua_api/l_nodetimer.h @@ -29,7 +29,7 @@ class NodeTimerRef : public ModApiBase { private: v3s16 m_p; - ServerEnvironment *m_env; + ServerEnvironment *m_env = nullptr; static const char className[]; static const luaL_Reg methods[]; diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index 9801ce02b..77874f00c 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -33,16 +33,29 @@ class RemotePlayer; */ class ObjectRef : public ModApiBase { -private: - ServerActiveObject *m_object; - - static const char className[]; - static const luaL_Reg methods[]; public: + ObjectRef(ServerActiveObject *object); + + ~ObjectRef(); + + // Creates an ObjectRef and leaves it on top of stack + // Not callable from Lua; all references are created on the C side. + static void create(lua_State *L, ServerActiveObject *object); + + static void set_null(lua_State *L); + + static void Register(lua_State *L); + static ObjectRef *checkobject(lua_State *L, int narg); static ServerActiveObject* getobject(ObjectRef *ref); private: + ServerActiveObject *m_object = nullptr; + + static const char className[]; + static const luaL_Reg methods[]; + + static LuaEntitySAO* getluaobject(ObjectRef *ref); static PlayerSAO* getplayersao(ObjectRef *ref); @@ -319,18 +332,6 @@ private: // get_nametag_attributes(self) static int l_get_nametag_attributes(lua_State *L); -public: - ObjectRef(ServerActiveObject *object); - - ~ObjectRef(); - - // Creates an ObjectRef and leaves it on top of stack - // Not callable from Lua; all references are created on the C side. - static void create(lua_State *L, ServerActiveObject *object); - - static void set_null(lua_State *L); - - static void Register(lua_State *L); }; #endif /* L_OBJECT_H_ */ diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index 70807f3d2..3dc5c9574 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -32,9 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., LuaSettings::LuaSettings(Settings *settings, const std::string &filename) : m_settings(settings), - m_filename(filename), - m_is_own_settings(false), - m_write_allowed(true) + m_filename(filename) { } diff --git a/src/script/lua_api/l_settings.h b/src/script/lua_api/l_settings.h index 54b003ab3..a664b4494 100644 --- a/src/script/lua_api/l_settings.h +++ b/src/script/lua_api/l_settings.h @@ -57,10 +57,10 @@ private: // to_table(self) -> {[key1]=value1,...} static int l_to_table(lua_State *L); - Settings *m_settings; + Settings *m_settings = nullptr; std::string m_filename; - bool m_is_own_settings; - bool m_write_allowed; + bool m_is_own_settings = false; + bool m_write_allowed = true; public: LuaSettings(Settings *settings, const std::string &filename); diff --git a/src/script/lua_api/l_storage.h b/src/script/lua_api/l_storage.h index ec6f8d941..eaf7ec9f6 100644 --- a/src/script/lua_api/l_storage.h +++ b/src/script/lua_api/l_storage.h @@ -38,7 +38,7 @@ public: class StorageRef : public MetaDataRef { private: - ModMetadata *m_object; + ModMetadata *m_object = nullptr; static const char className[]; static const luaL_Reg methods[]; diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index 254a7e5a6..ed5042bcf 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -365,22 +365,17 @@ int LuaVoxelManip::l_get_emerged_area(lua_State *L) return 2; } -LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) +LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) : vm(mmvm), is_mapgen_vm(is_mg_vm) { - this->vm = mmvm; - this->is_mapgen_vm = is_mg_vm; } -LuaVoxelManip::LuaVoxelManip(Map *map) +LuaVoxelManip::LuaVoxelManip(Map *map) : vm(new MMVManip(map)) { - this->vm = new MMVManip(map); - this->is_mapgen_vm = false; } LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2) { - this->vm = new MMVManip(map); - this->is_mapgen_vm = false; + vm = new MMVManip(map); v3s16 bp1 = getNodeBlockPos(p1); v3s16 bp2 = getNodeBlockPos(p2); diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index b6a69f36a..e706f3727 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -35,7 +35,7 @@ class LuaVoxelManip : public ModApiBase { private: std::map<v3s16, MapBlock *> modified_blocks; - bool is_mapgen_vm; + bool is_mapgen_vm = false; static const char className[]; static const luaL_Reg methods[]; @@ -65,7 +65,7 @@ private: static int l_get_emerged_area(lua_State *L); public: - MMVManip *vm; + MMVManip *vm = nullptr; LuaVoxelManip(MMVManip *mmvm, bool is_mapgen_vm); LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2); |