Skip to content

Commit e0688e7

Browse files
committed
Add new log category for script. Rename member variables in ImConsole to match style.
1 parent d59067c commit e0688e7

File tree

6 files changed

+62
-48
lines changed

6 files changed

+62
-48
lines changed

Common/Log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ enum class Log {
5757
GeDebugger,
5858
UI,
5959
IAP,
60+
Script,
6061

6162
sceAudio,
6263
sceCtrl,

Common/Log/LogManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static const char * const g_logTypeNames[] = {
9696
"GEDEBUGGER",
9797
"UI",
9898
"IAP",
99+
"SCRIPT",
99100
"SCEAUDIO",
100101
"SCECTRL",
101102
"SCEDISP",

Core/HLE/Plugins.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ bool Load(PSPModule *pluginWaitingModule, SceUID threadID) {
224224
INFO_LOG(Log::System, "Loaded plugin: %s", filename.c_str());
225225
}
226226

227+
bool anyLua = false;
228+
227229
for (LuaPlugin &luaPlugin : luaPlugins) {
228230
if (!g_Config.bEnablePlugins) {
229231
WARN_LOG(Log::System, "Plugins are disabled, ignoring enabled Lua plugin %s", luaPlugin.filename.c_str());
@@ -239,9 +241,15 @@ bool Load(PSPModule *pluginWaitingModule, SceUID threadID) {
239241
s.resize(luaCodeBytes.size());
240242
memcpy(s.data(), luaCodeBytes.data(), luaCodeBytes.size());
241243
luaPlugin.context->RunCode(s);
244+
245+
anyLua = true;
242246
}
243247
}
244248

249+
if (anyLua) {
250+
g_OSD.Show(OSDType::MESSAGE_WARNING, "Lua plugins are EXPERIMENTAL and the lua API WILL CHANGE in future versions!", 4.0f);
251+
}
252+
245253
std::lock_guard<std::mutex> guard(g_inputMutex);
246254
PluginDataKeys.clear();
247255
return started;

Core/LuaContext.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ static bool IsProbablyExpression(std::string_view input) {
3232

3333
// TODO: Should these also echo to the console?
3434
static void debug(const char *message) {
35-
DEBUG_LOG(Log::System, "%s", message);
35+
DEBUG_LOG(Log::Script, "%s", message);
3636
}
3737

3838
static void info(const char *message) {
39-
INFO_LOG(Log::System, "%s", message);
39+
INFO_LOG(Log::Script, "%s", message);
4040
}
4141

4242
static void warn(const char *message) {
43-
WARN_LOG(Log::System, "%s", message);
43+
WARN_LOG(Log::Script, "%s", message);
4444
}
4545

4646
static void error(const char *message) {
47-
ERROR_LOG(Log::System, "%s", message);
47+
ERROR_LOG(Log::Script, "%s", message);
4848
}
4949

5050
static int gpr(int reg) {
@@ -417,7 +417,7 @@ void LuaContext::RunCode(const std::string &code) {
417417
Print(LogLineType::Error, err.what());
418418
}
419419
} catch (const sol::error& e) {
420-
ERROR_LOG(Log::System, "Lua exception: %s", e.what());
420+
ERROR_LOG(Log::Script, "Lua exception: %s", e.what());
421421
Print(LogLineType::Error, e.what());
422422
}
423423
}
@@ -463,7 +463,7 @@ void LuaContext::PrintF(LogLineType type, const char* fmt, ...) {
463463
}
464464

465465
void LuaContext::Print(LogLineType type, std::string_view text) {
466-
INFO_LOG(Log::System, "%.*s", (int)text.size(), text.data());
466+
INFO_LOG(Log::Script, "%.*s", (int)text.size(), text.data());
467467
}
468468

469469
void LuaInteractiveContext::Print(LogLineType type, std::string_view text) {
@@ -561,7 +561,7 @@ void LuaInteractiveContext::ExecuteConsoleCommand(std::string_view cmd) {
561561
lines_.push_back(LuaLogLine{ LogLineType::Error, std::string(err.what()) });
562562
}
563563
} catch (const sol::error& e) {
564-
ERROR_LOG(Log::System, "Lua exception: %s", e.what());
564+
ERROR_LOG(Log::Script, "Lua exception: %s", e.what());
565565
lines_.push_back(LuaLogLine{ LogLineType::Error, std::string(e.what()) });
566566
}
567567
}

UI/ImDebugger/ImConsole.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
#include "Common/StringUtils.h"
99

1010
ImConsole::ImConsole() {
11-
memset(InputBuf, 0, sizeof(InputBuf));
11+
memset(inputBuf_, 0, sizeof(inputBuf_));
1212

13-
HistoryPos = -1;
13+
historyPos_ = -1;
1414

1515
// "CLASSIFY" is here to provide the test case where "C"+[tab] completes to "CL" and display multiple matches.
16-
AutoScroll = true;
17-
ScrollToBottom = false;
16+
autoScroll_ = true;
17+
scrollToBottom_ = false;
1818
}
1919

2020
ImConsole::~ImConsole() {
21-
for (int i = 0; i < History.Size; i++)
22-
ImGui::MemFree(History[i]);
21+
for (int i = 0; i < history_.Size; i++)
22+
ImGui::MemFree(history_[i]);
2323
}
2424

2525
// Portable helpers
@@ -52,7 +52,7 @@ void ImConsole::Draw(ImConfig &cfg) {
5252

5353
// Options menu
5454
if (ImGui::BeginPopup("Options")) {
55-
ImGui::Checkbox("Auto-scroll", &AutoScroll);
55+
ImGui::Checkbox("Auto-scroll", &autoScroll_);
5656
ImGui::EndPopup();
5757
}
5858

@@ -61,7 +61,7 @@ void ImConsole::Draw(ImConfig &cfg) {
6161
if (ImGui::Button("Options"))
6262
ImGui::OpenPopup("Options");
6363
ImGui::SameLine();
64-
Filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
64+
filter_.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
6565
ImGui::Separator();
6666

6767
// Reserve enough left-over height for 1 separator + 1 input text
@@ -101,7 +101,7 @@ void ImConsole::Draw(ImConfig &cfg) {
101101
if (copy_to_clipboard)
102102
ImGui::LogToClipboard();
103103
for (const auto &item : g_lua.GetLines()) {
104-
if (!Filter.PassFilter(item.line.c_str()))
104+
if (!filter_.PassFilter(item.line.c_str()))
105105
continue;
106106
ImVec4 color;
107107
bool has_color = true;
@@ -138,9 +138,9 @@ void ImConsole::Draw(ImConfig &cfg) {
138138

139139
// Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame.
140140
// Using a scrollbar or mouse-wheel will take away from the bottom edge.
141-
if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
141+
if (scrollToBottom_ || (autoScroll_ && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
142142
ImGui::SetScrollHereY(1.0f);
143-
ScrollToBottom = false;
143+
scrollToBottom_ = false;
144144

145145
ImGui::PopStyleVar();
146146
}
@@ -156,8 +156,8 @@ void ImConsole::Draw(ImConfig &cfg) {
156156
// Command-line
157157
bool reclaim_focus = false;
158158
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_EscapeClearsAll | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
159-
if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this)) {
160-
char* s = InputBuf;
159+
if (ImGui::InputText("Input", inputBuf_, IM_ARRAYSIZE(inputBuf_), input_text_flags, &TextEditCallbackStub, (void*)this)) {
160+
char* s = inputBuf_;
161161
Strtrim(s);
162162
if (s[0])
163163
ExecCommand(s);
@@ -176,15 +176,15 @@ void ImConsole::Draw(ImConfig &cfg) {
176176
void ImConsole::ExecCommand(const char* command_line) {
177177
// Insert into history. First find match and delete it so it can be pushed to the back.
178178
// This isn't trying to be smart or optimal.
179-
HistoryPos = -1;
180-
for (int i = History.Size - 1; i >= 0; i--) {
181-
if (Stricmp(History[i], command_line) == 0) {
182-
ImGui::MemFree(History[i]);
183-
History.erase(History.begin() + i);
179+
historyPos_ = -1;
180+
for (int i = history_.Size - 1; i >= 0; i--) {
181+
if (Stricmp(history_[i], command_line) == 0) {
182+
ImGui::MemFree(history_[i]);
183+
history_.erase(history_.begin() + i);
184184
break;
185185
}
186186
}
187-
History.push_back(Strdup(command_line));
187+
history_.push_back(Strdup(command_line));
188188

189189
g_lua.Print(LogLineType::Cmd, std::string(command_line));
190190

@@ -196,15 +196,15 @@ void ImConsole::ExecCommand(const char* command_line) {
196196
g_lua.Print(LogLineType::Url, "https://www.lua.org/manual/5.3/");
197197
// TODO: Also print available Lua commands.
198198
} else if (Stricmp(command_line, "history") == 0) {
199-
int first = History.Size - 10;
200-
for (int i = first > 0 ? first : 0; i < History.Size; i++)
201-
g_lua.Print(StringFromFormat("%3d: %s", i, History[i]));
199+
int first = history_.Size - 10;
200+
for (int i = first > 0 ? first : 0; i < history_.Size; i++)
201+
g_lua.Print(StringFromFormat("%3d: %s", i, history_[i]));
202202
} else {
203203
g_lua.ExecuteConsoleCommand(command_line);
204204
}
205205

206206
// On command input, we scroll to bottom even if AutoScroll==false
207-
ScrollToBottom = true;
207+
scrollToBottom_ = true;
208208
}
209209

210210
int ImConsole::TextEditCallback(ImGuiInputTextCallbackData* data) {
@@ -279,21 +279,21 @@ int ImConsole::TextEditCallback(ImGuiInputTextCallbackData* data) {
279279
case ImGuiInputTextFlags_CallbackHistory:
280280
{
281281
// Example of HISTORY
282-
const int prev_history_pos = HistoryPos;
282+
const int prev_history_pos = historyPos_;
283283
if (data->EventKey == ImGuiKey_UpArrow) {
284-
if (HistoryPos == -1)
285-
HistoryPos = History.Size - 1;
286-
else if (HistoryPos > 0)
287-
HistoryPos--;
284+
if (historyPos_ == -1)
285+
historyPos_ = history_.Size - 1;
286+
else if (historyPos_ > 0)
287+
historyPos_--;
288288
} else if (data->EventKey == ImGuiKey_DownArrow) {
289-
if (HistoryPos != -1)
290-
if (++HistoryPos >= History.Size)
291-
HistoryPos = -1;
289+
if (historyPos_ != -1)
290+
if (++historyPos_ >= history_.Size)
291+
historyPos_ = -1;
292292
}
293293

294294
// A better implementation would preserve the data on the current input line along with cursor position.
295-
if (prev_history_pos != HistoryPos) {
296-
const char* history_str = (HistoryPos >= 0) ? History[HistoryPos] : "";
295+
if (prev_history_pos != historyPos_) {
296+
const char* history_str = (historyPos_ >= 0) ? history_[historyPos_] : "";
297297
data->DeleteChars(0, data->BufTextLen);
298298
data->InsertChars(0, history_str);
299299
}

UI/ImDebugger/ImConsole.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
#include "ext/imgui/imgui.h"
77

88
// Adapted from the ImGui demo.
9+
// Used to interact with Lua contexts.
10+
11+
// TODO: Add a selector to choose different Lua contexts (e.g. for different plugins or the global one).
12+
// Though loading multiple different plugins seems like a recipe for confusion.
913
class ImConsole {
1014
public:
1115
ImConsole();
1216
~ImConsole();
1317

1418
void Draw(ImConfig &cfg);
15-
void ExecCommand(const char* command_line);
19+
void ExecCommand(const char *command_line);
1620

17-
int TextEditCallback(ImGuiInputTextCallbackData* data);
21+
int TextEditCallback(ImGuiInputTextCallbackData *data);
1822

1923
private:
20-
char InputBuf[256];
21-
ImVector<char*> History;
22-
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
23-
ImGuiTextFilter Filter;
24-
bool AutoScroll;
25-
bool ScrollToBottom;
24+
char inputBuf_[512];
25+
ImVector<char*> history_;
26+
int historyPos_; // -1: new line, 0..History.Size-1 browsing history.
27+
ImGuiTextFilter filter_;
28+
bool autoScroll_;
29+
bool scrollToBottom_;
2630
};

0 commit comments

Comments
 (0)