Advertisement
eliasdaler

Untitled

Oct 8th, 2014
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. std::vector<std::string> splitString(const std::string& str, char delim) {
  2.         std::string temp;
  3.         std::vector<std::string> tokens;
  4.         for (unsigned int i = 0; i < str.size(); i++) {
  5.             if (str.at(i) != delim) {
  6.                 temp += str.at(i);
  7.             }
  8.             else {
  9.                 tokens.push_back(temp);
  10.                 temp = "";
  11.             }
  12.         }
  13.         tokens.push_back(temp);
  14.         return tokens;
  15. }
  16.  
  17. std::vector<std::string> LuaScript::getTableKeys(const std::string& name) {
  18.     std::string code =
  19.         "function getKeys() "
  20.         "s = \"\""
  21.         "for k, v in pairs(" + name + ") do "
  22.         "    s = s..k..\",\" "
  23.         "    end "
  24.         "return s "
  25.         "end"; // function for getting table keys
  26.     luaL_loadstring(L, code.c_str()); // execute code
  27.     lua_pcall(L,0,0,0);
  28.     lua_getglobal(L, "getKeys"); // get function
  29.     lua_pcall(L, 0 , 1, 0); // execute function
  30.     std::string test = lua_tostring(L, -1);
  31.     test.pop_back(); // remove last ","
  32.     std::vector<std::string> strings = splitString(test, ',');
  33.     clean();
  34.     return strings;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement