Changed: Support for integer types in Lua 5.3, fixes #253

--HG--
branch : develop
hg/feature/material-editor
kervala 9 years ago
parent 53f46eb5fa
commit 9e88fa645b

@ -125,6 +125,9 @@ namespace NLGUI
void setValue(const char *key, bool value) throw(ELuaNotATable); void setValue(const char *key, bool value) throw(ELuaNotATable);
void setValue(const char *key, TLuaWrappedFunction value) throw(ELuaNotATable); void setValue(const char *key, TLuaWrappedFunction value) throw(ELuaNotATable);
void setValue(const char *key, double value) throw(ELuaNotATable); void setValue(const char *key, double value) throw(ELuaNotATable);
void setValue(const char *key, uint32 value) throw(ELuaNotATable);
void setValue(const char *key, sint32 value) throw(ELuaNotATable);
void setValue(const char *key, sint64 value) throw(ELuaNotATable);
void setValue(const std::string &key, const std::string &value) throw(ELuaNotATable) { setValue(key.c_str(), value); } void setValue(const std::string &key, const std::string &value) throw(ELuaNotATable) { setValue(key.c_str(), value); }
void setNil(const char *key) throw(ELuaNotATable); void setNil(const char *key) throw(ELuaNotATable);
void setNil(const std::string &key) throw(ELuaNotATable) { setNil(key.c_str()); } void setNil(const std::string &key) throw(ELuaNotATable) { setNil(key.c_str()); }

@ -389,6 +389,48 @@ namespace NLGUI
_LuaState->pop(); _LuaState->pop();
} }
// *************************************************
void CLuaObject::setValue(const char *key, uint32 value) throw(ELuaNotATable)
{
nlassert(key);
nlassert(isValid());
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%u' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
CLuaStackChecker lsc(_LuaState);
push();
_LuaState->push(key);
_LuaState->push(value);
_LuaState->setTable(-3);
_LuaState->pop();
}
// *************************************************
void CLuaObject::setValue(const char *key, sint32 value) throw(ELuaNotATable)
{
nlassert(key);
nlassert(isValid());
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%d' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
CLuaStackChecker lsc(_LuaState);
push();
_LuaState->push(key);
_LuaState->push(value);
_LuaState->setTable(-3);
_LuaState->pop();
}
// *************************************************
void CLuaObject::setValue(const char *key, sint64 value) throw(ELuaNotATable)
{
nlassert(key);
nlassert(isValid());
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%d"NL_I64"' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
CLuaStackChecker lsc(_LuaState);
push();
_LuaState->push(key);
_LuaState->push(value);
_LuaState->setTable(-3);
_LuaState->pop();
}
// ************************************************* // *************************************************
void CLuaObject::eraseValue(const char *key) throw(ELuaNotATable) void CLuaObject::eraseValue(const char *key) throw(ELuaNotATable)
{ {

@ -1427,7 +1427,7 @@ int CLuaIHMRyzom::getClientCfgVar(CLuaState &ls)
} }
for(uint i = 0; i<v->IntValues.size(); i++) for(uint i = 0; i<v->IntValues.size(); i++)
{ {
result.setValue(toString(count).c_str(), (double)v->IntValues[i]); result.setValue(toString(count).c_str(), (sint32)v->IntValues[i]);
count++; count++;
} }
for(uint i = 0; i<v->RealValues.size(); i++) for(uint i = 0; i<v->RealValues.size(); i++)
@ -1752,10 +1752,10 @@ int CLuaIHMRyzom::getCompleteIslands(CLuaState &ls)
ls.newTable(); ls.newTable();
CLuaObject islandTable(ls); CLuaObject islandTable(ls);
islandTable.setValue("continent", island->Continent); islandTable.setValue("continent", island->Continent);
islandTable.setValue("xmin", (double)island->XMin); islandTable.setValue("xmin", island->XMin);
islandTable.setValue("ymin", (double)island->YMin); islandTable.setValue("ymin", island->YMin);
islandTable.setValue("xmax", (double)island->XMax); islandTable.setValue("xmax", island->XMax);
islandTable.setValue("ymax", (double)island->YMax); islandTable.setValue("ymax", island->YMax);
ls.newTable(); ls.newTable();
CLuaObject entrypointsTable(ls); CLuaObject entrypointsTable(ls);
@ -1765,8 +1765,8 @@ int CLuaIHMRyzom::getCompleteIslands(CLuaState &ls)
const CScenarioEntryPoints::CShortEntryPoint & entryPoint = island->EntryPoints[e]; const CScenarioEntryPoints::CShortEntryPoint & entryPoint = island->EntryPoints[e];
ls.newTable(); ls.newTable();
CLuaObject entrypointTable(ls); CLuaObject entrypointTable(ls);
entrypointTable.setValue("x", (double)entryPoint.X); entrypointTable.setValue("x", entryPoint.X);
entrypointTable.setValue("y", (double)entryPoint.Y); entrypointTable.setValue("y", entryPoint.Y);
entrypointsTable.setValue(entryPoint.Location, entrypointTable); entrypointsTable.setValue(entryPoint.Location, entrypointTable);
} }

@ -373,34 +373,36 @@ void CSessionBrowserImpl::fill(const std::vector <RSMGR::TSessionDesc > &session
const RSMGR::TSessionDesc &sd = sessions[k]; const RSMGR::TSessionDesc &sd = sessions[k];
_Lua->newTable(); _Lua->newTable();
CLuaObject session(*_Lua); CLuaObject session(*_Lua);
session.setValue("Id", (double) sd.getSessionId().asInt()); session.setValue("Id", sd.getSessionId().asInt());
session.setValue("Owner", sd.getOwnerName()); session.setValue("Owner", sd.getOwnerName());
session.setValue("Title", sd.getTitle()); session.setValue("Title", sd.getTitle());
session.setValue("Desc", sd.getDescription()); session.setValue("Desc", sd.getDescription());
session.setValue("Level", (double) sd.getSessionLevel().getValue()); session.setValue("Level", (uint32) sd.getSessionLevel().getValue());
session.setValue("Language", sd.getLanguage()); session.setValue("Language", sd.getLanguage());
uint flags = (sd.getAnimMode().getValue() == RSMGR::TAnimMode::am_dm ? (uint) 1 : 0) | uint flags = (sd.getAnimMode().getValue() == RSMGR::TAnimMode::am_dm ? (uint) 1 : 0) |
(sd.getRequesterCharInvited() ? (uint) 2 : 0); (sd.getRequesterCharInvited() ? (uint) 2 : 0);
if(sd.getRequesterCharKicked()) if(sd.getRequesterCharKicked())
flags = (uint) 4; flags = (uint) 4;
session.setValue("Flags", (double) flags);
session.setValue("PlayerCount", (double) sd.getNbConnectedPlayer());
session.setValue("AllowFreeTrial", (double) sd.getAllowFreeTrial());
session.setValue("NbRating", (double) sd.getNbRating()); session.setValue("Flags", flags);
session.setValue("RateFun", (double) sd.getRateFun()); session.setValue("PlayerCount", sd.getNbConnectedPlayer());
session.setValue("RateDifficulty", (double) sd.getRateDifficulty()); session.setValue("AllowFreeTrial", sd.getAllowFreeTrial());
session.setValue("RateAccessibility", (double) sd.getRateAccessibility());
session.setValue("RateOriginality", (double) sd.getRateOriginality()); session.setValue("NbRating", sd.getNbRating());
session.setValue("RateDirection", (double) sd.getRateDirection()); session.setValue("RateFun", sd.getRateFun());
session.setValue("RateDifficulty", sd.getRateDifficulty());
session.setValue("RateAccessibility", sd.getRateAccessibility());
session.setValue("RateOriginality", sd.getRateOriginality());
session.setValue("RateDirection", sd.getRateDirection());
session.setValue("ScenarioRRPTotal", (double) sd.getScenarioRRPTotal()); session.setValue("ScenarioRRPTotal", sd.getScenarioRRPTotal());
session.setValue("AuthorRating", (double) _LastAuthorRating); session.setValue("AuthorRating", _LastAuthorRating);
if(sd.getAnimMode().getValue() == RSMGR::TAnimMode::am_dm) if(sd.getAnimMode().getValue() == RSMGR::TAnimMode::am_dm)
session.setValue("OwnerRating", (double) _LastAMRating); session.setValue("OwnerRating", _LastAMRating);
else else
session.setValue("OwnerRating", (double) _LastMasterlessRating); session.setValue("OwnerRating", _LastMasterlessRating);
// calculate the difference between local time and gmt // calculate the difference between local time and gmt
time_t rawtime; time_t rawtime;
@ -418,9 +420,9 @@ void CSessionBrowserImpl::fill(const std::vector <RSMGR::TSessionDesc > &session
// convert GMT time value from server to local time // convert GMT time value from server to local time
time_t adjustedTime= sd.getLaunchDate() + localTime - gmtTime; time_t adjustedTime= sd.getLaunchDate() + localTime - gmtTime;
session.setValue("LaunchDate", (double) adjustedTime); session.setValue("LaunchDate", (sint64)adjustedTime);
session.setValue("ScenarioType", (double) sd.getOrientation().getValue()); session.setValue("ScenarioType", (uint32)sd.getOrientation().getValue());
session.push(); session.push();
_Lua->rawSetI(-2, k +1); // set in session list _Lua->rawSetI(-2, k +1); // set in session list
} }
@ -442,12 +444,12 @@ void CSessionBrowserImpl::playerRatingFill(bool scenarioRated, uint32 rateFun, u
_Lua->newTable(); _Lua->newTable();
CLuaObject scores(*_Lua); CLuaObject scores(*_Lua);
scores.setValue("ScenarioRated", (double) scenarioRated); scores.setValue("ScenarioRated", scenarioRated);
scores.setValue("RateFun", (double) rateFun); scores.setValue("RateFun", rateFun);
scores.setValue("RateDifficulty", (double) rateDifficulty); scores.setValue("RateDifficulty", rateDifficulty);
scores.setValue("RateAccessibility", (double) rateAccessibility); scores.setValue("RateAccessibility", rateAccessibility);
scores.setValue("RateOriginality", (double) rateOriginality); scores.setValue("RateOriginality", rateOriginality);
scores.setValue("RateDirection", (double) rateDirection); scores.setValue("RateDirection", rateDirection);
scores.push(); scores.push();
@ -469,13 +471,13 @@ void CSessionBrowserImpl::averageScoresFill(bool scenarioRated, uint32 rateFun,
_Lua->newTable(); _Lua->newTable();
CLuaObject scores(*_Lua); CLuaObject scores(*_Lua);
scores.setValue("ScenarioRated", (double) scenarioRated); scores.setValue("ScenarioRated", scenarioRated);
scores.setValue("RateFun", (double) rateFun); scores.setValue("RateFun", rateFun);
scores.setValue("RateDifficulty", (double) rateDifficulty); scores.setValue("RateDifficulty", rateDifficulty);
scores.setValue("RateAccessibility", (double) rateAccessibility); scores.setValue("RateAccessibility", rateAccessibility);
scores.setValue("RateOriginality", (double) rateOriginality); scores.setValue("RateOriginality", rateOriginality);
scores.setValue("RateDirection", (double) rateDirection); scores.setValue("RateDirection", rateDirection);
scores.setValue("RRPTotal", (double) rrpTotal); scores.setValue("RRPTotal", rrpTotal);
scores.push(); scores.push();
@ -560,13 +562,13 @@ void CSessionBrowserImpl::on_scenarioAverageScores(NLNET::TSockId /* from */, bo
_Lua->newTable(); _Lua->newTable();
CLuaObject scores(*_Lua); CLuaObject scores(*_Lua);
scores.setValue("ScenarioRated", (double) scenarioRated); scores.setValue("ScenarioRated", scenarioRated);
scores.setValue("RateFun", (double) rateFun); scores.setValue("RateFun", rateFun);
scores.setValue("RateDifficulty", (double) rateDifficulty); scores.setValue("RateDifficulty", rateDifficulty);
scores.setValue("RateAccessibility", (double) rateAccessibility); scores.setValue("RateAccessibility", rateAccessibility);
scores.setValue("RateOriginality", (double) rateOriginality); scores.setValue("RateOriginality", rateOriginality);
scores.setValue("RateDirection", (double) rateDirection); scores.setValue("RateDirection", rateDirection);
scores.setValue("RRPTotal", (double) rrpTotal); scores.setValue("RRPTotal", rrpTotal);
scores.push(); scores.push();
@ -612,11 +614,11 @@ void CSessionBrowserImpl::charsFill(const std::vector <RSMGR::TCharDesc > &chars
{ {
_Lua->newTable(); _Lua->newTable();
CLuaObject luaChar(*_Lua); CLuaObject luaChar(*_Lua);
luaChar.setValue("Id", (double) cd.getCharId()); luaChar.setValue("Id", cd.getCharId());
luaChar.setValue("Char", cd.getCharName()); luaChar.setValue("Char", cd.getCharName());
luaChar.setValue("Guild", cd.getGuildName()); luaChar.setValue("Guild", cd.getGuildName());
luaChar.setValue("Race", (double) cd.getRace().getValue()); luaChar.setValue("Race", (uint32) cd.getRace().getValue());
luaChar.setValue("Religion", (double) cd.getCult().getValue()); luaChar.setValue("Religion", (uint32) cd.getCult().getValue());
string shardName = toString(cd.getShardId()); string shardName = toString(cd.getShardId());
for(uint l = 0; l < Mainlands.size(); ++l) for(uint l = 0; l < Mainlands.size(); ++l)
@ -630,7 +632,7 @@ void CSessionBrowserImpl::charsFill(const std::vector <RSMGR::TCharDesc > &chars
luaChar.setValue("Shard", shardName); luaChar.setValue("Shard", shardName);
// note: we do 'level-1' because the TSessionLevel enum starts at 1 // note: we do 'level-1' because the TSessionLevel enum starts at 1
luaChar.setValue("Level", (double) (cd.getLevel().getValue()-1)); luaChar.setValue("Level", (uint32) (cd.getLevel().getValue()-1));
/* /*
uint32 flags = 0; uint32 flags = 0;
if (cd.getConnected()) { flags += 1; } if (cd.getConnected()) { flags += 1; }
@ -639,7 +641,7 @@ void CSessionBrowserImpl::charsFill(const std::vector <RSMGR::TCharDesc > &chars
uint32 flags = cd.getConnected(); uint32 flags = cd.getConnected();
if (cd.getKicked()){ flags = 2; } if (cd.getKicked()){ flags = 2; }
luaChar.setValue("Flags", (double) flags); luaChar.setValue("Flags", flags);
luaChar.push(); luaChar.push();
_Lua->rawSetI(-2, k +1); // set in chars list _Lua->rawSetI(-2, k +1); // set in chars list
} }
@ -655,14 +657,14 @@ void CSessionBrowserImpl::charsFill(const std::vector <RSMGR::TCharDesc > &chars
// **************************************************************************** // ****************************************************************************
inline double ecoRingPoints(const std::string & ecoPoints, const char * c) inline uint32 ecoRingPoints(const std::string & ecoPoints, const char * c)
{ {
std::string::size_type cPlace = ecoPoints.find(c); std::string::size_type cPlace = ecoPoints.find(c);
if(cPlace==string::npos) if(cPlace==string::npos)
return 0; return 0;
std::string::size_type sepPlace = ecoPoints.find(":", cPlace); std::string::size_type sepPlace = ecoPoints.find(":", cPlace);
std::string points = ecoPoints.substr(cPlace+1, sepPlace); std::string points = ecoPoints.substr(cPlace+1, sepPlace);
double ret; uint32 ret;
fromString(points, ret); fromString(points, ret);
return ret; return ret;
} }
@ -678,9 +680,9 @@ void CSessionBrowserImpl::ringStatsFill()
CLuaObject luaRingPoints(*_Lua); CLuaObject luaRingPoints(*_Lua);
luaRingPoints.setValue("AuthorRating", (double) _LastAuthorRating); luaRingPoints.setValue("AuthorRating", _LastAuthorRating);
luaRingPoints.setValue("AMRating", (double) _LastAMRating); luaRingPoints.setValue("AMRating", _LastAMRating);
luaRingPoints.setValue("MasterlessRating", (double) _LastMasterlessRating); luaRingPoints.setValue("MasterlessRating", _LastMasterlessRating);
luaRingPoints.setValue("MaxBasicRingPoints", ecoRingPoints(_LastMaxRingPoints, "A")); luaRingPoints.setValue("MaxBasicRingPoints", ecoRingPoints(_LastMaxRingPoints, "A"));
luaRingPoints.setValue("BasicRingPoints", ecoRingPoints(_LastRingPoints, "A")); luaRingPoints.setValue("BasicRingPoints", ecoRingPoints(_LastRingPoints, "A"));

Loading…
Cancel
Save