Include :
- aggiornamenti vari.
This commit is contained in:
+77
@@ -185,6 +185,42 @@ LuaGetParam( lua_State* L, int nInd, DBLVECTOR& vPar)
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, STRVECTOR& vPar)
|
||||
{
|
||||
vPar.clear() ;
|
||||
if ( lua_isstring( L, nInd)) {
|
||||
std::string sVal = lua_tostring( L, nInd) ;
|
||||
vPar.emplace_back( sVal) ;
|
||||
return true ;
|
||||
}
|
||||
else if ( lua_istable( L, nInd)) {
|
||||
// lunghezza della tavola
|
||||
lua_len( L, nInd) ;
|
||||
if ( ! lua_isnumber( L, -1)) {
|
||||
lua_pop( L, 1) ;
|
||||
return false ;
|
||||
}
|
||||
int nLen = int( lua_tointeger( L, -1)) ;
|
||||
lua_pop( L, 1) ;
|
||||
vPar.reserve( nLen) ;
|
||||
for ( int i = 1 ; i <= nLen ; ++ i) {
|
||||
lua_rawgeti( L, nInd, i) ;
|
||||
if ( ! lua_isstring( L, -1)) {
|
||||
lua_pop( L, 1) ;
|
||||
return false ;
|
||||
}
|
||||
std::string sVal = lua_tostring( L, -1) ;
|
||||
vPar.emplace_back( sVal) ;
|
||||
lua_pop( L, 1) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
template <class T>
|
||||
bool
|
||||
@@ -198,6 +234,14 @@ LuaGetTabFieldParam( lua_State* L, int nInd, const char* szField, T& Val)
|
||||
return bOk ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
template <class T>
|
||||
bool
|
||||
LuaGetTabFieldParam( lua_State* L, int nInd, const std::string& sField, T& Val)
|
||||
{
|
||||
return LuaGetTabFieldParam( L, nInd, sField.c_str(), Val) ;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -314,6 +358,24 @@ LuaSetParam( lua_State* L, const DBLVECTOR& vPar)
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetParam( lua_State* L, const STRVECTOR& vPar)
|
||||
{
|
||||
try {
|
||||
int nSize = int( vPar.size()) ;
|
||||
lua_createtable( L, nSize, 0) ;
|
||||
for ( int i = 1 ; i <= nSize ; ++ i) {
|
||||
lua_pushstring( L, vPar[i-1].c_str()) ;
|
||||
lua_rawseti( L, -2, i) ;
|
||||
}
|
||||
}
|
||||
catch( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetTabFieldParam( lua_State* L, int nInd, const char* szField)
|
||||
@@ -327,6 +389,13 @@ LuaSetTabFieldParam( lua_State* L, int nInd, const char* szField)
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetTabFieldParam( lua_State* L, int nInd, const std::string& sField)
|
||||
{
|
||||
return LuaSetTabFieldParam( L, nInd, sField.c_str()) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
template <class T>
|
||||
bool
|
||||
@@ -341,6 +410,14 @@ LuaSetTabFieldParam( lua_State* L, int nInd, const char* szField, const T& Val)
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
template <class T>
|
||||
bool
|
||||
LuaSetTabFieldParam( lua_State* L, int nInd, const std::string& sField, const T& Val)
|
||||
{
|
||||
return LuaSetTabFieldParam( L, nInd, sField.c_str(), Val) ;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user