Add io functions

This commit is contained in:
Federico Cecchetto 2021-09-18 00:44:35 +02:00
parent 46fa43bec5
commit d46bac727d
4 changed files with 25 additions and 2 deletions

View File

@ -3,6 +3,7 @@
#include "game/game.hpp" #include "game/game.hpp"
#include "command.hpp"
#include "scheduler.hpp" #include "scheduler.hpp"
#include "scripting.hpp" #include "scripting.hpp"
@ -55,6 +56,7 @@ namespace scripting
void scr_load_level_stub() void scr_load_level_stub()
{ {
scr_load_level_hook.invoke<void>(); scr_load_level_hook.invoke<void>();
command::execute("reloadmenus");
lua::engine::start(); lua::engine::start();
} }

View File

@ -12,6 +12,7 @@
#include "../../../component/chat.hpp" #include "../../../component/chat.hpp"
#include <utils/string.hpp> #include <utils/string.hpp>
#include <utils/io.hpp>
namespace scripting::lua namespace scripting::lua
{ {
@ -32,6 +33,16 @@ namespace scripting::lua
{ {
state["level"] = entity{*game::levelEntityId}; state["level"] = entity{*game::levelEntityId};
state["io"]["fileexists"] = utils::io::file_exists;
state["io"]["writefile"] = utils::io::write_file;
state["io"]["filesize"] = utils::io::file_size;
state["io"]["createdirectory"] = utils::io::create_directory;
state["io"]["directoryexists"] = utils::io::directory_exists;
state["io"]["directoryisempty"] = utils::io::directory_is_empty;
state["io"]["listfiles"] = utils::io::list_files;
state["io"]["copyfolder"] = utils::io::copy_folder;
state["io"]["readfile"] = static_cast<std::string(*)(const std::string&)>(utils::io::read_file);
auto vector_type = state.new_usertype<vector>("vector", sol::constructors<vector(float, float, float)>()); auto vector_type = state.new_usertype<vector>("vector", sol::constructors<vector(float, float, float)>());
vector_type["x"] = sol::property(&vector::get_x, &vector::set_x); vector_type["x"] = sol::property(&vector::get_x, &vector::set_x);
vector_type["y"] = sol::property(&vector::get_y, &vector::set_y); vector_type["y"] = sol::property(&vector::get_y, &vector::set_y);

View File

@ -10,6 +10,7 @@
#include <utils/string.hpp> #include <utils/string.hpp>
#include <utils/nt.hpp> #include <utils/nt.hpp>
#include <utils/io.hpp>
namespace ui_scripting::lua namespace ui_scripting::lua
{ {
@ -65,7 +66,7 @@ namespace ui_scripting::lua
{ {
for (const auto c : name) for (const auto c : name)
{ {
if (!isalnum(c)) if (!isalnum(c) && c != '_')
{ {
return false; return false;
} }
@ -76,6 +77,16 @@ namespace ui_scripting::lua
void setup_types(sol::state& state, event_handler& handler, scheduler& scheduler) void setup_types(sol::state& state, event_handler& handler, scheduler& scheduler)
{ {
state["io"]["fileexists"] = utils::io::file_exists;
state["io"]["writefile"] = utils::io::write_file;
state["io"]["filesize"] = utils::io::file_size;
state["io"]["createdirectory"] = utils::io::create_directory;
state["io"]["directoryexists"] = utils::io::directory_exists;
state["io"]["directoryisempty"] = utils::io::directory_is_empty;
state["io"]["listfiles"] = utils::io::list_files;
state["io"]["copyfolder"] = utils::io::copy_folder;
state["io"]["readfile"] = static_cast<std::string(*)(const std::string&)>(utils::io::read_file);
auto vector_type = state.new_usertype<scripting::vector>("vector", sol::constructors<scripting::vector(float, float, float)>()); auto vector_type = state.new_usertype<scripting::vector>("vector", sol::constructors<scripting::vector(float, float, float)>());
vector_type["x"] = sol::property(&scripting::vector::get_x, &scripting::vector::set_x); vector_type["x"] = sol::property(&scripting::vector::get_x, &scripting::vector::set_x);
vector_type["y"] = sol::property(&scripting::vector::get_y, &scripting::vector::set_y); vector_type["y"] = sol::property(&scripting::vector::get_y, &scripting::vector::set_y);

View File

@ -39,7 +39,6 @@ launcher::mode detect_mode_from_arguments()
return launcher::mode::none; return launcher::mode::none;
} }
FARPROC load_binary(const launcher::mode mode, uint64_t* base_address) FARPROC load_binary(const launcher::mode mode, uint64_t* base_address)
{ {
loader loader; loader loader;