aboutsummaryrefslogtreecommitdiff
path: root/src/lua/common/je_lua_reference.cpp
blob: 05dc82bd41e556aab9c8600af1160de25a180da6 (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
#include "je_lua_reference.h"

#include "LuaJIT/lua.hpp"
#include "libraries/luax/luax.h"

namespace JinEngine
{
    namespace Lua
    {

        LuaRef::LuaRef(lua_State* L, int i)
            : mL(L)
        {
            luax_pushvalue(mL, i);
            mIndex = luax_ref(mL, LUA_REGISTRYINDEX);
        }

        LuaRef::~LuaRef()
        {
            unref();
        }

        void LuaRef::unref()
        {
            luax_unref(mL, LUA_REGISTRYINDEX, mIndex);
        }

        void LuaRef::push()
        {
            luax_rawgeti(mL, LUA_REGISTRYINDEX, mIndex);
        }

    }
}