aboutsummaryrefslogtreecommitdiff
path: root/src/lua/common/Proxy.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-23 12:23:58 +0800
committerchai <chaifix@163.com>2018-10-23 12:23:58 +0800
commit40fc27154fe754181934dc7ee31375e6bdfb33fc (patch)
tree897ad98d759bc308ef66561181ba88b85f2ccd47 /src/lua/common/Proxy.h
parent1480c9445100075c9e1a894eb07c0ef727b509a1 (diff)
*merge from minimal
Diffstat (limited to 'src/lua/common/Proxy.h')
-rw-r--r--src/lua/common/Proxy.h79
1 files changed, 49 insertions, 30 deletions
diff --git a/src/lua/common/Proxy.h b/src/lua/common/Proxy.h
index 8323ead..5ebb5b2 100644
--- a/src/lua/common/Proxy.h
+++ b/src/lua/common/Proxy.h
@@ -3,46 +3,65 @@
#include "Reference.hpp"
-namespace jin
+namespace JinEngine
{
-namespace lua
-{
-
- class Proxy
+ namespace Lua
{
- public:
- void bind(RefBase* ref)
- {
- if (ref == nullptr)
- return;
- reference = ref;
- }
- void release()
+ class Proxy
{
- if (reference != nullptr)
+ public:
+ void bind(RefBase* ref)
{
- reference->release();
- reference = nullptr;
+ if (ref == nullptr)
+ return;
+ reference = ref;
}
- }
- template<class T>
- Ref<T>& getRef()
- {
- return *(Ref<T>*) reference;
- }
+ void release()
+ {
+ if (reference != nullptr)
+ {
+ reference->release();
+ reference = nullptr;
+ }
+ }
- const char* getObjectType()
- {
- return reference->type;
- }
+ void retain()
+ {
+ if (reference != nullptr)
+ reference->retain();
+ }
+
+ void setUserdata(void* data)
+ {
+ if (reference != nullptr)
+ reference->setUserdata(data);
+ }
+
+ template<class T>
+ Ref<T>& getRef()
+ {
+ return *(Ref<T>*) reference;
+ }
+
+ template<class T>
+ T* getObject()
+ {
+ Ref<T>& ref = getRef<T>();
+ return ref.getObject();
+ }
+
+ const char* getObjectType()
+ {
+ return reference->type;
+ }
- RefBase* reference;
+ RefBase* reference;
- };
+ };
-} // lua
-} // jin
+ } // namespace Lua
+} // namespace JinEngine
#endif // __JIN_COMMON_PROXY_H \ No newline at end of file