Added example file

This commit is contained in:
2026-03-19 17:28:13 +03:00
parent 87b131d12f
commit eedf714cb3
3 changed files with 25 additions and 6 deletions

5
.gitignore vendored
View File

@@ -31,11 +31,6 @@
*.out
*.app
# Autogenerated files
# Fixes errors when building on Windows with some IDEs
# Was initially writing this file to build dir but fails on some Windows builds
include/mantisbase/config.hpp
# CMake Build Directory
build/
cmake-build-*/

View File

@@ -16,7 +16,6 @@ FetchContent_Declare(
GIT_TAG v3.5.2
)
FetchContent_MakeAvailable(nlohmann_json Catch2)
add_library(mantis_script STATIC
src/lexer.cpp
src/parser.cpp
@@ -31,6 +30,10 @@ target_include_directories(mantis_script
)
target_link_libraries(mantis_script PUBLIC nlohmann_json::nlohmann_json)
add_executable(mbs-example examples/main.cpp)
target_link_libraries(mbs-example PUBLIC mantis_script)
add_executable(mantis_tests
tests/test_script.cpp
tests/test_extended.cpp

21
examples/main.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include <iostream>
#include <mantis/script.hpp>
#include <nlohmann/json.hpp>
using mantis::EvalErr;
using mantis::EvalOk;
using mantis::eval_true;
using mantis::eval_val;
using mantis::test;
using nlohmann::json;
int main() {
const std::string src = "1+1+@pi";
json ctx = json::object();
ctx["pi"] = 3.14;
const auto r = eval_val(src, ctx);
std::cout << "Res: " << std::holds_alternative<EvalOk>(r) << std::endl;
std::cout << "Res: " << std::get<EvalOk>(r).value << std::endl;
return 0;
}