aboutsummaryrefslogtreecommitdiff
path: root/src/lua/common/je_lua_proxy.h
blob: 56e5fee908a0c5dd844ba014a7d30e0f2305dcdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef __JIN_COMMON_PROXY_H
#define __JIN_COMMON_PROXY_H

#include "je_lua_shared.hpp"

namespace JinEngine
{
    namespace Lua
    {

        class Proxy
        {
        public:
            void bind(SharedBase* ref)
            {
                if (ref == nullptr)
                    return;
                shared = ref;
            }

            void release()
            {
                if (shared != nullptr)
                {
                    shared->release();
                    shared = nullptr;
                }
            }

		    void retain()
		    {
			    if (shared != nullptr)
				    shared->retain();
		    }

		    void setUserdata(void* data)
		    {
			    if (shared != nullptr)
				    shared->setUserdata(data);
		    }

            template<class T>
            Shared<T>& getShared()
            {
                return *(static_cast<Shared<T>*>(shared));
            }

            template<class T>
            T* getObject()
            {
                Shared<T>& ref = getShared<T>();
                return ref.getObject();
            }

            const char* getObjectType()
            {
                return shared->type;
            }

            SharedBase* shared; 

        };

    } // namespace Lua
} // namespace JinEngine

#endif // __JIN_COMMON_PROXY_H