Created
March 14, 2018 10:41
-
-
Save ThePhD/ea5d3a0a8e5c3fb4e36c3bec0ad16f7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #define SOL_CHECK_ARGUMENTS 1 | |
| #include <sol.hpp> | |
| #include <string> | |
| #include <iostream> | |
| #include "catch_mock.hpp" | |
| #include <unordered_set> | |
| #include <unordered_map> | |
| int main() { | |
| struct Engine { | |
| std::unordered_multimap<int, std::pair<std::string, std::string>> breakingpoints; | |
| void load_breakingpoints(std::unordered_multimap<int, std::pair<std::string, std::string>> breakingpoints) { | |
| this->breakingpoints = std::move(breakingpoints); | |
| } | |
| }; | |
| { | |
| Engine e; | |
| e.load_breakingpoints({ | |
| {0, {"the base", "for all things, right?"}}, | |
| {1, {"a", "a lot of text goes here,"}}, | |
| {1, {"b", "and junk, you know?"}}, | |
| {3, {"super duper", "price model"}}, | |
| {4, {"j", "k"}}, | |
| }); | |
| { | |
| sol::state lua; | |
| lua.set_function("get_breakpoint", [](Engine &e, int line, sol::this_state ts) { | |
| sol::state_view lua(ts); | |
| auto range = e.breakingpoints.equal_range(line); | |
| sol::table ret = lua.create_table(); | |
| for (auto i = range.first; i != range.second; ++i) { | |
| ret[i->second.first] = i->second.second; | |
| } | |
| return ret; | |
| }); | |
| lua.set("e", std::move(e)); | |
| lua.script("t = get_breakpoint(e, 1)"); | |
| sol::table t = lua["t"]; | |
| std::string a = t["a"]; | |
| std::string b = t["b"]; | |
| assert(a == "a lot of text goes here,"); | |
| assert(b == "and junk, you know?"); | |
| std::cout << "destroy state..." << std::endl; | |
| } | |
| std::cout << "destroy engine..." << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment