migrate from std::filesystem::path to io::path (WIP)

This commit is contained in:
MihailRis
2025-01-30 22:23:13 +03:00
parent 1e22882284
commit e0314803c0
72 changed files with 1189 additions and 791 deletions
+17 -18
View File
@@ -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
) {