Skip to content

Commit

Permalink
embedding lua in crap
Browse files Browse the repository at this point in the history
  • Loading branch information
lsproule committed Dec 7, 2023
1 parent d98d9c1 commit fda612c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ CPMAddPackage(
CPMAddPackage(
lua
GITHUB_REPOSITORY lua/lua
GIT_TAG v5.4.3
GIT_TAG v5.4.4
)

CPMAddPackage(
Expand Down Expand Up @@ -151,7 +151,6 @@ else()
add_definitions(-DDEBUG)
message("Default mode")
endif()

target_link_libraries(${PROJECT_NAME} libcurl)
target_link_libraries(${PROJECT_NAME} cxxopts)
target_link_libraries(${PROJECT_NAME} nlohmann_json)
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Actions/List.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <Frate/Command/Actions/List.hpp>
#include <Frate/Command/License.hpp>
#include <Frate/Command/Modes.hpp>
#include <Frate/Command/Author.hpp>.hpp>
#include <Frate/Command/Author.hpp>
#include <Frate/Command/Flags.hpp>
#include <Frate/Command/Package.hpp>
#include <Frate/Command/RemoteServers.hpp>
Expand Down
Empty file added src/Command/Library/Library.cpp
Empty file.
Empty file added src/Command/Library/add.cpp
Empty file.
20 changes: 19 additions & 1 deletion src/Generators/CMakeTemplates.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <filesystem>
#include <map>
#include <string>
#include <nlohmann/json.hpp>
#include <Frate/Command.hpp>
#include <Frate/Utils/General.hpp>
#include <sol/sol.hpp>
#include <git2.h>
#include <inja.hpp>

Expand Down Expand Up @@ -30,7 +32,23 @@ namespace Frate::Generators::CMakeList {

CPMFile << CPM;
inja::Environment env;

sol::state lua;
lua.open_libraries(sol::lib::base, sol::lib::package);

auto render = [&env](std::string str, sol::table data){
json j;
data.for_each([&j](sol::object key, sol::object value){
j[key.as<std::string>()] = value.as<std::string>();
});
std::cout << j.dump(2) << std::endl;
std::cout << str << std::endl;
return env.render(str, j);
};
lua["render"] = render;
lua.script(R"(
print(render("{{name}}", {name = "Frate"}))
)");
//env.add_callback()
std::string CMakeListsExecutable = env.render_file(pro->project_path /"templates" /"CMakeLists.tmpl", pro->toJson());
std::ofstream file;
std::string file_name = "CMakeLists.txt";
Expand Down

0 comments on commit fda612c

Please sign in to comment.