00001 #ifndef LuaUtils_HPP
00002 #define LuaUtils_HPP
00003
00004 #include <string>
00005 #include<vector>
00006
00007
00008
00009
00010 extern "C" {
00011 #include <lua.h>
00012 }
00013
00014 using std::string;
00015 using std::vector;
00016
00017
00025 class LuaUtils{
00026
00027 private:
00028
00029
00030 static int convertStackIndex(struct lua_State * state, int stackIndex);
00031
00032 public:
00033
00034
00042 static std::string getStringFromTable(struct lua_State * state, const char * key);
00043
00044
00045 static int getIntFromTable(struct lua_State * state, const char * key);
00046
00055 static void setFieldOnTable(struct lua_State * state,
00056 const char * key,
00057 const char * value,
00058 int tableIndexOnStack);
00059
00068 static void setFieldOnTable(struct lua_State * state,
00069 string key,
00070 string value,
00071 int tableIndexOnStack){
00072 LuaUtils::setFieldOnTable(state, key.c_str(), value.c_str(), tableIndexOnStack);
00073
00074 }
00075
00076
00085 static void setFieldOnTable(struct lua_State * state,
00086 const char * key,
00087 double value,
00088 int tableIndexOnStack);
00089
00098 static void setFieldOnTable(struct lua_State * state,
00099 string key,
00100 double value,
00101 int tableIndexOnStack){
00102
00103 LuaUtils::setFieldOnTable(state, key.c_str(), value, tableIndexOnStack);
00104 }
00105
00106
00107
00116 static void writeFile(struct lua_State * state,
00117 std::string fileName,
00118 int stackIndex);
00119
00120
00121 static void openFileForRead(struct lua_State * state,
00122 std::string fileName);
00123
00124 static void openFileForWrite(struct lua_State * state,
00125 std::string fileName);
00126
00127
00128
00129 static void closeDefaultFile(struct lua_State * state);
00130
00131
00132 static void readFullFile(struct lua_State * state);
00133
00134
00135 static void writeToFile(struct lua_State * state, int stackIndex);
00136
00137
00138 static void printTable(struct lua_State * state, int stackIndex);
00139
00140
00141 static vector<string> extractStringSequence(struct lua_State * state, int stackIndex);
00142
00143 };
00144
00145 #endif//LuaUtils_HPP