-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobalUI.cpp
166 lines (147 loc) · 3.39 KB
/
GlobalUI.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "stdafx.h"
#include "GlobalUI.h"
#include "utility/FlLayout.h"
#ifdef USE_LUABIND
#include "../MainLib/WrapperLua/BaselibLUA.h"
#include "../MainLib/WrapperLua/MainlibLUA.h"
#include <luabind/luabind.hpp>
#include <luabind/operator.hpp>
#include <luabind/out_value_policy.hpp>
#include <luabind/adopt_policy.hpp>
#include <luabind/error.hpp>
#else
#include "WrapperLua/LUAwrapper.h"
#endif
#include "luna.h"
#include "luna_baselib.h"
#include "luna_mainlib.h"
#define CATCH_LUABIND_ERROR(x) catch(luabind::error& e)\
{\
printf("lua error %s, %s \n", x, e.what());\
int n=lua_gettop(e.state());\
Msg::msgBox("lua error %s", lua_tostring(e.state(), n));\
ASSERT(0);\
delete _L; _L=NULL;\
}
#ifndef WIN32
#include <unistd.h>
#endif
void registerFlChoiceWins(lua_State* L);
// singleton class
static FlLayout* _win=NULL;
static GlobalUI* _GUI=NULL;
void registerGlobalUI(LUAwrapper* L);
void Register_baselib(lua_State*L);
void Register_mainlib(lua_State*L);
GlobalUI::GlobalUI(FlLayout* wins,int argc, char* argv[])
{
_win=wins;
_GUI=this;
_param.resize(argc-1);
for(int i=1; i<argc; i++)
_param[i-1]=argv[i];
_L=NULL;
if(argc>1)
{
#ifdef USE_LUABIND
_L=new LUAwrapper();
addMainlibModule(_L->L);
registerGlobalUI(_L);
try{
_L->setRef<TStrings>("param", _param);
_L->dofile(_param[0]);
}
CATCH_LUABIND_ERROR("ctor")
#else
_L=new LUAwrapper();
Register_baselib(_L->L);
Register_mainlib(_L->L);
lunaStack ls(_L->L);
ls.set<TStrings>("param", &_param);
ls.set<GlobalUI>("GUI", _GUI);
ls.set<FlLayout>("wins", _win);
//try{
_L->dofile(_param[0]);
//}
//CATCH_LUABIND_ERROR("ctor")
#endif
}
}
int GlobalUI::work(TString const& wn, OR::LUAStack& L)
{
return 0;
}
#ifdef USE_LUABIND
void GlobalUI::work(const char* _wn, luabind::adl::object const& table)
{
TString wn=_wn;
if(wn=="showOgreTraceManager")
{
RE::FltkRenderer().onCallback(NULL, Hash("OgreTraceManager"));
}
#ifndef WIN32
else if(wn=="chdir"){
TString temp=luabind::object_cast<const char*>(table);
chdir(temp.ptr());
}
else if(wn=="printcwd"){
char buf[1000];
getcwd(buf,1000);
printf("cwd:%s\n", buf);
}
#endif
}
#endif
#ifdef USE_LUABIND
void registerGlobalUI(LUAwrapper* L)
{
registerFlChoiceWins(L->L);
luabind::module(L->L)
[
luabind::class_<GlobalUI>("GlobalUI")
.def("__call", &GlobalUI::work)
];
if(_GUI)
{
L->setRef<GlobalUI>("GUI", *_GUI);
L->setRef<FlChoiceWins>("wins", *_wins);
}
else
{
printf("??????\n");
}
}
#endif
GlobalUI* getGlobalUI()
{
return _GUI;
}
GlobalUI::~GlobalUI()
{
if(_L) delete _L;
_L=NULL;
}
#ifdef USE_LUABIND
using namespace luabind;
void registerFlChoiceWins(lua_State* L)
{
struct FlChoiceWins_
{
static FlChoiceWins* choiceWin(FlChoiceWins* win, int i)
{
return dynamic_cast<FlChoiceWins*>(win->window(i));
}
static FlLayout* layout(FlChoiceWins* win, int i)
{
return static_cast<FlLayout*>(win->window(i));
}
};
module(L)[
class_<FlChoiceWins>("FlChoiceWins")
.def("show",(void (FlChoiceWins::*)(int))&FlChoiceWins::show)
.def_readwrite("windowNames", &FlChoiceWins::windowNames)
.def("choiceWin", &FlChoiceWins_::choiceWin)
.def("layout", &FlChoiceWins_::layout)
];
}
#endif