mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Add new log category for script. Rename member variables in ImConsole to match style.
This commit is contained in:
@@ -59,6 +59,7 @@ enum class Log {
|
||||
IAP,
|
||||
CwCheats,
|
||||
Net, // Non-sce related networking logs.
|
||||
Script,
|
||||
|
||||
sceAudio,
|
||||
sceCtrl,
|
||||
|
||||
@@ -98,6 +98,7 @@ static const char * const g_logTypeNames[] = {
|
||||
"IAP",
|
||||
"CWCHEATS",
|
||||
"NET",
|
||||
"SCRIPT",
|
||||
"SCEAUDIO",
|
||||
"SCECTRL",
|
||||
"SCEDISP",
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
IFileSystem *GetSystem(std::string_view prefix);
|
||||
IFileSystem *GetSystemFromFilename(std::string_view filename);
|
||||
IFileSystem *GetHandleOwner(u32 handle) const;
|
||||
FileSystemFlags FlagsFromFilename(std::string_view &filename) {
|
||||
FileSystemFlags FlagsFromFilename(std::string_view filename) {
|
||||
const IFileSystem *sys = GetSystemFromFilename(filename);
|
||||
return sys ? sys->Flags() : FileSystemFlags::NONE;
|
||||
}
|
||||
|
||||
@@ -232,6 +232,8 @@ bool Load(PSPModule *pluginWaitingModule, SceUID threadID) {
|
||||
INFO_LOG(Log::System, "Loaded plugin: '%s'", plugin.name.c_str());
|
||||
}
|
||||
|
||||
bool anyLua = false;
|
||||
|
||||
for (LuaPlugin &luaPlugin : luaPlugins) {
|
||||
if (!g_Config.bEnablePlugins) {
|
||||
WARN_LOG(Log::System, "Plugins are disabled, ignoring enabled Lua plugin %s", luaPlugin.filename.c_str());
|
||||
@@ -247,9 +249,15 @@ bool Load(PSPModule *pluginWaitingModule, SceUID threadID) {
|
||||
s.resize(luaCodeBytes.size());
|
||||
memcpy(s.data(), luaCodeBytes.data(), luaCodeBytes.size());
|
||||
luaPlugin.context->RunCode(s);
|
||||
|
||||
anyLua = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (anyLua) {
|
||||
g_OSD.Show(OSDType::MESSAGE_WARNING, "Lua plugins are EXPERIMENTAL and the lua API WILL CHANGE in future versions!", 4.0f);
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(g_inputMutex);
|
||||
PluginDataKeys.clear();
|
||||
return started;
|
||||
|
||||
+7
-7
@@ -32,19 +32,19 @@ static bool IsProbablyExpression(std::string_view input) {
|
||||
|
||||
// TODO: Should these also echo to the console?
|
||||
static void debug(const char *message) {
|
||||
DEBUG_LOG(Log::System, "%s", message);
|
||||
DEBUG_LOG(Log::Script, "%s", message);
|
||||
}
|
||||
|
||||
static void info(const char *message) {
|
||||
INFO_LOG(Log::System, "%s", message);
|
||||
INFO_LOG(Log::Script, "%s", message);
|
||||
}
|
||||
|
||||
static void warn(const char *message) {
|
||||
WARN_LOG(Log::System, "%s", message);
|
||||
WARN_LOG(Log::Script, "%s", message);
|
||||
}
|
||||
|
||||
static void error(const char *message) {
|
||||
ERROR_LOG(Log::System, "%s", message);
|
||||
ERROR_LOG(Log::Script, "%s", message);
|
||||
}
|
||||
|
||||
static int gpr(int reg) {
|
||||
@@ -417,7 +417,7 @@ void LuaContext::RunCode(const std::string &code) {
|
||||
Print(LogLineType::Error, err.what());
|
||||
}
|
||||
} catch (const sol::error& e) {
|
||||
ERROR_LOG(Log::System, "Lua exception: %s", e.what());
|
||||
ERROR_LOG(Log::Script, "Lua exception: %s", e.what());
|
||||
Print(LogLineType::Error, e.what());
|
||||
}
|
||||
}
|
||||
@@ -463,7 +463,7 @@ void LuaContext::PrintF(LogLineType type, const char* fmt, ...) {
|
||||
}
|
||||
|
||||
void LuaContext::Print(LogLineType type, std::string_view text) {
|
||||
INFO_LOG(Log::System, "%.*s", (int)text.size(), text.data());
|
||||
INFO_LOG(Log::Script, "%.*s", (int)text.size(), text.data());
|
||||
}
|
||||
|
||||
void LuaInteractiveContext::Print(LogLineType type, std::string_view text) {
|
||||
@@ -561,7 +561,7 @@ void LuaInteractiveContext::ExecuteConsoleCommand(std::string_view cmd) {
|
||||
lines_.push_back(LuaLogLine{ LogLineType::Error, std::string(err.what()) });
|
||||
}
|
||||
} catch (const sol::error& e) {
|
||||
ERROR_LOG(Log::System, "Lua exception: %s", e.what());
|
||||
ERROR_LOG(Log::Script, "Lua exception: %s", e.what());
|
||||
lines_.push_back(LuaLogLine{ LogLineType::Error, std::string(e.what()) });
|
||||
}
|
||||
}
|
||||
|
||||
+33
-33
@@ -8,18 +8,18 @@
|
||||
#include "Common/StringUtils.h"
|
||||
|
||||
ImConsole::ImConsole() {
|
||||
memset(InputBuf, 0, sizeof(InputBuf));
|
||||
memset(inputBuf_, 0, sizeof(inputBuf_));
|
||||
|
||||
HistoryPos = -1;
|
||||
historyPos_ = -1;
|
||||
|
||||
// "CLASSIFY" is here to provide the test case where "C"+[tab] completes to "CL" and display multiple matches.
|
||||
AutoScroll = true;
|
||||
ScrollToBottom = false;
|
||||
autoScroll_ = true;
|
||||
scrollToBottom_ = false;
|
||||
}
|
||||
|
||||
ImConsole::~ImConsole() {
|
||||
for (int i = 0; i < History.Size; i++)
|
||||
ImGui::MemFree(History[i]);
|
||||
for (int i = 0; i < history_.Size; i++)
|
||||
ImGui::MemFree(history_[i]);
|
||||
}
|
||||
|
||||
// Portable helpers
|
||||
@@ -52,7 +52,7 @@ void ImConsole::Draw(ImConfig &cfg) {
|
||||
|
||||
// Options menu
|
||||
if (ImGui::BeginPopup("Options")) {
|
||||
ImGui::Checkbox("Auto-scroll", &AutoScroll);
|
||||
ImGui::Checkbox("Auto-scroll", &autoScroll_);
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ void ImConsole::Draw(ImConfig &cfg) {
|
||||
if (ImGui::Button("Options"))
|
||||
ImGui::OpenPopup("Options");
|
||||
ImGui::SameLine();
|
||||
Filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
|
||||
filter_.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
|
||||
ImGui::Separator();
|
||||
|
||||
// Reserve enough left-over height for 1 separator + 1 input text
|
||||
@@ -101,7 +101,7 @@ void ImConsole::Draw(ImConfig &cfg) {
|
||||
if (copy_to_clipboard)
|
||||
ImGui::LogToClipboard();
|
||||
for (const auto &item : g_lua.GetLines()) {
|
||||
if (!Filter.PassFilter(item.line.c_str()))
|
||||
if (!filter_.PassFilter(item.line.c_str()))
|
||||
continue;
|
||||
ImVec4 color;
|
||||
bool has_color = true;
|
||||
@@ -138,9 +138,9 @@ void ImConsole::Draw(ImConfig &cfg) {
|
||||
|
||||
// Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame.
|
||||
// Using a scrollbar or mouse-wheel will take away from the bottom edge.
|
||||
if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
|
||||
if (scrollToBottom_ || (autoScroll_ && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
ScrollToBottom = false;
|
||||
scrollToBottom_ = false;
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
@@ -156,8 +156,8 @@ void ImConsole::Draw(ImConfig &cfg) {
|
||||
// Command-line
|
||||
bool reclaim_focus = false;
|
||||
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_EscapeClearsAll | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
|
||||
if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), input_text_flags, &TextEditCallbackStub, (void*)this)) {
|
||||
char* s = InputBuf;
|
||||
if (ImGui::InputText("Input", inputBuf_, IM_ARRAYSIZE(inputBuf_), input_text_flags, &TextEditCallbackStub, (void*)this)) {
|
||||
char* s = inputBuf_;
|
||||
Strtrim(s);
|
||||
if (s[0])
|
||||
ExecCommand(s);
|
||||
@@ -176,15 +176,15 @@ void ImConsole::Draw(ImConfig &cfg) {
|
||||
void ImConsole::ExecCommand(const char* command_line) {
|
||||
// Insert into history. First find match and delete it so it can be pushed to the back.
|
||||
// This isn't trying to be smart or optimal.
|
||||
HistoryPos = -1;
|
||||
for (int i = History.Size - 1; i >= 0; i--) {
|
||||
if (Stricmp(History[i], command_line) == 0) {
|
||||
ImGui::MemFree(History[i]);
|
||||
History.erase(History.begin() + i);
|
||||
historyPos_ = -1;
|
||||
for (int i = history_.Size - 1; i >= 0; i--) {
|
||||
if (Stricmp(history_[i], command_line) == 0) {
|
||||
ImGui::MemFree(history_[i]);
|
||||
history_.erase(history_.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
History.push_back(Strdup(command_line));
|
||||
history_.push_back(Strdup(command_line));
|
||||
|
||||
g_lua.Print(LogLineType::Cmd, std::string(command_line));
|
||||
|
||||
@@ -196,15 +196,15 @@ void ImConsole::ExecCommand(const char* command_line) {
|
||||
g_lua.Print(LogLineType::Url, "https://www.lua.org/manual/5.3/");
|
||||
// TODO: Also print available Lua commands.
|
||||
} else if (Stricmp(command_line, "history") == 0) {
|
||||
int first = History.Size - 10;
|
||||
for (int i = first > 0 ? first : 0; i < History.Size; i++)
|
||||
g_lua.Print(StringFromFormat("%3d: %s", i, History[i]));
|
||||
int first = history_.Size - 10;
|
||||
for (int i = first > 0 ? first : 0; i < history_.Size; i++)
|
||||
g_lua.Print(StringFromFormat("%3d: %s", i, history_[i]));
|
||||
} else {
|
||||
g_lua.ExecuteConsoleCommand(command_line);
|
||||
}
|
||||
|
||||
// On command input, we scroll to bottom even if AutoScroll==false
|
||||
ScrollToBottom = true;
|
||||
scrollToBottom_ = true;
|
||||
}
|
||||
|
||||
int ImConsole::TextEditCallback(ImGuiInputTextCallbackData* data) {
|
||||
@@ -279,21 +279,21 @@ int ImConsole::TextEditCallback(ImGuiInputTextCallbackData* data) {
|
||||
case ImGuiInputTextFlags_CallbackHistory:
|
||||
{
|
||||
// Example of HISTORY
|
||||
const int prev_history_pos = HistoryPos;
|
||||
const int prev_history_pos = historyPos_;
|
||||
if (data->EventKey == ImGuiKey_UpArrow) {
|
||||
if (HistoryPos == -1)
|
||||
HistoryPos = History.Size - 1;
|
||||
else if (HistoryPos > 0)
|
||||
HistoryPos--;
|
||||
if (historyPos_ == -1)
|
||||
historyPos_ = history_.Size - 1;
|
||||
else if (historyPos_ > 0)
|
||||
historyPos_--;
|
||||
} else if (data->EventKey == ImGuiKey_DownArrow) {
|
||||
if (HistoryPos != -1)
|
||||
if (++HistoryPos >= History.Size)
|
||||
HistoryPos = -1;
|
||||
if (historyPos_ != -1)
|
||||
if (++historyPos_ >= history_.Size)
|
||||
historyPos_ = -1;
|
||||
}
|
||||
|
||||
// A better implementation would preserve the data on the current input line along with cursor position.
|
||||
if (prev_history_pos != HistoryPos) {
|
||||
const char* history_str = (HistoryPos >= 0) ? History[HistoryPos] : "";
|
||||
if (prev_history_pos != historyPos_) {
|
||||
const char* history_str = (historyPos_ >= 0) ? history_[historyPos_] : "";
|
||||
data->DeleteChars(0, data->BufTextLen);
|
||||
data->InsertChars(0, history_str);
|
||||
}
|
||||
|
||||
@@ -8,21 +8,25 @@
|
||||
struct ImConfig;
|
||||
|
||||
// Adapted from the ImGui demo.
|
||||
// Used to interact with Lua contexts.
|
||||
|
||||
// TODO: Add a selector to choose different Lua contexts (e.g. for different plugins or the global one).
|
||||
// Though loading multiple different plugins seems like a recipe for confusion.
|
||||
class ImConsole {
|
||||
public:
|
||||
ImConsole();
|
||||
~ImConsole();
|
||||
|
||||
void Draw(ImConfig &cfg);
|
||||
void ExecCommand(const char* command_line);
|
||||
void ExecCommand(const char *command_line);
|
||||
|
||||
int TextEditCallback(ImGuiInputTextCallbackData* data);
|
||||
int TextEditCallback(ImGuiInputTextCallbackData *data);
|
||||
|
||||
private:
|
||||
char InputBuf[256];
|
||||
ImVector<char*> History;
|
||||
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
|
||||
ImGuiTextFilter Filter;
|
||||
bool AutoScroll;
|
||||
bool ScrollToBottom;
|
||||
char inputBuf_[512];
|
||||
ImVector<char*> history_;
|
||||
int historyPos_; // -1: new line, 0..History.Size-1 browsing history.
|
||||
ImGuiTextFilter filter_;
|
||||
bool autoScroll_;
|
||||
bool scrollToBottom_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user