Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::vector<std::string> splitString(const std::string& str, char delim) {
- std::string temp;
- std::vector<std::string> tokens;
- for (unsigned int i = 0; i < str.size(); i++) {
- if (str.at(i) != delim) {
- temp += str.at(i);
- }
- else {
- tokens.push_back(temp);
- temp = "";
- }
- }
- tokens.push_back(temp);
- return tokens;
- }
- std::vector<std::string> LuaScript::getTableKeys(const std::string& name) {
- std::string code =
- "function getKeys() "
- "s = \"\""
- "for k, v in pairs(" + name + ") do "
- " s = s..k..\",\" "
- " end "
- "return s "
- "end"; // function for getting table keys
- luaL_loadstring(L, code.c_str()); // execute code
- lua_pcall(L,0,0,0);
- lua_getglobal(L, "getKeys"); // get function
- lua_pcall(L, 0 , 1, 0); // execute function
- std::string test = lua_tostring(L, -1);
- test.pop_back(); // remove last ","
- std::vector<std::string> strings = splitString(test, ',');
- clean();
- return strings;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement