mirror of
https://github.com/allankoechke/mbs.git
synced 2026-11-29 09:17:52 +00:00
Added example file
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -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-*/
|
||||
|
||||
@@ -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
21
examples/main.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user