blob: 3903d9c76896768f1f6b31be5251e238625b712a (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#ifndef __LUAX_RUNTIME_H_
#define __LUAX_RUNTIME_H_
#include "luax_runtime.h"
using namespace std;
namespace Luax
{
LuaxRuntime* LuaxRuntime::mRuntime = nullptr;
LuaxRuntime::LuaxRuntime() {};
LuaxRuntime::~LuaxRuntime() {};
LuaxRuntime& LuaxRuntime::Get()
{
if (mRuntime == nullptr)
mRuntime = new LuaxRuntime();
return *mRuntime;
}
lua_State* LuaxRuntime::Open()
{
lua_State* L = lua_open();
assert(L);
//
mContexts.insert(pair<lua_State*, Context>(L, Context(L)));
// ʼcontext
(*this)[L].Setup();
return L;
}
void LuaxRuntime::Close(lua_State* L)
{
map<lua_State*, Context>::iterator it = mContexts.find(L);
if (it != mContexts.end())
{
lua_close(it->second.state);
mContexts.erase(it);
}
}
bool LuaxRuntime::HasLuaxState(lua_State* L)
{
map<lua_State*, Context>::iterator it = mContexts.find(L);
return it != mContexts.end();
}
LuaxState& LuaxRuntime::GetLuaxState(lua_State* L)
{
map<lua_State*, Context>::iterator it = mContexts.find(L);
if (it != mContexts.end())
{
return it->second.state;
}
}
LuaxRefTable& LuaxRuntime::GetStrongRefTable(lua_State* L)
{
map<lua_State*, Context>::iterator it = mContexts.find(L);
if (it != mContexts.end())
{
return it->second.strongRefTable;
}
}
LuaxRefTable& LuaxRuntime::GetWeaksRefTable(lua_State* L)
{
map<lua_State*, Context>::iterator it = mContexts.find(L);
if (it != mContexts.end())
{
return it->second.weakRefTable;
}
}
Context& LuaxRuntime::operator[](lua_State* L)
{
map<lua_State*, Context>::iterator it = mContexts.find(L);
assert(it != mContexts.end());
return it->second;
}
}
#endif
|