Skip to content

Commit

Permalink
Merge branch 'main' into Keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Mar 7, 2024
2 parents 4f446a8 + 46e4655 commit f989796
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 37 deletions.
14 changes: 12 additions & 2 deletions src/game_api/script/lua_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "lua_libs/lua_libs.hpp" // for require_serpent_lua
#include "lua_vm.hpp" // for execute_lua, expose_unsafe_libraries
#include "script/lua_backend.hpp" // for LuaBackend
#include "util.hpp" // for ON_SCOPE_EXIT

class SoundManager;

Expand Down Expand Up @@ -1047,8 +1048,17 @@ ConsoleResult LuaConsole::execute(std::string str, bool raw)
if (res.get_type() == sol::type::nil || res.get_type() == sol::type::none)
return ConsoleResult{"", false};

sol::function dump_string = lua["dump_string"];
return ConsoleResult{dump_string(res, 2), false};
LuaBackend::push_calling_backend(this);
ON_SCOPE_EXIT(LuaBackend::pop_calling_backend(this));

sol::protected_function dump_string = lua["dump_string"];
sol::protected_function_result out = dump_string(res, 2);
if (!out.valid())
{
sol::error err = out;
return ConsoleResult{err.what(), true};
}
return ConsoleResult{out, false};
}

sol::protected_function_result LuaConsole::execute_raw(std::string str)
Expand Down
27 changes: 1 addition & 26 deletions src/game_api/script/script_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,7 @@ std::string sanitize(std::string data)
return data;
}

int InputTextCallback(ImGuiInputTextCallbackData* data)
{
InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData;
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
{
std::string* str = user_data->Str;
IM_ASSERT(data->Buf == str->c_str());
str->resize(data->BufTextLen);
data->Buf = (char*)str->c_str();
}
else if (user_data->ChainCallback)
{
data->UserData = user_data->ChainCallbackUserData;
return user_data->ChainCallback(data);
}
return 0;
}

bool InputString(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
{
IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
flags |= ImGuiInputTextFlags_CallbackResize;

InputTextCallback_UserData cb_user_data;
cb_user_data.Str = str;
cb_user_data.ChainCallback = callback;
cb_user_data.ChainCallbackUserData = user_data;
return ImGui::InputText(label, str, flags, InputTextCallback, &cb_user_data);
return ImGui::InputText(label, str, flags, callback, user_data);
}
9 changes: 0 additions & 9 deletions src/game_api/script/script_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,4 @@ void AddImageRotated(ImDrawList* draw_list, ImTextureID user_texture_id, const I

std::string sanitize(std::string data);

struct InputTextCallback_UserData
{
std::string* Str;
ImGuiInputTextCallback ChainCallback;
void* ChainCallbackUserData;
};

int InputTextCallback(ImGuiInputTextCallbackData* data);

bool InputString(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data);

0 comments on commit f989796

Please sign in to comment.