migrate from std::filesystem::path to io::path (WIP)
This commit is contained in:
@@ -260,7 +260,7 @@ static int l_load_texture(lua::State* L) {
|
||||
|
||||
static int l_open_folder(lua::State* L) {
|
||||
auto path = engine->getPaths().resolve(lua::require_string(L, 1));
|
||||
platform::open_folder(path);
|
||||
platform::open_folder(io::resolve(path));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
namespace fs = std::filesystem;
|
||||
using namespace scripting;
|
||||
|
||||
static fs::path resolve_path(const std::string& path) {
|
||||
static io::path resolve_path(const std::string& path) {
|
||||
return engine->getPaths().resolve(path);
|
||||
}
|
||||
|
||||
static fs::path resolve_path_soft(const std::string& path) {
|
||||
static io::path resolve_path_soft(const std::string& path) {
|
||||
if (path.find(':') == std::string::npos) {
|
||||
return fs::u8path("");
|
||||
return "";
|
||||
}
|
||||
return engine->getPaths().resolve(path, false);
|
||||
}
|
||||
@@ -34,17 +34,17 @@ static int l_find(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_resolve(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushstring(L, path.u8string());
|
||||
io::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushstring(L, path.string());
|
||||
}
|
||||
|
||||
static int l_read(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (fs::is_regular_file(path)) {
|
||||
io::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (io::is_regular_file(path)) {
|
||||
return lua::pushstring(L, io::read_string(path));
|
||||
}
|
||||
throw std::runtime_error(
|
||||
"file does not exists " + util::quote(path.u8string())
|
||||
"file does not exists " + util::quote(path.string())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,9 +52,9 @@ static std::set<std::string> writeable_entry_points {
|
||||
"world", "export", "config"
|
||||
};
|
||||
|
||||
static fs::path get_writeable_path(lua::State* L) {
|
||||
static io::path get_writeable_path(lua::State* L) {
|
||||
std::string rawpath = lua::require_string(L, 1);
|
||||
fs::path path = resolve_path(rawpath);
|
||||
io::path path = resolve_path(rawpath);
|
||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
throw std::runtime_error("access denied");
|
||||
@@ -63,7 +63,7 @@ static fs::path get_writeable_path(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_write(lua::State* L) {
|
||||
fs::path path = get_writeable_path(L);
|
||||
io::path path = get_writeable_path(L);
|
||||
std::string text = lua::require_string(L, 2);
|
||||
io::write_string(path, text);
|
||||
return 1;
|
||||
@@ -71,62 +71,62 @@ static int l_write(lua::State* L) {
|
||||
|
||||
static int l_remove(lua::State* L) {
|
||||
std::string rawpath = lua::require_string(L, 1);
|
||||
fs::path path = resolve_path(rawpath);
|
||||
io::path path = resolve_path(rawpath);
|
||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
throw std::runtime_error("access denied");
|
||||
}
|
||||
return lua::pushboolean(L, fs::remove(path));
|
||||
return lua::pushboolean(L, io::remove(path));
|
||||
}
|
||||
|
||||
static int l_remove_tree(lua::State* L) {
|
||||
std::string rawpath = lua::require_string(L, 1);
|
||||
fs::path path = resolve_path(rawpath);
|
||||
io::path path = resolve_path(rawpath);
|
||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
throw std::runtime_error("access denied");
|
||||
}
|
||||
return lua::pushinteger(L, fs::remove_all(path));
|
||||
return lua::pushinteger(L, io::remove_all(path));
|
||||
}
|
||||
|
||||
static int l_exists(lua::State* L) {
|
||||
fs::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::exists(path));
|
||||
io::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, io::exists(path));
|
||||
}
|
||||
|
||||
static int l_isfile(lua::State* L) {
|
||||
fs::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::is_regular_file(path));
|
||||
io::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, io::is_regular_file(path));
|
||||
}
|
||||
|
||||
static int l_isdir(lua::State* L) {
|
||||
fs::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::is_directory(path));
|
||||
io::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, io::is_directory(path));
|
||||
}
|
||||
|
||||
static int l_length(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (fs::exists(path)) {
|
||||
return lua::pushinteger(L, fs::file_size(path));
|
||||
io::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (io::exists(path)) {
|
||||
return lua::pushinteger(L, io::file_size(path));
|
||||
} else {
|
||||
return lua::pushinteger(L, -1);
|
||||
}
|
||||
}
|
||||
|
||||
static int l_mkdir(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::create_directory(path));
|
||||
io::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, io::create_directories(path)); // FIXME
|
||||
}
|
||||
|
||||
static int l_mkdirs(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::create_directories(path));
|
||||
io::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, io::create_directories(path));
|
||||
}
|
||||
|
||||
static int l_read_bytes(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (fs::is_regular_file(path)) {
|
||||
size_t length = static_cast<size_t>(fs::file_size(path));
|
||||
io::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (io::is_regular_file(path)) {
|
||||
size_t length = static_cast<size_t>(io::file_size(path));
|
||||
|
||||
auto bytes = io::read_bytes(path, length);
|
||||
|
||||
@@ -140,12 +140,12 @@ static int l_read_bytes(lua::State* L) {
|
||||
return 1;
|
||||
}
|
||||
throw std::runtime_error(
|
||||
"file does not exists " + util::quote(path.u8string())
|
||||
"file does not exists " + util::quote(path.string())
|
||||
);
|
||||
}
|
||||
|
||||
static int l_write_bytes(lua::State* L) {
|
||||
fs::path path = get_writeable_path(L);
|
||||
io::path path = get_writeable_path(L);
|
||||
|
||||
if (auto bytearray = lua::touserdata<lua::LuaBytearray>(L, 2)) {
|
||||
auto& bytes = bytearray->data();
|
||||
@@ -176,15 +176,15 @@ static int l_list(lua::State* L) {
|
||||
if (dirname.find(':') == std::string::npos) {
|
||||
return l_list_all_res(L, dirname);
|
||||
}
|
||||
fs::path path = resolve_path(dirname);
|
||||
if (!fs::is_directory(path)) {
|
||||
io::path path = resolve_path(dirname);
|
||||
if (!io::is_directory(path)) {
|
||||
throw std::runtime_error(
|
||||
util::quote(path.u8string()) + " is not a directory"
|
||||
util::quote(path.string()) + " is not a directory"
|
||||
);
|
||||
}
|
||||
lua::createtable(L, 0, 0);
|
||||
size_t index = 1;
|
||||
for (auto& entry : fs::directory_iterator(path)) {
|
||||
for (auto& entry : fs::directory_iterator(io::resolve(path))) {
|
||||
auto name = entry.path().filename().u8string();
|
||||
auto file = dirname + "/" + name;
|
||||
lua::pushstring(L, file);
|
||||
@@ -240,7 +240,7 @@ static int l_read_combined_object(lua::State* L) {
|
||||
|
||||
static int l_is_writeable(lua::State* L) {
|
||||
std::string rawpath = lua::require_string(L, 1);
|
||||
fs::path path = resolve_path(rawpath);
|
||||
io::path path = resolve_path(rawpath);
|
||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
return lua::pushboolean(L, false);
|
||||
|
||||
@@ -38,8 +38,8 @@ static int l_load_fragment(lua::State* L) {
|
||||
const auto& paths = engine->getPaths();
|
||||
auto filename = lua::require_string(L, 1);
|
||||
auto path = paths.resolve(filename);
|
||||
if (!std::filesystem::exists(path)) {
|
||||
throw std::runtime_error("file "+path.u8string()+" does not exist");
|
||||
if (!io::exists(path)) {
|
||||
throw std::runtime_error("file "+path.string()+" does not exist");
|
||||
}
|
||||
auto map = io::read_binary_json(path);
|
||||
|
||||
|
||||
@@ -135,12 +135,12 @@ static int l_is_pressed(lua::State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static void resetPackBindings(fs::path& packFolder) {
|
||||
auto configFolder = packFolder/fs::path("config");
|
||||
auto bindsFile = configFolder/fs::path("bindings.toml");
|
||||
if (fs::is_regular_file(bindsFile)) {
|
||||
static void reset_pack_bindings(const io::path& packFolder) {
|
||||
auto configFolder = packFolder / "config";
|
||||
auto bindsFile = configFolder / "bindings.toml";
|
||||
if (io::is_regular_file(bindsFile)) {
|
||||
Events::loadBindings(
|
||||
bindsFile.u8string(),
|
||||
bindsFile.string(),
|
||||
io::read_string(bindsFile),
|
||||
BindType::REBIND
|
||||
);
|
||||
@@ -148,10 +148,9 @@ static void resetPackBindings(fs::path& packFolder) {
|
||||
}
|
||||
|
||||
static int l_reset_bindings(lua::State*) {
|
||||
auto resFolder = engine->getPaths().getResourcesFolder();
|
||||
resetPackBindings(resFolder);
|
||||
reset_pack_bindings("res:");
|
||||
for (auto& pack : engine->getContentPacks()) {
|
||||
resetPackBindings(pack.folder);
|
||||
reset_pack_bindings(pack.folder);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ static int l_pack_get_folder(lua::State* L) {
|
||||
|
||||
for (auto& pack : packs) {
|
||||
if (pack.id == packName) {
|
||||
return lua::pushstring(L, pack.folder.u8string() + "/");
|
||||
return lua::pushstring(L, pack.folder.string() + "/");
|
||||
}
|
||||
}
|
||||
return lua::pushstring(L, "");
|
||||
@@ -40,7 +40,7 @@ static int l_pack_get_installed(lua::State* L) {
|
||||
|
||||
/// @brief pack.get_available() -> array<string>
|
||||
static int l_pack_get_available(lua::State* L) {
|
||||
fs::path worldFolder("");
|
||||
io::path worldFolder;
|
||||
if (level) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
@@ -88,7 +88,7 @@ static int l_pack_get_info(
|
||||
auto assets = engine->getAssets();
|
||||
std::string icon = pack.id + ".icon";
|
||||
if (!AssetsLoader::loadExternalTexture(
|
||||
assets, icon, {pack.folder / fs::path("icon.png")}
|
||||
assets, icon, {pack.folder / "icon.png"}
|
||||
)) {
|
||||
icon = "gui/no_icon";
|
||||
}
|
||||
@@ -146,7 +146,7 @@ static int pack_get_infos(lua::State* L) {
|
||||
}
|
||||
}
|
||||
if (!ids.empty()) {
|
||||
fs::path worldFolder("");
|
||||
io::path worldFolder;
|
||||
if (level) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
@@ -188,7 +188,7 @@ static int l_pack_get_info(lua::State* L) {
|
||||
return pack.id == packid;
|
||||
});
|
||||
if (found == packs.end()) {
|
||||
fs::path worldFolder("");
|
||||
io::path worldFolder;
|
||||
if (level) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
@@ -225,7 +225,7 @@ static int l_pack_assemble(lua::State* L) {
|
||||
ids.push_back(lua::require_string(L, -1));
|
||||
lua::pop(L);
|
||||
}
|
||||
fs::path worldFolder("");
|
||||
io::path worldFolder;
|
||||
if (level) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ static int l_get_list(lua::State* L) {
|
||||
int versionMajor = versionMap["major"].asInteger();
|
||||
int versionMinor = versionMap["minor"].asInteger();
|
||||
|
||||
auto name = folder.filename().u8string();
|
||||
auto name = folder.name();
|
||||
lua::pushstring(L, name);
|
||||
lua::setfield(L, "name");
|
||||
|
||||
@@ -105,7 +105,7 @@ static int l_get_seed(lua::State* L) {
|
||||
static int l_exists(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto worldsDir = engine->getPaths().getWorldFolderByName(name);
|
||||
return lua::pushboolean(L, fs::is_directory(worldsDir));
|
||||
return lua::pushboolean(L, io::is_directory(worldsDir));
|
||||
}
|
||||
|
||||
static int l_is_day(lua::State* L) {
|
||||
|
||||
@@ -125,7 +125,7 @@ void lua::initialize(const EnginePaths& paths, const CoreParameters& params) {
|
||||
main_thread = create_state(
|
||||
paths, params.headless ? StateType::SCRIPT : StateType::BASE
|
||||
);
|
||||
lua::pushstring(main_thread, params.scriptFile.stem().u8string());
|
||||
lua::pushstring(main_thread, params.scriptFile.stem());
|
||||
lua::setglobal(main_thread, "__VC_SCRIPT_NAME");
|
||||
}
|
||||
|
||||
@@ -159,8 +159,7 @@ State* lua::create_state(const EnginePaths& paths, StateType stateType) {
|
||||
}
|
||||
init_state(L, stateType);
|
||||
|
||||
auto resDir = paths.getResourcesFolder();
|
||||
auto file = resDir / fs::u8path("scripts/stdmin.lua");
|
||||
auto file = "res:scripts/stdmin.lua";
|
||||
auto src = io::read_string(file);
|
||||
lua::pop(L, lua::execute(L, 0, src, "core:scripts/stdmin.lua"));
|
||||
return L;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "libs/api_lua.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
|
||||
@@ -68,7 +68,7 @@ static int l_dump(lua::State* L) {
|
||||
raster[i*3 + 2] = val;
|
||||
}
|
||||
}
|
||||
imageio::write(file.u8string(), &image);
|
||||
imageio::write(file, &image);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -41,12 +41,11 @@ const ContentIndices* scripting::indices = nullptr;
|
||||
BlocksController* scripting::blocks = nullptr;
|
||||
LevelController* scripting::controller = nullptr;
|
||||
|
||||
void scripting::load_script(const fs::path& name, bool throwable) {
|
||||
const auto& paths = scripting::engine->getPaths();
|
||||
fs::path file = paths.getResourcesFolder() / fs::path("scripts") / name;
|
||||
void scripting::load_script(const io::path& name, bool throwable) {
|
||||
io::path file = io::path("res:scripts") / name;
|
||||
std::string src = io::read_string(file);
|
||||
auto L = lua::get_main_state();
|
||||
lua::loadbuffer(L, 0, src, "core:scripts/"+name.u8string());
|
||||
lua::loadbuffer(L, 0, src, "core:scripts/"+name.string());
|
||||
if (throwable) {
|
||||
lua::call(L, 0, 0);
|
||||
} else {
|
||||
@@ -57,11 +56,11 @@ void scripting::load_script(const fs::path& name, bool throwable) {
|
||||
int scripting::load_script(
|
||||
int env,
|
||||
const std::string& type,
|
||||
const fs::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName
|
||||
) {
|
||||
std::string src = io::read_string(file);
|
||||
logger.info() << "script (" << type << ") " << file.u8string();
|
||||
logger.info() << "script (" << type << ") " << file.string();
|
||||
return lua::execute(lua::get_main_state(), env, src, fileName);
|
||||
}
|
||||
|
||||
@@ -69,8 +68,8 @@ void scripting::initialize(Engine* engine) {
|
||||
scripting::engine = engine;
|
||||
lua::initialize(engine->getPaths(), engine->getCoreParameters());
|
||||
|
||||
load_script(fs::path("stdlib.lua"), true);
|
||||
load_script(fs::path("classes.lua"), true);
|
||||
load_script(io::path("stdlib.lua"), true);
|
||||
load_script(io::path("classes.lua"), true);
|
||||
}
|
||||
|
||||
class LuaCoroutine : public Process {
|
||||
@@ -113,12 +112,12 @@ public:
|
||||
};
|
||||
|
||||
std::unique_ptr<Process> scripting::start_coroutine(
|
||||
const std::filesystem::path& script
|
||||
const io::path& script
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
if (lua::getglobal(L, "__vc_start_coroutine")) {
|
||||
auto source = io::read_string(script);
|
||||
lua::loadbuffer(L, 0, source, script.filename().u8string());
|
||||
lua::loadbuffer(L, 0, source, script.name());
|
||||
if (lua::call(L, 1)) {
|
||||
int id = lua::tointeger(L, -1);
|
||||
lua::pop(L, 2);
|
||||
@@ -253,8 +252,8 @@ void scripting::on_content_load(Content* content) {
|
||||
lua::setfield(L, "properties");
|
||||
lua::pop(L);
|
||||
}
|
||||
load_script(fs::path("post_content.lua"), true);
|
||||
load_script(fs::path("stdcmd.lua"), true);
|
||||
load_script("post_content.lua", true);
|
||||
load_script("stdcmd.lua", true);
|
||||
}
|
||||
|
||||
void scripting::on_world_load(LevelController* controller) {
|
||||
@@ -829,7 +828,7 @@ int scripting::get_values_on_stack() {
|
||||
void scripting::load_content_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
BlockFuncsSet& funcsset
|
||||
) {
|
||||
@@ -854,7 +853,7 @@ void scripting::load_content_script(
|
||||
void scripting::load_content_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
ItemFuncsSet& funcsset
|
||||
) {
|
||||
@@ -869,11 +868,11 @@ void scripting::load_content_script(
|
||||
}
|
||||
|
||||
void scripting::load_entity_component(
|
||||
const std::string& name, const fs::path& file, const std::string& fileName
|
||||
const std::string& name, const io::path& file, const std::string& fileName
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
std::string src = io::read_string(file);
|
||||
logger.info() << "script (component) " << file.u8string();
|
||||
logger.info() << "script (component) " << file.string();
|
||||
lua::loadbuffer(L, 0, src, fileName);
|
||||
lua::store_in(L, lua::CHUNKS_TABLE, name);
|
||||
}
|
||||
@@ -881,7 +880,7 @@ void scripting::load_entity_component(
|
||||
void scripting::load_world_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
WorldFuncsSet& funcsset
|
||||
) {
|
||||
@@ -917,7 +916,7 @@ void scripting::load_world_script(
|
||||
void scripting::load_layout_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
uidocscript& script
|
||||
) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "io/fwd.hpp"
|
||||
#include "data/dv.hpp"
|
||||
#include "delegates.hpp"
|
||||
#include "typedefs.hpp"
|
||||
@@ -61,7 +61,7 @@ namespace scripting {
|
||||
void process_post_runnables();
|
||||
|
||||
std::unique_ptr<Process> start_coroutine(
|
||||
const std::filesystem::path& script
|
||||
const io::path& script
|
||||
);
|
||||
|
||||
void on_world_load(LevelController* controller);
|
||||
@@ -150,7 +150,7 @@ namespace scripting {
|
||||
void load_content_script(
|
||||
const scriptenv& env,
|
||||
const std::string& prefix,
|
||||
const std::filesystem::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
BlockFuncsSet& funcsset
|
||||
);
|
||||
@@ -164,7 +164,7 @@ namespace scripting {
|
||||
void load_content_script(
|
||||
const scriptenv& env,
|
||||
const std::string& prefix,
|
||||
const std::filesystem::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
ItemFuncsSet& funcsset
|
||||
);
|
||||
@@ -175,13 +175,13 @@ namespace scripting {
|
||||
/// @param fileName script file path using the engine format
|
||||
void load_entity_component(
|
||||
const std::string& name,
|
||||
const std::filesystem::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName
|
||||
);
|
||||
|
||||
std::unique_ptr<GeneratorScript> load_generator(
|
||||
const GeneratorDef& def,
|
||||
const std::filesystem::path& file,
|
||||
const io::path& file,
|
||||
const std::string& dirPath
|
||||
);
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace scripting {
|
||||
void load_world_script(
|
||||
const scriptenv& env,
|
||||
const std::string& packid,
|
||||
const std::filesystem::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
WorldFuncsSet& funcsset
|
||||
);
|
||||
@@ -207,7 +207,7 @@ namespace scripting {
|
||||
void load_layout_script(
|
||||
const scriptenv& env,
|
||||
const std::string& prefix,
|
||||
const std::filesystem::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName,
|
||||
uidocscript& script
|
||||
);
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
#include "io/fwd.hpp"
|
||||
|
||||
namespace scripting {
|
||||
void load_script(const std::filesystem::path& name, bool throwable);
|
||||
void load_script(const io::path& name, bool throwable);
|
||||
|
||||
[[nodiscard]] int load_script(
|
||||
int env,
|
||||
const std::string& type,
|
||||
const std::filesystem::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ Hud* scripting::hud = nullptr;
|
||||
WorldRenderer* scripting::renderer = nullptr;
|
||||
|
||||
static void load_script(const std::string& name) {
|
||||
auto file = engine->getPaths().getResourcesFolder() / "scripts" / name;
|
||||
auto file = io::path("res:scripts") / name;
|
||||
std::string src = io::read_string(file);
|
||||
logger.info() << "loading script " << file.u8string();
|
||||
logger.info() << "loading script " << file.string();
|
||||
|
||||
lua::execute(lua::get_main_state(), 0, src, file.u8string());
|
||||
lua::execute(lua::get_main_state(), 0, src, file.string());
|
||||
}
|
||||
|
||||
void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
|
||||
@@ -80,12 +80,12 @@ void scripting::on_frontend_close() {
|
||||
void scripting::load_hud_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& packid,
|
||||
const fs::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName
|
||||
) {
|
||||
int env = *senv;
|
||||
std::string src = io::read_string(file);
|
||||
logger.info() << "loading script " << file.u8string();
|
||||
logger.info() << "loading script " << file.string();
|
||||
|
||||
lua::execute(lua::get_main_state(), env, src, fileName);
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
#include "io/fwd.hpp"
|
||||
|
||||
class Hud;
|
||||
class WorldRenderer;
|
||||
@@ -33,7 +31,7 @@ namespace scripting {
|
||||
void load_hud_script(
|
||||
const scriptenv& env,
|
||||
const std::string& packid,
|
||||
const fs::path& file,
|
||||
const io::path& file,
|
||||
const std::string& fileName
|
||||
);
|
||||
|
||||
|
||||
@@ -26,10 +26,15 @@ class LuaGeneratorScript : public GeneratorScript {
|
||||
const GeneratorDef& def;
|
||||
scriptenv env = nullptr;
|
||||
|
||||
fs::path file;
|
||||
io::path file;
|
||||
std::string dirPath;
|
||||
public:
|
||||
LuaGeneratorScript(State* L, const GeneratorDef& def, const fs::path& file, const std::string& dirPath)
|
||||
LuaGeneratorScript(
|
||||
State* L,
|
||||
const GeneratorDef& def,
|
||||
const io::path& file,
|
||||
const std::string& dirPath
|
||||
)
|
||||
: L(L), def(def), file(file), dirPath(dirPath) {
|
||||
}
|
||||
|
||||
@@ -54,10 +59,10 @@ public:
|
||||
|
||||
pop(L);
|
||||
|
||||
if (fs::exists(file)) {
|
||||
if (io::exists(file)) {
|
||||
std::string src = io::read_string(file);
|
||||
logger.info() << "script (generator) " << file.u8string();
|
||||
pop(L, execute(L, *env, src, file.u8string()));
|
||||
logger.info() << "script (generator) " << file.string();
|
||||
pop(L, execute(L, *env, src, file.string()));
|
||||
} else {
|
||||
// Use default (empty) script
|
||||
pop(L, execute(L, *env, "", "<empty>"));
|
||||
@@ -252,7 +257,7 @@ public:
|
||||
|
||||
std::unique_ptr<GeneratorScript> scripting::load_generator(
|
||||
const GeneratorDef& def,
|
||||
const fs::path& file,
|
||||
const io::path& file,
|
||||
const std::string& dirPath
|
||||
) {
|
||||
auto L = create_state(engine->getPaths(), StateType::GENERATOR);
|
||||
|
||||
Reference in New Issue
Block a user