Advertisement
EDHpastebin

lua-c exe header

Feb 9th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #pragma once
  2.  
  3. std::vector<std::string> LuaCSplit(std::string s)
  4. {
  5.     std::vector<std::string> elems;
  6.     std::stringstream ss(s);
  7.     std::istream_iterator<std::string> begin(ss);
  8.     std::istream_iterator<std::string> end;
  9.     std::vector<std::string> vstrings(begin, end);
  10.     return vstrings;
  11. }
  12.  
  13. void LuaCExe(std::string input) {
  14.     try {
  15.         std::vector<std::string> In = LuaCSplit(input);
  16.  
  17.         if (In.at(0) == "getfield") {
  18.             std::string field;
  19.             for (size_t i = 2; i < In.size(); i++) {
  20.                 if (i < (In.size() - 1)) {
  21.                     field.append(In.at(i) + ' ');
  22.                 }
  23.                 if (i == (In.size() - 1)) {
  24.                     field.append(In.at(i));
  25.                 }
  26.             }
  27.             Rlua::rlua_getfield(luaState, stoi(In.at(1)), field.c_str());
  28.         }
  29.  
  30.         else if (In.at(0) == "getglobal") {
  31.             rlua_getglobal(luaState, In.at(1).c_str());
  32.         }
  33.  
  34.         else if (In.at(0) == "setfield") {
  35.             rlua_setfield(luaState, stoi(In.at(1)), In.at(2).c_str());
  36.         }
  37.  
  38.         else if (In.at(0) == "pushvalue") {
  39.             Rlua::rlua_pushvalue(luaState, stoi(In.at(1)));
  40.         }
  41.  
  42.         else if (In.at(0) == "pushstring") {
  43.             std::string string;
  44.             for (size_t i = 1; i < In.size(); i++) {
  45.                 if (i < (In.size() - 1)) {
  46.                     string.append(In.at(i) + ' ');
  47.                 }
  48.                 if (i == (In.size() - 1)) {
  49.                     string.append(In.at(i));
  50.                 }
  51.             }
  52.             Rlua::rlua_pushstring(luaState, string.c_str());
  53.         }
  54.  
  55.         else if (In.at(0) == "pushnumber") {
  56.             Rlua::rlua_pushnumber(luaState, stoi(In.at(1)));
  57.         }
  58.  
  59.         else if (In.at(0) == "pcall") {
  60.             rlua_bpcall(luaState, stoi(In.at(1)), stoi(In.at(2)), stoi(In.at(3)));
  61.         }
  62.  
  63.         else if (In.at(0) == "emptystack") {
  64.             Rlua::rlua_settop(luaState, 0);
  65.         }
  66.  
  67.         else if (In.at(0) == "settop") {
  68.             Rlua::rlua_settop(luaState, stoi(In.at(1)));
  69.         }
  70.  
  71.         else if (In.at(0) == "getservice") {
  72.             rlua_getService(In.at(1).c_str());
  73.         }
  74.  
  75.         else if (In.at(0) == "pushboolean") {
  76.             if (In.at(1) == "false") {
  77.                 Rlua::rlua_pushboolean(luaState, false);
  78.             }
  79.             else if (In.at(1) == "true") {
  80.                 Rlua::rlua_pushboolean(luaState, true);
  81.             }
  82.         }
  83.  
  84.     }
  85.     catch (...) {
  86.  
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement