From 7322a090355af1989d7a1de0de431b6c89844fe2 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 25 Oct 2018 08:18:13 +0800 Subject: =?UTF-8?q?*=E5=A2=9E=E5=8A=A0lua=E5=AF=BC=E5=87=BA=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/common/Proxy.h | 67 ---------------------------- src/lua/common/Reference.hpp | 88 ------------------------------------- src/lua/common/common.h | 8 ---- src/lua/common/constant.h | 1 - src/lua/common/error.h | 28 ------------ src/lua/common/je_lua_common.h | 9 ++++ src/lua/common/je_lua_constant.h | 1 + src/lua/common/je_lua_error.h | 27 ++++++++++++ src/lua/common/je_lua_port.h | 8 ++++ src/lua/common/je_lua_proxy.h | 67 ++++++++++++++++++++++++++++ src/lua/common/je_lua_reference.hpp | 88 +++++++++++++++++++++++++++++++++++++ 11 files changed, 200 insertions(+), 192 deletions(-) delete mode 100644 src/lua/common/Proxy.h delete mode 100644 src/lua/common/Reference.hpp delete mode 100644 src/lua/common/common.h delete mode 100644 src/lua/common/constant.h delete mode 100644 src/lua/common/error.h create mode 100644 src/lua/common/je_lua_common.h create mode 100644 src/lua/common/je_lua_constant.h create mode 100644 src/lua/common/je_lua_error.h create mode 100644 src/lua/common/je_lua_port.h create mode 100644 src/lua/common/je_lua_proxy.h create mode 100644 src/lua/common/je_lua_reference.hpp (limited to 'src/lua/common') diff --git a/src/lua/common/Proxy.h b/src/lua/common/Proxy.h deleted file mode 100644 index 5ebb5b2..0000000 --- a/src/lua/common/Proxy.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __JIN_COMMON_PROXY_H -#define __JIN_COMMON_PROXY_H - -#include "Reference.hpp" - -namespace JinEngine -{ - namespace Lua - { - - class Proxy - { - public: - void bind(RefBase* ref) - { - if (ref == nullptr) - return; - reference = ref; - } - - void release() - { - if (reference != nullptr) - { - reference->release(); - reference = nullptr; - } - } - - void retain() - { - if (reference != nullptr) - reference->retain(); - } - - void setUserdata(void* data) - { - if (reference != nullptr) - reference->setUserdata(data); - } - - template - Ref& getRef() - { - return *(Ref*) reference; - } - - template - T* getObject() - { - Ref& ref = getRef(); - return ref.getObject(); - } - - const char* getObjectType() - { - return reference->type; - } - - RefBase* reference; - - }; - - } // namespace Lua -} // namespace JinEngine - -#endif // __JIN_COMMON_PROXY_H \ No newline at end of file diff --git a/src/lua/common/Reference.hpp b/src/lua/common/Reference.hpp deleted file mode 100644 index ba918bb..0000000 --- a/src/lua/common/Reference.hpp +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef __JIN_COMMON_REFERENCE_H -#define __JIN_COMMON_REFERENCE_H - -namespace JinEngine -{ - namespace Lua - { - - /*abstract*/class RefBase - { - public: - void retain() - { - ++count; - } - - void release() - { - if (--count <= 0) - delete this; - } - - // object type string - const char* const type; - - void setUserdata(void* data) - { - userdata = data; - } - - void* getUserdata() - { - return userdata; - } - - protected: - RefBase(void* obj, const char* t) - : count(1) - , object(obj) - , type(t) - { - } - - RefBase(const RefBase&); - - virtual ~RefBase() - { - } - - void* object; - int count; - void* userdata; - }; - - template - class Ref : public RefBase - { - public: - Ref(T* obj, const char* type) - : RefBase(obj, type) - { - } - - ~Ref() - { - T* obj = static_cast(object); - delete obj; - } - - T* operator->() - { - return (T*)object; - } - - T* getObject() - { - return (T*)object; - } - - private: - Ref(const Ref& ref); - - }; - - } -} - -#endif \ No newline at end of file diff --git a/src/lua/common/common.h b/src/lua/common/common.h deleted file mode 100644 index 0ee72cc..0000000 --- a/src/lua/common/common.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __JIN_M_TYPES_H -#define __JIN_M_TYPES_H - -#include "Proxy.h" -#include "Reference.hpp" -#include "error.h" - -#endif \ No newline at end of file diff --git a/src/lua/common/constant.h b/src/lua/common/constant.h deleted file mode 100644 index 6f70f09..0000000 --- a/src/lua/common/constant.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/src/lua/common/error.h b/src/lua/common/error.h deleted file mode 100644 index c254486..0000000 --- a/src/lua/common/error.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __JIN_ERROR_H -#define __JIN_ERROR_H -#include "../../luax.h" -#include "../jin.h" -#include - -namespace JinEngine -{ -namespace Lua -{ - - static const int FORMAT_MSG_BUFFER_SIZE = 2048; - - inline void error(lua_State* L, const char* fmt, ...) - { - char err[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 }; - va_list args; - va_start(args, fmt); - vsnprintf(err + strlen(err), FORMAT_MSG_BUFFER_SIZE, fmt, args); - va_end(args); - luax_getglobal(L, MODULE_NAME); - luax_setfieldstring(L, "error", err); - } - -} -} - -#endif \ No newline at end of file diff --git a/src/lua/common/je_lua_common.h b/src/lua/common/je_lua_common.h new file mode 100644 index 0000000..1d772a5 --- /dev/null +++ b/src/lua/common/je_lua_common.h @@ -0,0 +1,9 @@ +#ifndef __JIN_M_TYPES_H +#define __JIN_M_TYPES_H + +#include "je_lua_port.h" +#include "je_lua_proxy.h" +#include "je_lua_reference.hpp" +#include "je_lua_error.h" + +#endif \ No newline at end of file diff --git a/src/lua/common/je_lua_constant.h b/src/lua/common/je_lua_constant.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/src/lua/common/je_lua_constant.h @@ -0,0 +1 @@ +#pragma once diff --git a/src/lua/common/je_lua_error.h b/src/lua/common/je_lua_error.h new file mode 100644 index 0000000..fd21b41 --- /dev/null +++ b/src/lua/common/je_lua_error.h @@ -0,0 +1,27 @@ +#ifndef __JIN_ERROR_H +#define __JIN_ERROR_H +#include "../luax.h" +#include + +namespace JinEngine +{ + namespace Lua + { + + static const int FORMAT_MSG_BUFFER_SIZE = 2048; + + inline void error(lua_State* L, const char* fmt, ...) + { + char err[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 }; + va_list args; + va_start(args, fmt); + vsnprintf(err + strlen(err), FORMAT_MSG_BUFFER_SIZE, fmt, args); + va_end(args); + luax_getglobal(L, "jin"); + luax_setfieldstring(L, "error", err); + } + + } +} + +#endif \ No newline at end of file diff --git a/src/lua/common/je_lua_port.h b/src/lua/common/je_lua_port.h new file mode 100644 index 0000000..8e99ca4 --- /dev/null +++ b/src/lua/common/je_lua_port.h @@ -0,0 +1,8 @@ +#ifndef __JE_LUA_PORT_H +#define __JE_LUA_PORT_H + +#define LUA_PORT extern +#define LUA_IMPLEMENT static +#define LUA_EXPORT + +#endif \ No newline at end of file diff --git a/src/lua/common/je_lua_proxy.h b/src/lua/common/je_lua_proxy.h new file mode 100644 index 0000000..b428dc9 --- /dev/null +++ b/src/lua/common/je_lua_proxy.h @@ -0,0 +1,67 @@ +#ifndef __JIN_COMMON_PROXY_H +#define __JIN_COMMON_PROXY_H + +#include "je_lua_reference.hpp" + +namespace JinEngine +{ + namespace Lua + { + + class Proxy + { + public: + void bind(RefBase* ref) + { + if (ref == nullptr) + return; + reference = ref; + } + + void release() + { + if (reference != nullptr) + { + reference->release(); + reference = nullptr; + } + } + + void retain() + { + if (reference != nullptr) + reference->retain(); + } + + void setUserdata(void* data) + { + if (reference != nullptr) + reference->setUserdata(data); + } + + template + Ref& getRef() + { + return *(Ref*) reference; + } + + template + T* getObject() + { + Ref& ref = getRef(); + return ref.getObject(); + } + + const char* getObjectType() + { + return reference->type; + } + + RefBase* reference; + + }; + + } // namespace Lua +} // namespace JinEngine + +#endif // __JIN_COMMON_PROXY_H \ No newline at end of file diff --git a/src/lua/common/je_lua_reference.hpp b/src/lua/common/je_lua_reference.hpp new file mode 100644 index 0000000..ba918bb --- /dev/null +++ b/src/lua/common/je_lua_reference.hpp @@ -0,0 +1,88 @@ +#ifndef __JIN_COMMON_REFERENCE_H +#define __JIN_COMMON_REFERENCE_H + +namespace JinEngine +{ + namespace Lua + { + + /*abstract*/class RefBase + { + public: + void retain() + { + ++count; + } + + void release() + { + if (--count <= 0) + delete this; + } + + // object type string + const char* const type; + + void setUserdata(void* data) + { + userdata = data; + } + + void* getUserdata() + { + return userdata; + } + + protected: + RefBase(void* obj, const char* t) + : count(1) + , object(obj) + , type(t) + { + } + + RefBase(const RefBase&); + + virtual ~RefBase() + { + } + + void* object; + int count; + void* userdata; + }; + + template + class Ref : public RefBase + { + public: + Ref(T* obj, const char* type) + : RefBase(obj, type) + { + } + + ~Ref() + { + T* obj = static_cast(object); + delete obj; + } + + T* operator->() + { + return (T*)object; + } + + T* getObject() + { + return (T*)object; + } + + private: + Ref(const Ref& ref); + + }; + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0