Use function class

This commit is contained in:
Federico Cecchetto
2021-06-19 22:17:41 +02:00
parent 7ac6443b2c
commit 97371d8f44
7 changed files with 105 additions and 38 deletions

View File

@ -20,13 +20,13 @@ namespace io
const auto path = game::Dvar_FindVar("fs_basegame")->current.string;
std::filesystem::current_path(path);
gsc::function::add("fremove", [](gsc::function_args args)
gsc::function::add("fremove", [](const gsc::function_args& args)
{
const auto path = args[0].as<const char*>();
return std::remove(path);
});
gsc::function::add("fopen", [](gsc::function_args args)
gsc::function::add("fopen", [](const gsc::function_args& args)
{
const auto* path = args[0].as<const char*>();
const auto* mode = args[1].as<const char*>();
@ -41,13 +41,13 @@ namespace io
return handle;
});
gsc::function::add("fclose", [](gsc::function_args args)
gsc::function::add("fclose", [](const gsc::function_args& args)
{
const auto handle = args[0].as_ptr<FILE>();
return fclose(handle);
});
gsc::function::add("fwrite", [](gsc::function_args args)
gsc::function::add("fwrite", [](const gsc::function_args& args)
{
const auto handle = args[0].as_ptr<FILE>();
const auto text = args[1].as<const char*>();
@ -55,7 +55,7 @@ namespace io
return fprintf(handle, text);
});
gsc::function::add("fread", [](gsc::function_args args)
gsc::function::add("fread", [](const gsc::function_args& args)
{
const auto handle = args[0].as_ptr<FILE>();
@ -74,13 +74,13 @@ namespace io
return result;
});
gsc::function::add("fileexists", [](gsc::function_args args)
gsc::function::add("fileexists", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::file_exists(path);
});
gsc::function::add("writefile", [](gsc::function_args args)
gsc::function::add("writefile", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
const auto data = args[1].as<std::string>();
@ -94,37 +94,37 @@ namespace io
return utils::io::write_file(path, data, append);
});
gsc::function::add("readfile", [](gsc::function_args args)
gsc::function::add("readfile", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::read_file(path);
});
gsc::function::add("filesize", [](gsc::function_args args)
gsc::function::add("filesize", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::file_size(path);
});
gsc::function::add("createdirectory", [](gsc::function_args args)
gsc::function::add("createdirectory", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::create_directory(path);
});
gsc::function::add("directoryexists", [](gsc::function_args args)
gsc::function::add("directoryexists", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::directory_exists(path);
});
gsc::function::add("directoryisempty", [](gsc::function_args args)
gsc::function::add("directoryisempty", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::directory_is_empty(path);
});
gsc::function::add("listfiles", [](gsc::function_args args)
gsc::function::add("listfiles", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
const auto files = utils::io::list_files(path);
@ -138,7 +138,7 @@ namespace io
return array.get_raw();
});
gsc::function::add("copyfolder", [](gsc::function_args args)
gsc::function::add("copyfolder", [](const gsc::function_args& args)
{
const auto source = args[0].as<std::string>();
const auto target = args[1].as<std::string>();