mirror of
https://github.com/devZoGok/gameBase.git
synced 2026-08-26 19:43:28 +00:00
merged methods for extracting fields directly from scripts or tables
within
This commit is contained in:
@@ -20,14 +20,13 @@ namespace gameBase {
|
||||
|
||||
LuaManager *luaManager = LuaManager::getSingleton();
|
||||
luaManager->buildScript(vector<string>{optionsFile});
|
||||
string table = "mappings";
|
||||
|
||||
for(int i = firstMapping; i < firstMapping + numMappings; i++){
|
||||
Index idIndex = Index(i + 1);
|
||||
int bind = luaManager->getIntFromTable(table, vector<Index>{idIndex, Index("bind")});
|
||||
Mapping::BindType type = (Mapping::BindType)luaManager->getIntFromTable(table, vector<Index>{idIndex, Index("bindType")});
|
||||
bool action = luaManager->getBoolFromTable(table, vector<Index>{idIndex, Index("action")});
|
||||
int trigger = luaManager->getIntFromTable(table, vector<Index>{idIndex, Index("trigger")});
|
||||
Index tableInd = Index("mappings"), idIndex = Index(i + 1);
|
||||
int bind = luaManager->getInt(vector<Index>{tableInd, idIndex, Index("bind")});
|
||||
Mapping::BindType type = (Mapping::BindType)luaManager->getInt(vector<Index>{tableInd, idIndex, Index("bindType")});
|
||||
bool action = luaManager->getBool(vector<Index>{tableInd, idIndex, Index("action")});
|
||||
int trigger = luaManager->getInt(vector<Index>{tableInd, idIndex, Index("trigger")});
|
||||
|
||||
Mapping *m = new Mapping;
|
||||
m->bind = bind;
|
||||
|
||||
+18
-40
@@ -32,37 +32,13 @@ namespace gameBase{
|
||||
cout << errMsg;
|
||||
}
|
||||
|
||||
int LuaManager::getInt(string varName){
|
||||
lua_getglobal(state, varName.c_str());
|
||||
int isNum;
|
||||
int var = (int)lua_tointegerx(state, -1, &isNum);
|
||||
lua_pop(state, 1);
|
||||
return var;
|
||||
}
|
||||
|
||||
float LuaManager::getFloat(string varName){
|
||||
lua_getglobal(state, varName.c_str());
|
||||
int isNum;
|
||||
float var = (int)lua_tonumberx(state, -1, &isNum);
|
||||
lua_pop(state, 1);
|
||||
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<Index> &indices){
|
||||
lua_getglobal(state, table.c_str());
|
||||
void LuaManager::prepareTableForRetrieval(vector<Index> &indices){
|
||||
lua_getglobal(state, indices[0].index.c_str());
|
||||
|
||||
for(int i = 1; i < indices.size(); i++){
|
||||
if(!lua_istable(state, -1))
|
||||
cout << table << " is not a table\n";
|
||||
cout << indices[i].index << " is not in the " << indices[0].index << " table\n";
|
||||
|
||||
for(int i = 0; i < indices.size(); i++){
|
||||
if(indices[i].string)
|
||||
lua_pushstring(state, indices[i].index.c_str());
|
||||
else
|
||||
@@ -72,40 +48,42 @@ namespace gameBase{
|
||||
}
|
||||
}
|
||||
|
||||
int LuaManager::getIntFromTable(string table, vector<Index> indices){
|
||||
prepareTableForRetrieval(table, indices);
|
||||
int LuaManager::getInt(vector<Index> indices){
|
||||
prepareTableForRetrieval(indices);
|
||||
|
||||
int isNum;
|
||||
int result = lua_tointegerx(state, -1, &isNum);
|
||||
|
||||
lua_pop(state, 1 + indices.size());
|
||||
lua_pop(state, indices.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float LuaManager::getFloatFromTable(string table, vector<Index> indices){
|
||||
prepareTableForRetrieval(table, indices);
|
||||
float LuaManager::getFloat(vector<Index> indices){
|
||||
prepareTableForRetrieval(indices);
|
||||
|
||||
int isNum;
|
||||
float result = lua_tonumberx(state, -1, &isNum);
|
||||
|
||||
lua_pop(state, 1 + indices.size());
|
||||
lua_pop(state, indices.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LuaManager::getBoolFromTable(string table, vector<Index> indices){
|
||||
prepareTableForRetrieval(table, indices);
|
||||
bool LuaManager::getBool(vector<Index> indices){
|
||||
prepareTableForRetrieval(indices);
|
||||
|
||||
bool result = lua_toboolean(state, -1);
|
||||
lua_pop(state, 1 + indices.size());
|
||||
lua_pop(state, indices.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
string LuaManager::getStringFromTable(string table, vector<Index> indices){
|
||||
prepareTableForRetrieval(table, indices);
|
||||
string LuaManager::getString(vector<Index> indices){
|
||||
prepareTableForRetrieval(indices);
|
||||
|
||||
string result = lua_tostring(state, -1);
|
||||
lua_pop(state, 1 + indices.size());
|
||||
lua_pop(state, indices.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+5
-8
@@ -35,16 +35,13 @@ namespace gameBase{
|
||||
inline lua_State* getState(){return state;}
|
||||
void buildScript(std::vector<std::string>);
|
||||
void executeCode(std::string, std::string = "Error executing code\n");
|
||||
int getInt(std::string);
|
||||
float getFloat(std::string);
|
||||
int getIntFromTable(std::string, std::vector<Index>);
|
||||
bool getBoolFromTable(std::string, std::vector<Index>);
|
||||
float getFloatFromTable(std::string, std::vector<Index>);
|
||||
std::string getStringFromTable(std::string, std::vector<Index>);
|
||||
std::string getString(std::string);
|
||||
int getInt(std::vector<Index>);
|
||||
bool getBool(std::vector<Index>);
|
||||
float getFloat(std::vector<Index>);
|
||||
std::string getString(std::vector<Index>);
|
||||
private:
|
||||
LuaManager();
|
||||
void prepareTableForRetrieval(std::string, std::vector<Index>&);
|
||||
void prepareTableForRetrieval(std::vector<Index>&);
|
||||
|
||||
lua_State *state = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user