Files
EgtExecutor/EXE_Lua.cpp
T
Dario Sassi b14c634bc3 EgtExecutor 1.6g5 :
- in creazione curve eliminata la normale (si deduce dal riferimento indicato)
- in creazione gruppo di inserimento è layer corrente da costante
- gestino carattere ' nelle stringhe per lua.
2015-07-20 13:07:09 +00:00

239 lines
7.0 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2015
//----------------------------------------------------------------------------
// File : EXE_LUA.cpp Data : 05.05.15 Versione : 1.6e1
// Contenuto : Funzioni esecuzione LUA per EXE.
//
//
//
// Modifiche : 28.09.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "EXE.h"
#include "LUA_Base.h"
#include "/EgtDev/Include/EXeExecutor.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EgtStringConverter.h"
using namespace std ;
//-----------------------------------------------------------------------------
bool
ExeLuaSetGlobBoolVar( const string& sVar, bool bVal)
{
// assegno il valore della variabile
bool bOk = LuaSetGlobVar( sVar, bVal) ;
// se richiesto, salvo il comando Lua
if ( IsCmdLog()) {
string sLua = sVar + "=" + ( bVal ? "true" : "false") +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco il risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaSetGlobIntVar( const string& sVar, int nVal)
{
// assegno il valore della variabile
bool bOk = LuaSetGlobVar( sVar, nVal) ;
// se richiesto, salvo il comando Lua
if ( IsCmdLog()) {
string sLua = sVar + "=" + ToString( nVal) +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco il risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaSetGlobNumVar( const string& sVar, double dVal)
{
// assegno il valore della variabile
bool bOk = LuaSetGlobVar( sVar, dVal) ;
// se richiesto, salvo il comando Lua
if ( IsCmdLog()) {
string sLua = sVar + "=" + ToString( dVal) +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco il risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaSetGlobStringVar( const string& sVar, const string& sVal)
{
// assegno il valore della variabile
bool bOk = LuaSetGlobVar( sVar, sVal) ;
// se richiesto, salvo il comando Lua
if ( IsCmdLog()) {
string sLua = sVar + "='" + sVal + "'" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco il risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaGetGlobBoolVar( const string& sVar, bool* pbVal)
{
// verifico parametro di ritorno
if ( pbVal == nullptr)
return false ;
// recupero il valore della variabile
return LuaGetGlobVar( sVar, *pbVal) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaGetGlobIntVar( const string& sVar, int* pnVal)
{
// verifico parametro di ritorno
if ( pnVal == nullptr)
return false ;
// recupero il valore della variabile
return LuaGetGlobVar( sVar, *pnVal) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaGetGlobNumVar( const string& sVar, double* pdVal)
{
// verifico parametro di ritorno
if ( pdVal == nullptr)
return false ;
// recupero il valore della variabile
return LuaGetGlobVar( sVar, *pdVal) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaGetGlobStringVar( const string& sVar, string& sVal)
{
// verifico parametro di ritorno
if ( &sVal == nullptr)
return false ;
// recupero il valore della variabile
return LuaGetGlobVar( sVar, sVal) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaResetGlobVar( const string& sVar)
{
// eseguo il reset della variabile
return LuaResetGlobVar( sVar) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaCreateGlobTable( const string& sVar)
{
// creazione della tavola
return LuaCreateGlobTable( sVar) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaEvalNumExpr( const string& sExpr, double* pdVal)
{
// verifico parametro di ritorno
if ( pdVal == nullptr)
return false ;
// valuto l'espressione
return LuaEvalExpr( sExpr, *pdVal) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaEvalStringExpr( const string& sExpr, string& sVal)
{
// verifico parametro di ritorno
if ( &sVal == nullptr)
return false ;
// valuto l'espressione
return LuaEvalExpr( sExpr, sVal) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaExecLine( const string& sLine)
{
// disabilito log dei comandi e salvo stato precedente
bool bPrevCmdLog = SetCmdLog( false) ;
// eseguo il comando
bool bOk = LuaExecLine( sLine) ;
// ripristino lo stato originale del log dei comandi
SetCmdLog( bPrevCmdLog) ;
// se richiesto, salvo il comando Lua
if ( IsCmdLog()) {
string sLua = sLine +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco il risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaExecFile( const string& sFilePath)
{
// emetto info
string sInfo = "Exec File = " + sFilePath ;
LOG_INFO( GetLogger(), sInfo.c_str())
// disabilito il log dei comandi
bool bPrevCmdLog = IsCmdLog() ;
ExeDisableCommandLogger() ;
// esecuzione script
bool bOk = LuaExecFile( sFilePath) ;
// ripristino lo stato originale del log dei comandi
if ( bPrevCmdLog)
ExeEnableCommandLogger() ;
// se richiesto, salvo il comando Lua
if ( IsCmdLog()) {
string sLuaPath = sFilePath ;
ReplaceString( sLuaPath, "\\", "\\\\") ;
ReplaceString( sLuaPath, "'", "\\'") ;
string sLua = "dofile('" + sLuaPath + "')" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco il risultato
return bOk ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaRequire( const string& sFilePath)
{
// emetto info
string sInfo = "Require Library = " + sFilePath ;
LOG_INFO( GetLogger(), sInfo.c_str())
// eseguo il comando
return LuaRequire( sFilePath) ;
}
//-----------------------------------------------------------------------------
bool
ExeLuaGetLastError( string& sError)
{
// verifico parametro di ritorno
if ( &sError == nullptr)
return false ;
sError = LuaGetLastError() ;
return true ;
}