forked from ComputerNerd/Retro-Graphics-Toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacklua.cpp
73 lines (65 loc) · 2.64 KB
/
callbacklua.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
/*
This file is part of Retro Graphics Toolkit
Retro Graphics Toolkit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or any later version.
Retro Graphics Toolkit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Retro Graphics Toolkit. If not, see <http://www.gnu.org/licenses/>.
Copyright Sega16 (or whatever you wish to call me) (2012-2017)
*/
#include "callbacklua.h"
#include "project.h"
#include "class_global.h"
#include "runlua.h"
#include "luaconfig.h"
int curScript = -1;
void appendLuaScript(Fl_Widget*, void*) {
window->luaEditProject->show();
unsigned name = currentProject->lScrpt.size();
std::string nstr = std::to_string(name);
currentProject->lScrpt.emplace_back(luaScript{std::string(""), nstr});
window->luaScriptSel->add(nstr.c_str(), 0, switchCurLuaScript, (void*)(intptr_t)name);
window->luaScriptSel->value(name);
switchCurLuaScript(nullptr, (void*)(intptr_t)name);
}
void deleteLuaScript(Fl_Widget*, void*) {
if (curScript >= 0) {
currentProject->lScrpt.erase(currentProject->lScrpt.begin() + curScript);
window->luaScriptSel->remove(curScript);
if (currentProject->lScrpt.size()) {
if (curScript >= currentProject->lScrpt.size()) {
curScript = currentProject->lScrpt.size() - 1;
window->luaScriptName->value(currentProject->lScrpt[curScript].name.c_str());
window->luaBufProject->text(currentProject->lScrpt[curScript].str.c_str());
}
} else
window->luaEditProject->hide();
}
window->redraw();
}
void setNameLuaScript(Fl_Widget*w, void*) {
Fl_Input*i = (Fl_Input*)w;
if (curScript >= 0) {
currentProject->lScrpt[curScript].name.assign(i->value());
window->luaScriptSel->replace(curScript, currentProject->lScrpt[curScript].name.c_str());
}
window->redraw();
}
void switchCurLuaScript(Fl_Widget*, void*o) {
if (curScript >= 0)
currentProject->lScrpt[curScript].str.assign(window->luaBufProject->text());
curScript = (intptr_t)o;
window->luaScriptName->value(currentProject->lScrpt[curScript].name.c_str());
window->luaBufProject->text(currentProject->lScrpt[curScript].str.c_str());
window->redraw();
}
void runCurLuaScript(Fl_Widget*, void*) {
if (curScript >= 0) {
currentProject->lScrpt[curScript].str.assign(window->luaBufProject->text());
runLua(Lconf, currentProject->lScrpt[curScript].str.c_str(), false);
}
}