add app.start_debug_instance
This commit is contained in:
parent
9c429f7809
commit
31ea198301
@ -71,6 +71,14 @@ EnginePaths::EnginePaths(CoreParameters& params)
|
||||
io::create_subdevice("config", "user", "config");
|
||||
}
|
||||
|
||||
std::filesystem::path EnginePaths::getResourcesFolder() const {
|
||||
return resourcesFolder;
|
||||
}
|
||||
|
||||
std::filesystem::path EnginePaths::getUserFilesFolder() const {
|
||||
return userFilesFolder;
|
||||
}
|
||||
|
||||
io::path EnginePaths::getNewScreenshotFile(const std::string& ext) const {
|
||||
auto folder = SCREENSHOTS_FOLDER;
|
||||
if (!io::is_directory(folder)) {
|
||||
|
||||
@ -48,6 +48,9 @@ public:
|
||||
|
||||
EnginePaths(CoreParameters& params);
|
||||
|
||||
std::filesystem::path getResourcesFolder() const;
|
||||
std::filesystem::path getUserFilesFolder() const;
|
||||
|
||||
io::path getWorldFolderByName(const std::string& name);
|
||||
io::path getWorldsFolder() const;
|
||||
|
||||
|
||||
@ -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…
x
Reference in New Issue
Block a user