diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/audio/luaopen_Source.cpp | 2 | ||||
-rw-r--r-- | src/lua/audio/luaopen_audio.cpp | 2 | ||||
-rw-r--r-- | src/lua/common/Proxy.h | 46 | ||||
-rw-r--r-- | src/lua/common/Reference.hpp | 72 | ||||
-rw-r--r-- | src/lua/common/common.h | 8 | ||||
-rw-r--r-- | src/lua/common/types.h | 20 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Canvas.cpp | 2 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Font.cpp | 2 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Image.cpp | 2 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_JSL.cpp | 2 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_graphics.cpp | 2 | ||||
-rw-r--r-- | src/lua/luaopen_jin.h | 6 | ||||
-rw-r--r-- | src/lua/luaopen_types.h | 95 | ||||
-rw-r--r-- | src/lua/net/Buffer.h | 2 | ||||
-rw-r--r-- | src/lua/net/luaopen_Buffer.cpp | 2 | ||||
-rw-r--r-- | src/lua/net/luaopen_Socket.cpp | 2 | ||||
-rw-r--r-- | src/lua/net/luaopen_net.cpp | 2 | ||||
-rw-r--r-- | src/lua/thread/Thread.h | 2 | ||||
-rw-r--r-- | src/lua/thread/luaopen_Thread.cpp | 2 | ||||
-rw-r--r-- | src/lua/thread/luaopen_thread.cpp | 2 |
20 files changed, 163 insertions, 112 deletions
diff --git a/src/lua/audio/luaopen_Source.cpp b/src/lua/audio/luaopen_Source.cpp index 25e44b3..3e4408a 100644 --- a/src/lua/audio/luaopen_Source.cpp +++ b/src/lua/audio/luaopen_Source.cpp @@ -1,6 +1,6 @@ #include "lua/luax.h" -#include "../luaopen_types.h" #include "libjin/jin.h" +#include "../common/common.h" namespace jin { diff --git a/src/lua/audio/luaopen_audio.cpp b/src/lua/audio/luaopen_audio.cpp index 5edfe7b..e6c54c9 100644 --- a/src/lua/audio/luaopen_audio.cpp +++ b/src/lua/audio/luaopen_audio.cpp @@ -1,5 +1,5 @@ #include "lua/luax.h" -#include "../luaopen_types.h" +#include "../common/common.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/common/Proxy.h b/src/lua/common/Proxy.h new file mode 100644 index 0000000..60658ec --- /dev/null +++ b/src/lua/common/Proxy.h @@ -0,0 +1,46 @@ +#ifndef __JIN_COMMON_PROXY_H +#define __JIN_COMMON_PROXY_H + +#include "Reference.hpp" + +namespace jin +{ +namespace lua +{ + + class Proxy + { + public: + void bind(Reference* ref, const char* t) + { + if (ref == nullptr) + return; + reference = ref; + type = t; + } + + void release() + { + if (reference != nullptr) + { + reference->release(); + reference = nullptr; + type = nullptr; + } + } + + template<class T> + Ref<T>& getRef() + { + return *(Ref<T>*) reference; + } + + const char* type; // type name and metatable name + Reference* reference; // acctual object binded + + }; + +} // lua +} // jin + +#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 new file mode 100644 index 0000000..f330323 --- /dev/null +++ b/src/lua/common/Reference.hpp @@ -0,0 +1,72 @@ +#ifndef __JIN_COMMON_REFERENCE_H +#define __JIN_COMMON_REFERENCE_H + +namespace jin +{ +namespace lua +{ + + /*abstract*/class Reference + { + public: + void retain() + { + ++count; + } + + void release() + { + if (--count <= 0) + delete this; + } + + protected: + Reference(void* obj) + : count(1) + , object(obj) + { + } + Reference(const Reference&); + virtual ~Reference() + { + } + + void* object; + int count; + + }; + + template<class T> + class Ref : public Reference + { + public: + Ref(T* obj) + : Reference(obj) + { + } + + ~Ref() + { + T* obj = (T*)object; + delete obj; + } + + T* operator->() + { + return (T*)object; + } + + T* getObject() + { + return (T*)object; + } + + private: + Ref(const Ref<T>& ref); + + }; + +} +} + +#endif
\ No newline at end of file diff --git a/src/lua/common/common.h b/src/lua/common/common.h new file mode 100644 index 0000000..833b204 --- /dev/null +++ b/src/lua/common/common.h @@ -0,0 +1,8 @@ +#ifndef __JIN_M_TYPES_H +#define __JIN_M_TYPES_H + +#include "types.h" +#include "Proxy.h" +#include "Reference.hpp" + +#endif
\ No newline at end of file diff --git a/src/lua/common/types.h b/src/lua/common/types.h new file mode 100644 index 0000000..0ab40a6 --- /dev/null +++ b/src/lua/common/types.h @@ -0,0 +1,20 @@ +#ifndef __JIN_COMMON_TYPES_H +#define __JIN_COMMON_TYPES_H + +// graphics module +#define JIN_GRAPHICS_IMAGE "jin.graphics.Image" +#define JIN_GRAPHICS_SHADER "jin.graphics.Shader" +#define JIN_GRAPHICS_CANVAS "jin.graphics.Canvas" +#define JIN_GRAPHICS_FONT "jin.graphics.Font" + +// audio module +#define JIN_AUDIO_SOURCE "jin.Audio.Source" + +// thread module +#define JIN_THREAD_THREAD "jin.thread.Thread" + +// network module +#define JIN_NETWORK_SOCKET "jin.net.Socket" +#define JIN_NETWORK_BUFFER "jin.net.Buffer" + +#endif
\ No newline at end of file diff --git a/src/lua/graphics/luaopen_Canvas.cpp b/src/lua/graphics/luaopen_Canvas.cpp index ca1270c..302d139 100644 --- a/src/lua/graphics/luaopen_Canvas.cpp +++ b/src/lua/graphics/luaopen_Canvas.cpp @@ -1,5 +1,5 @@ #include "lua/luax.h" -#include "lua/luaopen_types.h" +#include "lua/common/common.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/graphics/luaopen_Font.cpp b/src/lua/graphics/luaopen_Font.cpp index dc891b0..6686d03 100644 --- a/src/lua/graphics/luaopen_Font.cpp +++ b/src/lua/graphics/luaopen_Font.cpp @@ -1,5 +1,5 @@ #include "lua/luax.h" -#include "lua/luaopen_types.h" +#include "lua/common/common.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/graphics/luaopen_Image.cpp b/src/lua/graphics/luaopen_Image.cpp index 47cb4c6..4ed92cf 100644 --- a/src/lua/graphics/luaopen_Image.cpp +++ b/src/lua/graphics/luaopen_Image.cpp @@ -1,5 +1,5 @@ #include "lua/luax.h" -#include "lua/luaopen_types.h" +#include "lua/common/common.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/graphics/luaopen_JSL.cpp b/src/lua/graphics/luaopen_JSL.cpp index 30b109a..cd77a03 100644 --- a/src/lua/graphics/luaopen_JSL.cpp +++ b/src/lua/graphics/luaopen_JSL.cpp @@ -1,5 +1,5 @@ #include "lua/luax.h" -#include "lua/luaopen_types.h" +#include "lua/common/common.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp index 14449a4..c30365f 100644 --- a/src/lua/graphics/luaopen_graphics.cpp +++ b/src/lua/graphics/luaopen_graphics.cpp @@ -1,6 +1,6 @@ #include "lua/luax.h" #include "libjin/jin.h" -#include "lua/luaopen_types.h" +#include "lua/common/common.h" #include "lua/embed/graphics.lua.h" namespace jin diff --git a/src/lua/luaopen_jin.h b/src/lua/luaopen_jin.h index f4253b6..c93b66d 100644 --- a/src/lua/luaopen_jin.h +++ b/src/lua/luaopen_jin.h @@ -40,7 +40,7 @@ namespace lua void boot(lua_State* L); -} -} +} // jin +} // lua -#endif
\ No newline at end of file +#endif // __JIN_M_JIN_H
\ No newline at end of file diff --git a/src/lua/luaopen_types.h b/src/lua/luaopen_types.h deleted file mode 100644 index 47eb3be..0000000 --- a/src/lua/luaopen_types.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef __JIN_M_TYPES_H -#define __JIN_M_TYPES_H - -// graphics module -#define JIN_GRAPHICS_IMAGE "jin.graphics.Image" -#define JIN_GRAPHICS_SHADER "jin.graphics.Shader" -#define JIN_GRAPHICS_CANVAS "jin.graphics.Canvas" -#define JIN_GRAPHICS_FONT "jin.graphics.Font" - -// audio module -#define JIN_AUDIO_SOURCE "jin.Audio.Source" - -// thread module -#define JIN_THREAD_THREAD "jin.thread.Thread" - -// network module -#define JIN_NETWORK_SOCKET "jin.net.Socket" -#define JIN_NETWORK_BUFFER "jin.net.Buffer" - -namespace jin -{ -namespace lua -{ - - class Reference - { - public: - Reference(void* obj) - : count(1) - , object(obj) - { - } - - void retain() - { - ++count; - } - - void release() - { - if (--count <= 0) - delete this; - } - - template<class T> - T* getObject() - { - return (T*)object; - } - - private: - Reference(const Reference&); - virtual ~Reference() {} - - void* object; - int count; - - }; - - class Proxy - { - public: - void bind(Reference* ref, const char* t) - { - if (ref == nullptr) - return; - reference = ref; - type = t; - } - - void release() - { - if (reference != nullptr) - { - reference->release(); - reference = nullptr; - type = nullptr; - } - } - - template<class T> - T* getObject() - { - return reference->getObject<T>(); - } - - const char* type; // type name and metatable name - Reference* reference; // acctual object binded - - }; - -} // lua -} // jin - -#endif
\ No newline at end of file diff --git a/src/lua/net/Buffer.h b/src/lua/net/Buffer.h index 894de8c..89a4fc0 100644 --- a/src/lua/net/Buffer.h +++ b/src/lua/net/Buffer.h @@ -3,7 +3,7 @@ #include <cstring> #include <cstdlib> -#include "../luaopen_types.h" +#include "../common/common.h" namespace jin { diff --git a/src/lua/net/luaopen_Buffer.cpp b/src/lua/net/luaopen_Buffer.cpp index f50f82e..9708357 100644 --- a/src/lua/net/luaopen_Buffer.cpp +++ b/src/lua/net/luaopen_Buffer.cpp @@ -1,5 +1,5 @@ #include "lua/luax.h" -#include "../luaopen_types.h" +#include "../common/common.h" #include "libjin/jin.h" #include "Buffer.h" diff --git a/src/lua/net/luaopen_Socket.cpp b/src/lua/net/luaopen_Socket.cpp index 4f8c45a..0ee5f4c 100644 --- a/src/lua/net/luaopen_Socket.cpp +++ b/src/lua/net/luaopen_Socket.cpp @@ -1,5 +1,5 @@ #include "lua/luax.h" -#include "../luaopen_types.h" +#include "../common/common.h" #include "libjin/jin.h" #include "Buffer.h" diff --git a/src/lua/net/luaopen_net.cpp b/src/lua/net/luaopen_net.cpp index 0fce20f..5a9ce71 100644 --- a/src/lua/net/luaopen_net.cpp +++ b/src/lua/net/luaopen_net.cpp @@ -1,6 +1,6 @@ #include "lua/luax.h" #include "libjin/jin.h" -#include "../luaopen_types.h" +#include "../common/common.h" #include "Buffer.h" namespace jin diff --git a/src/lua/thread/Thread.h b/src/lua/thread/Thread.h index 4e39c34..3b2cbaf 100644 --- a/src/lua/thread/Thread.h +++ b/src/lua/thread/Thread.h @@ -1,5 +1,5 @@ #include "libjin/jin.h" -#include "../luaopen_types.h" +#include "../common/common.h" namespace jin { diff --git a/src/lua/thread/luaopen_Thread.cpp b/src/lua/thread/luaopen_Thread.cpp index 0d87907..eaa263d 100644 --- a/src/lua/thread/luaopen_Thread.cpp +++ b/src/lua/thread/luaopen_Thread.cpp @@ -1,7 +1,7 @@ #include "lua/luax.h" #include "libjin/jin.h" #include "../luaopen_jin.h" -#include "../luaopen_types.h" +#include "../common/common.h" #include "Thread.h" namespace jin diff --git a/src/lua/thread/luaopen_thread.cpp b/src/lua/thread/luaopen_thread.cpp index 0d87907..eaa263d 100644 --- a/src/lua/thread/luaopen_thread.cpp +++ b/src/lua/thread/luaopen_thread.cpp @@ -1,7 +1,7 @@ #include "lua/luax.h" #include "libjin/jin.h" #include "../luaopen_jin.h" -#include "../luaopen_types.h" +#include "../common/common.h" #include "Thread.h" namespace jin |