diff options
Diffstat (limited to 'src/lua/common')
-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 |
4 files changed, 146 insertions, 0 deletions
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 |