aboutsummaryrefslogtreecommitdiff
path: root/src/lua/common/Proxy.h
blob: 60658ec0c848664f547deb82d941acfe15ffdbdf (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
#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