-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:frate-dev/frate into dev
- Loading branch information
Showing
7 changed files
with
186 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <Frate/LuaAPI.hpp> | ||
|
||
|
||
namespace Frate::LuaAPI { | ||
std::string FrateApi::format(const std::string &str, sol::variadic_args var_args) { | ||
std::vector<std::string> args; | ||
std::string result; | ||
|
||
for (const auto &arg : var_args) { | ||
if (arg.is<std::string>()) { | ||
args.push_back(arg.as<std::string>()); | ||
} else if (arg.is<int>()) { | ||
args.push_back(std::to_string(arg.as<int>())); | ||
} else if (arg.is<bool>()) { | ||
args.push_back(arg.as<bool>() ? "true" : "false"); | ||
} else if (arg.is<float>()) { | ||
args.push_back(std::to_string(arg.as<float>())); | ||
} else { | ||
args.push_back("nil"); | ||
} | ||
} | ||
|
||
for (size_t i = 0; i < str.size(); i++) { | ||
if (str[i] == '{') { | ||
if (str[i + 1] == '{') { | ||
result += '{'; | ||
i++; | ||
} else { | ||
size_t j = i + 1; | ||
while (j < str.size() && str[j] != '}') { | ||
j++; | ||
} | ||
if (j == str.size()) { | ||
throw std::runtime_error("Invalid format string"); | ||
} | ||
std::string index = str.substr(i + 1, j - i - 1); | ||
if (index == "0") { | ||
result += args[0]; | ||
} else { | ||
int idx = std::stoi(index); | ||
if (idx < 1 || idx > args.size()) { | ||
throw std::runtime_error("Invalid format string"); | ||
} | ||
result += args[idx - 1]; | ||
} | ||
i = j; | ||
} | ||
} else { | ||
result += str[i]; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <Frate/LuaAPI.hpp> | ||
#include <Frate/Constants.hpp> | ||
namespace Frate::LuaAPI { | ||
using std::filesystem::path; | ||
std::string FrateApi::get_os() { | ||
return Frate::Constants::BUILD_OS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <Frate/LuaAPI.hpp> | ||
#include <filesystem> | ||
namespace Frate::LuaAPI { | ||
std::string FrateApi::get_path() { | ||
return std::filesystem::current_path().string() | ||
#ifdef DEBUG | ||
+ "/build" | ||
#endif | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <Frate/LuaAPI.hpp> | ||
#include <filesystem> | ||
|
||
namespace Frate::LuaAPI { | ||
std::vector<std::string> FrateApi::get_paths_recurse(std::string input_path) { | ||
std::filesystem::path deepest_path = std::filesystem::current_path(); | ||
info << "Getting paths from " << input_path << std::endl; | ||
//check if path is absolute | ||
if (input_path[0] != '/') { | ||
error << "Frate Lua Api Error: Path in get_paths_recurse must be absolute" << std::endl; | ||
exit(1); | ||
} | ||
|
||
if(input_path.find(deepest_path.string()) == std::string::npos){ | ||
error << "Frate Lua Api Error: Path in get_paths_recurse must be in project directory" << std::endl; | ||
exit(1); | ||
} | ||
|
||
|
||
std::vector<std::string> paths; | ||
for (const auto &p : std::filesystem::recursive_directory_iterator(input_path)) { | ||
paths.push_back(p.path().string()); | ||
} | ||
|
||
return paths; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <Frate/LuaAPI.hpp> | ||
|
||
namespace Frate::LuaAPI { | ||
bool registerProject(sol::state &lua, std::shared_ptr<Command::Project> pro) { | ||
|
||
lua.set("project", pro); | ||
lua.new_usertype<Command::Package>("Package", | ||
"new", sol::no_constructor, | ||
"name", &Command::Package::name, | ||
"git", &Command::Package::git, | ||
"git_short", &Command::Package::git_short, | ||
"git_prefixed", &Command::Package::git_prefixed, | ||
"selected_version", &Command::Package::selected_version, | ||
"versions", &Command::Package::versions, | ||
"target_link", &Command::Package::target_link, | ||
"description", &Command::Package::description, | ||
"selected_version", &Command::Package::selected_version, | ||
"git_description", &Command::Package::git_description, | ||
"language", &Command::Package::language, | ||
"license", &Command::Package::license, | ||
"owner", &Command::Package::owner, | ||
"owner_type", &Command::Package::owner_type, | ||
"stars", &Command::Package::stars, | ||
"forks", &Command::Package::forks, | ||
"open_issues", &Command::Package::open_issues, | ||
"watchers", &Command::Package::watchers | ||
); | ||
|
||
lua.new_usertype<Command::Mode>("Mode", | ||
"new", sol::no_constructor, | ||
"name", &Command::Mode::name, | ||
"flags", &Command::Mode::flags, | ||
"dependencies", &Command::Mode::dependencies | ||
); | ||
|
||
|
||
lua.new_usertype<Command::Project>("Project" | ||
"new", sol::no_constructor, | ||
"name", &Command::Project::project_name, | ||
"version", &Command::Project::project_version, | ||
"description", &Command::Project::project_description, | ||
"authors", &Command::Project::authors, | ||
"dependencies", &Command::Project::dependencies, | ||
"toolchains", &Command::Project::toolchains, | ||
"flags", &Command::Project::flags, | ||
"modes", &Command::Project::modes, | ||
"libs", &Command::Project::libs, | ||
"license", &Command::Project::license, | ||
"git", &Command::Project::git, | ||
"cmake_version", &Command::Project::cmake_version, | ||
"build_dir", &Command::Project::build_dir, | ||
"src_dir", &Command::Project::src_dir, | ||
"include_dir", &Command::Project::include_dir, | ||
"lang_version", &Command::Project::lang_version, | ||
"lang", &Command::Project::lang, | ||
"project_type", &Command::Project::project_type, | ||
"keywords", &Command::Project::keywords, | ||
"prompts", &Command::Project::prompts | ||
); | ||
|
||
lua.new_usertype<Command::ProjectPrompt>("ProjectPrompt", | ||
"value", &Command::ProjectPrompt::value, | ||
"default", &Command::ProjectPrompt::default_value, | ||
"getstr", &Command::ProjectPrompt::get<std::string>, | ||
"getint", &Command::ProjectPrompt::get<int>, | ||
"getbool", &Command::ProjectPrompt::get<bool>, | ||
"getfloat", &Command::ProjectPrompt::get<float> | ||
); | ||
|
||
|
||
|
||
return true; | ||
} | ||
} |