From 56cd618b464994059d6a6c746a3f1b916f868f78 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 3 Jul 2022 16:06:31 +0300 Subject: [PATCH] added string extraction method --- luaManager.cpp | 8 ++++++++ luaManager.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/luaManager.cpp b/luaManager.cpp index 88297e3..5f486c2 100644 --- a/luaManager.cpp +++ b/luaManager.cpp @@ -36,6 +36,14 @@ namespace gameBase{ return var; } + string LuaManager::getString(string varName){ + lua_getglobal(state, varName.c_str()); + string result = lua_tostring(state, -1); + lua_pop(state, 1); + + return result; + } + void LuaManager::prepareTableForRetrieval(string table, vector &indices){ lua_getglobal(state, table.c_str()); diff --git a/luaManager.h b/luaManager.h index fd1b146..f74cf8f 100644 --- a/luaManager.h +++ b/luaManager.h @@ -29,12 +29,15 @@ namespace gameBase{ bool getBoolFromTable(std::string, std::vector); float getFloatFromTable(std::string, std::vector); std::string getStringFromTable(std::string, std::vector); + std::string getString(std::string); private: LuaManager(); void prepareTableForRetrieval(std::string, std::vector&); lua_State *state = nullptr; }; + + typedef LuaManager::Index Index; } #endif