Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Add Comment
Please, Sign In to add comment