EgtGeneral 1.6x1 :

- in LuaManager aggiunti controlli validità ambiente Lua.
This commit is contained in:
Dario Sassi
2017-01-04 07:36:41 +00:00
parent 0c547c501c
commit 638025ed79
2 changed files with 31 additions and 2 deletions
+31 -2
View File
@@ -1,13 +1,14 @@
//----------------------------------------------------------------------------
// EgalTech 2015-2015
// EgalTech 2015-2017
//----------------------------------------------------------------------------
// File : LuaManager.cpp Data : 20.08.15 Versione : 1.6h4
// File : LuaManager.cpp Data : 03.01.17 Versione : 1.6x1
// Contenuto : Implementazione della classe LuaMgr.
//
//
//
// Modifiche : 21.03.15 DS Creazione modulo.
// 20.08.15 DS Controllo che il double di EvalExpr sia numero valido.
// 03.01.17 DS Aggiunti controlli validità ambiente lua.
//
//----------------------------------------------------------------------------
@@ -44,6 +45,7 @@ LuaMgr::Init( void)
bool
LuaMgr::Exit( void)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// termino Lua
@@ -56,6 +58,9 @@ LuaMgr::Exit( void)
bool
LuaMgr::GetVersion( string& sLuaVer)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// verifico il parametro di ritorno
if ( &sLuaVer == nullptr)
return false ;
@@ -71,6 +76,9 @@ LuaMgr::GetVersion( string& sLuaVer)
bool
LuaMgr::SetLuaLibsDir( const string& sDir)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// salvo il direttorio
m_sLuaLibsDir = sDir ;
// recupero la stringa globale package.path
@@ -96,6 +104,9 @@ LuaMgr::SetLuaLibsDir( const string& sDir)
bool
LuaMgr::Require( const string& sFile)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// salvo nome libreria richiesta
m_sLastRequire = sFile ;
// eseguo
@@ -122,6 +133,9 @@ LuaMgr::Require( const string& sFile)
bool
LuaMgr::RegisterFunction( const string& sFunName, PFLUA pFun)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
if ( &sFunName == nullptr)
return false ;
try {
@@ -137,6 +151,9 @@ LuaMgr::RegisterFunction( const string& sFunName, PFLUA pFun)
bool
LuaMgr::EvalExpr( const string& sExpr, double& dVal)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// completo la stringa da valutare
string sEval = "return " + sExpr ;
// valuto l'espressione
@@ -172,6 +189,9 @@ LuaMgr::EvalExpr( const string& sExpr, double& dVal)
bool
LuaMgr::EvalExpr( const string& sExpr, string& sVal)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// completo la stringa da valutare
string sEval = "return " + sExpr ;
// valuto l'espressione
@@ -199,6 +219,9 @@ LuaMgr::EvalExpr( const string& sExpr, string& sVal)
bool
LuaMgr::ExecLine( const string& sLine)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// eseguo la linea
int nErr = luaL_loadstring( m_pL, sLine.c_str()) || lua_pcall( m_pL, 0, LUA_MULTRET, 0) ;
// senza errori
@@ -222,6 +245,9 @@ LuaMgr::ExecLine( const string& sLine)
bool
LuaMgr::ExecFile( const string& sFile)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// eseguo la linea
int nErr = luaL_loadfile( m_pL, sFile.c_str()) || lua_pcall( m_pL, 0, LUA_MULTRET, 0) ;
// senza errori
@@ -245,6 +271,9 @@ LuaMgr::ExecFile( const string& sFile)
bool
LuaMgr::ExistsFunction( const string& sFunName)
{
// verifico ambiente lua
if ( m_pL == nullptr)
return false ;
// recupero la funzione
if ( sFunName.find( '.') == std::string::npos) {
// è direttamente il nome