#include "variable_manager.h" #include "imgui/imgui.h" #include "imgui/imgui_stdlib.h" #include "common/widgets/json_editor.h" #include "libs/sol2/sol.hpp" #include "logger.h" #include "core/exception.h" #include namespace satdump { namespace ndsp { void LuaVariableManager::drawVariables() { widgets::JSONTableEditor(variables, "Variables"); } nlohmann::json LuaVariableManager::getVariable(std::string var_str) { sol::state lua; lua.open_libraries(sol::lib::string); lua.open_libraries(sol::lib::math); for (auto &j : variables.items()) { if (j.value().is_number()) { if (j.value().is_number_integer()) lua[j.key()] = j.value().get(); else lua[j.key()] = j.value().get(); } else if (j.value().is_string()) lua[j.key()] = j.value().get(); else logger->error("Type unsupported for Lua! : " + j.key()); } lua.script("output = " + var_str); printf("%s\n", sol::type_name(lua, lua["output"].get_type()).c_str()); sol::object o = lua["output"]; if (o.is()) return o.as(); // else if (o.is()) // TODOREWORK return o.as(); else if (o.is()) return o.as(); else if (o.is()) return o.as(); else { lua.open_libraries(sol::lib::base); lua.script("print(output)"); throw satdump_exception("Could not convert type from Lua to JSON"); } } } }