mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31:49 +00:00
add app.start_debug_instance
This commit is contained in:
parent
9c429f7809
commit
31ea198301
3 changed files with 40 additions and 1 deletions
|
|
@ -1,6 +1,34 @@
|
|||
#include "api_lua.hpp"
|
||||
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "engine/EnginePaths.hpp"
|
||||
#include "network/Network.hpp"
|
||||
#include "util/platform.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);
|
||||
}
|
||||
|
||||
const luaL_Reg applib[] = {
|
||||
// see libcore.cpp an stdlib.lua
|
||||
{"start_debug_instance", lua::wrap<l_start_debug_instance>},
|
||||
// for other functions see libcore.cpp and stdlib.lua
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue