forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableMgr.cpp
More file actions
54 lines (46 loc) · 1.17 KB
/
TableMgr.cpp
File metadata and controls
54 lines (46 loc) · 1.17 KB
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
/*
* Copyright (C) 2010 - 2015 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#include "LuaEngine.h"
#include "TableMgr.h"
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
};
TableMgr::TableMgr(Eluna * eluna) : owner(eluna)
{
ASSERT(eluna);
}
void TableMgr::DeleteAllTableRefs()
{
while (!tableRefMap.empty())
DeleteTableRef(tableRefMap.begin()->first);
}
void TableMgr::DeleteTableRef(ObjectGuid const & guid)
{
const auto it = tableRefMap.find(guid);
if (it != tableRefMap.end())
{
luaL_unref(owner->L, LUA_REGISTRYINDEX, it->second);
tableRefMap.erase(it);
}
}
void TableMgr::PushTableRef(ObjectGuid const & guid)
{
const auto it = tableRefMap.find(guid);
if (it != tableRefMap.end())
lua_rawgeti(owner->L, LUA_REGISTRYINDEX, it->second);
else
lua_pushnil(owner->L);
}
void TableMgr::CreateTable(ObjectGuid const & guid)
{
DeleteTableRef(guid);
lua_newtable(owner->L);
int ref = luaL_ref(owner->L, LUA_REGISTRYINDEX);
if (ref != LUA_REFNIL)
tableRefMap[guid] = ref;
}