From d29f5f4aebd90b1e256967801b28a5990249b2e7 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 16 Mar 2019 19:29:23 +0800 Subject: *luax --- Source/Asura.Engine/scripting/portable.cpp | 9 ------- Source/Asura.Engine/scripting/portable.h | 19 ------------- Source/Asura.Engine/scripting/portable.hpp | 43 ++++++++++++++++++++++++++++++ Source/Asura.Engine/scripting/portable.inl | 30 +++++++++++++++++++++ 4 files changed, 73 insertions(+), 28 deletions(-) delete mode 100644 Source/Asura.Engine/scripting/portable.cpp delete mode 100644 Source/Asura.Engine/scripting/portable.h create mode 100644 Source/Asura.Engine/scripting/portable.hpp create mode 100644 Source/Asura.Engine/scripting/portable.inl (limited to 'Source/Asura.Engine/scripting') diff --git a/Source/Asura.Engine/scripting/portable.cpp b/Source/Asura.Engine/scripting/portable.cpp deleted file mode 100644 index 0aa5f08..0000000 --- a/Source/Asura.Engine/scripting/portable.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Portable.h" - -namespace AsuraEngine -{ - namespace Scripting - { - - } -} diff --git a/Source/Asura.Engine/scripting/portable.h b/Source/Asura.Engine/scripting/portable.h deleted file mode 100644 index 0527308..0000000 --- a/Source/Asura.Engine/scripting/portable.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __ASURA_ENGINE_PORTABLE_H__ -#define __ASURA_ENGINE_PORTABLE_H__ - -#include "Luax.hpp" -#include "Config.h" -#include "Type.h" - -namespace AsuraEngine -{ - namespace Scripting - { - - template - using Portable = Luax::LuaxClass; - - } -} - -#endif \ No newline at end of file diff --git a/Source/Asura.Engine/scripting/portable.hpp b/Source/Asura.Engine/scripting/portable.hpp new file mode 100644 index 0000000..773e7ad --- /dev/null +++ b/Source/Asura.Engine/scripting/portable.hpp @@ -0,0 +1,43 @@ +#ifndef __ASURA_ENGINE_PORTABLE_H__ +#define __ASURA_ENGINE_PORTABLE_H__ + +#include "Config.h" +#include "Luax.hpp" +#include "Type.h" + +namespace AsuraEngine +{ + namespace Scripting + { + + template + class Portable : public Luax::LuaxClass + { + public: + + Portable(); + virtual ~Portable(); + + void Retain(); + void Release(); + + private: + + /// + /// 多线程保护,lua调用gc后,如果在其他线程用了此native object,不会调用delete。 + /// + int mRefCount; + + /// + /// delete保险,继承portable的类,无法使用delete,只能使用Release。 + /// + bool mSafer; + + }; + +#include "portable.inl" + + } +} + +#endif \ No newline at end of file diff --git a/Source/Asura.Engine/scripting/portable.inl b/Source/Asura.Engine/scripting/portable.inl new file mode 100644 index 0000000..a27b2e8 --- /dev/null +++ b/Source/Asura.Engine/scripting/portable.inl @@ -0,0 +1,30 @@ + +template +Portable::Portable() + : mRefCount(1) + , mSafer(false) +{ +} + +template +Portable::~Portable() +{ + ASSERT(mSafer); +} + +template +void Portable::Retain() +{ + ++mRefCount; +} + +template +void Portable::Release() +{ + if (--mRefCount <= 0) + { + mSafer = true; + delete this; + } +} + -- cgit v1.1-26-g67d0