Merge pull request #671 from MihailRis/debugging-client
Debugging client
This commit is contained in:
@@ -2,12 +2,40 @@
|
||||
|
||||
#include "io/io.hpp"
|
||||
#include "io/devices/MemoryDevice.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "content/ContentControl.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "engine/EnginePaths.hpp"
|
||||
#include "network/Network.hpp"
|
||||
#include "util/platform.hpp"
|
||||
#include "window/Window.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_start_debug_instance(lua::State* L) {
|
||||
int port = lua::tointeger(L, 1);
|
||||
if (port == 0) {
|
||||
port = engine->getNetwork().findFreePort();
|
||||
if (port == -1) {
|
||||
throw std::runtime_error("could not find free port");
|
||||
}
|
||||
}
|
||||
const auto& paths = engine->getPaths();
|
||||
|
||||
std::vector<std::string> args {
|
||||
"--res", paths.getResourcesFolder().u8string(),
|
||||
"--dir", paths.getUserFilesFolder().u8string(),
|
||||
"--dbg-server", "tcp:" + std::to_string(port),
|
||||
};
|
||||
platform::new_engine_instance(std::move(args));
|
||||
return lua::pushinteger(L, port);
|
||||
}
|
||||
|
||||
static int l_focus(lua::State* L) {
|
||||
engine->getWindow().focus();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_create_memory_device(lua::State* L) {
|
||||
std::string name = lua::require_string(L, 1);
|
||||
if (io::get_device(name)) {
|
||||
@@ -54,10 +82,12 @@ static int l_reset_content_sources(lua::State* L) {
|
||||
}
|
||||
|
||||
const luaL_Reg applib[] = {
|
||||
{"start_debug_instance", lua::wrap<l_start_debug_instance>},
|
||||
{"focus", lua::wrap<l_focus>},
|
||||
{"create_memory_device", lua::wrap<l_create_memory_device>},
|
||||
{"get_content_sources", lua::wrap<l_get_content_sources>},
|
||||
{"set_content_sources", lua::wrap<l_set_content_sources>},
|
||||
{"reset_content_sources", lua::wrap<l_reset_content_sources>},
|
||||
// see libcore.cpp an stdlib.lua
|
||||
// for other functions see libcore.cpp and stdlib.lua
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "graphics/ui/gui_util.hpp"
|
||||
#include "graphics/ui/GUI.hpp"
|
||||
#include "graphics/ui/elements/Menu.hpp"
|
||||
#include "window/Window.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
@@ -299,6 +300,12 @@ static int l_capture_output(lua::State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_set_title(lua::State* L) {
|
||||
auto title = lua::require_string(L, 1);
|
||||
engine->getWindow().setTitle(title);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg corelib[] = {
|
||||
{"blank", lua::wrap<l_blank>},
|
||||
{"get_version", lua::wrap<l_get_version>},
|
||||
@@ -320,5 +327,6 @@ const luaL_Reg corelib[] = {
|
||||
{"open_url", lua::wrap<l_open_url>},
|
||||
{"quit", lua::wrap<l_quit>},
|
||||
{"capture_output", lua::wrap<l_capture_output>},
|
||||
{"set_title", lua::wrap<l_set_title>},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
@@ -173,7 +173,25 @@ static int l_get_line_at(lua::State* L) {
|
||||
auto node = get_document_node(L, 1);
|
||||
auto position = lua::tointeger(L, 2);
|
||||
if (auto box = dynamic_cast<TextBox*>(node.node.get())) {
|
||||
return lua::pushinteger(L, box->getLineAt(position));
|
||||
return lua::pushinteger(L, box->getLineAt(position) + 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_index_by_pos(lua::State* L) {
|
||||
auto node = get_document_node(L, 1);
|
||||
auto position = lua::tovec2(L, 2);
|
||||
if (auto box = dynamic_cast<TextBox*>(node.node.get())) {
|
||||
return lua::pushinteger(L, box->calcIndexAt(position.x, position.y));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_line_y(lua::State* L) {
|
||||
auto node = get_document_node(L, 1);
|
||||
auto line = lua::tointeger(L, 2);
|
||||
if (auto box = dynamic_cast<TextBox*>(node.node.get())) {
|
||||
return lua::pushinteger(L, box->getLineYOffset(line - 1));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -509,6 +527,12 @@ static int p_get_focused(UINode* node, lua::State* L) {
|
||||
static int p_get_line_at(UINode*, lua::State* L) {
|
||||
return lua::pushcfunction(L, l_get_line_at);
|
||||
}
|
||||
static int p_get_index_by_pos(UINode*, lua::State* L) {
|
||||
return lua::pushcfunction(L, l_get_index_by_pos);
|
||||
}
|
||||
static int p_get_line_y(UINode*, lua::State* L) {
|
||||
return lua::pushcfunction(L, l_get_line_y);
|
||||
}
|
||||
static int p_get_line_pos(UINode*, lua::State* L) {
|
||||
return lua::pushcfunction(L, l_get_line_pos);
|
||||
}
|
||||
@@ -619,6 +643,8 @@ static int l_gui_getattr(lua::State* L) {
|
||||
{"edited", p_get_edited},
|
||||
{"lineNumbers", p_get_line_numbers},
|
||||
{"lineAt", p_get_line_at},
|
||||
{"indexByPos", p_get_index_by_pos},
|
||||
{"lineY", p_get_line_y},
|
||||
{"linePos", p_get_line_pos},
|
||||
{"syntax", p_get_syntax},
|
||||
{"markup", p_get_markup},
|
||||
|
||||
@@ -50,8 +50,11 @@ static int l_add_callback(lua::State* L) {
|
||||
handler = input.addKeyCallback(key, actual_callback);
|
||||
}
|
||||
}
|
||||
auto callback = [&gui, actual_callback]() -> bool {
|
||||
if (!gui.isFocusCaught()) {
|
||||
|
||||
bool isTopLevel = lua::toboolean(L, 4);
|
||||
|
||||
auto callback = [&gui, actual_callback, isTopLevel]() -> bool {
|
||||
if (isTopLevel || !gui.isFocusCaught()) {
|
||||
return actual_callback();
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -410,7 +410,11 @@ static int l_get_total_download(lua::State* L, network::Network& network) {
|
||||
}
|
||||
|
||||
static int l_find_free_port(lua::State* L, network::Network& network) {
|
||||
return lua::pushinteger(L, network.findFreePort());
|
||||
int port = network.findFreePort();
|
||||
if (port == -1) {
|
||||
return 0;
|
||||
}
|
||||
return lua::pushinteger(L, port);
|
||||
}
|
||||
|
||||
static int l_set_nodelay(lua::State* L, network::Network& network) {
|
||||
|
||||
@@ -309,14 +309,15 @@ static int l_debug_sendvalue(lua::State* L) {
|
||||
|
||||
lua::pushnil(L);
|
||||
while (lua::next(L, 1)) {
|
||||
auto key = lua::tolstring(L, -2);
|
||||
lua::pushvalue(L, -2);
|
||||
|
||||
int type = lua::type(L, -1);
|
||||
auto key = lua::tolstring(L, -1);
|
||||
int type = lua::type(L, -2);
|
||||
table[std::string(key)] = dv::object({
|
||||
{"type", std::string(lua::type_name(L, type))},
|
||||
{"short", get_short_value(L, -1, type)},
|
||||
{"short", get_short_value(L, -2, type)},
|
||||
});
|
||||
lua::pop(L);
|
||||
lua::pop(L, 2);
|
||||
}
|
||||
lua::pop(L);
|
||||
value = std::move(table);
|
||||
|
||||
Reference in New Issue
Block a user