SHARE
TWEET

Untitled

eliasdaler Oct 8th, 2014 302 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top