Guest User

Untitled

a guest
Mar 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #define SOL_CHECK_ARGUMENTS 1
  2. #include <sol.hpp>
  3. #include <string>
  4. #include <iostream>
  5.  
  6. #include "catch_mock.hpp"
  7.  
  8. #include <unordered_set>
  9. #include <unordered_map>
  10.  
  11. int main() {
  12. struct Engine {
  13. std::unordered_multimap<int, std::pair<std::string, std::string>> breakingpoints;
  14.  
  15. void load_breakingpoints(std::unordered_multimap<int, std::pair<std::string, std::string>> breakingpoints) {
  16. this->breakingpoints = std::move(breakingpoints);
  17. }
  18. };
  19. {
  20. Engine e;
  21. e.load_breakingpoints({
  22. {0, {"the base", "for all things, right?"}},
  23. {1, {"a", "a lot of text goes here,"}},
  24. {1, {"b", "and junk, you know?"}},
  25. {3, {"super duper", "price model"}},
  26. {4, {"j", "k"}},
  27. });
  28. {
  29. sol::state lua;
  30. lua.set_function("get_breakpoint", [](Engine &e, int line, sol::this_state ts) {
  31. sol::state_view lua(ts);
  32. auto range = e.breakingpoints.equal_range(line);
  33.  
  34. sol::table ret = lua.create_table();
  35.  
  36. for (auto i = range.first; i != range.second; ++i) {
  37. ret[i->second.first] = i->second.second;
  38. }
  39.  
  40. return ret;
  41. });
  42.  
  43. lua.set("e", std::move(e));
  44. lua.script("t = get_breakpoint(e, 1)");
  45. sol::table t = lua["t"];
  46. std::string a = t["a"];
  47. std::string b = t["b"];
  48. assert(a == "a lot of text goes here,");
  49. assert(b == "and junk, you know?");
  50. std::cout << "destroy state..." << std::endl;
  51. }
  52. std::cout << "destroy engine..." << std::endl;
  53. }
  54. return 0;
  55. }
Add Comment
Please, Sign In to add comment