forked from gideros/gideros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpluginmanager.cpp
88 lines (73 loc) · 1.54 KB
/
pluginmanager.cpp
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
88
#include "pluginmanager.h"
static GGPlugin *s_active = NULL;
void *GGPlugin::main(lua_State *L, int type)
{
void *result;
if (type == 0)
{
s_active = this;
result = main2(L, type);
s_active = NULL;
}
else if (type == 1)
{
result = main2(L, type);
openUrl = NULL;
enterFrame = NULL;
suspend = NULL;
resume = NULL;
background = NULL;
foreground = NULL;
}
else
{
result = main2(L, type);
}
return result;
}
PluginManager& PluginManager::instance()
{
static PluginManager instance;
return instance;
}
int PluginManager::registerPlugin(void*(*main)(lua_State*, int))
{
GGPlugin plugin;
plugin.main2 = main;
plugins.push_back(plugin);
return 0;
}
extern "C"
{
int g_registerPlugin(void*(*main)(lua_State*, int))
{
return PluginManager::instance().registerPlugin(main);
}
}
extern "C"
{
void g_registerOpenUrlCallback(void(*openUrl)(lua_State*, const char *))
{
s_active->openUrl = openUrl;
}
void g_registerEnterFrameCallback(void(*enterFrame)(lua_State*))
{
s_active->enterFrame = enterFrame;
}
void g_registerSuspendCallback(void(*suspend)(lua_State*))
{
s_active->suspend = suspend;
}
void g_registerResumeCallback(void(*resume)(lua_State*))
{
s_active->resume = resume;
}
void g_registerForegroundCallback(void(*foreground)(lua_State*))
{
s_active->foreground = foreground;
}
void g_registerBackgroundCallback(void(*background)(lua_State*))
{
s_active->background = background;
}
}