Files
EgtInterface/API_Lua.cpp
T
Dario Sassi 1e24540dc1 EgtInterface 1.6b2 :
- razionalizzazione
- modificati comandi per creazione superfici per gestione piani di regioni con buchi
- aggiunta SplitCurve.
2015-02-11 11:46:14 +00:00

120 lines
3.8 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : API_LUA.cpp Data : 28.09.14 Versione : 1.5i5
// Contenuto : Funzioni esecuzione LUA per API.
//
//
//
// Modifiche : 28.09.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "API.h"
#include "LUA.h"
#include "/EgtDev/Include/EInAPI.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGnStringConverter.h"
using namespace std ;
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtLuaEvalNumExpr( const wchar_t* wsExpr, double* pdVal)
{
// verifico parametro di ritorno
if ( pdVal == nullptr)
return FALSE ;
// valuto l'espressione
return ( LuaEvalNumExpr( wstrztoA( wsExpr), *pdVal) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtLuaEvalStringExpr( const wchar_t* wsExpr, wchar_t*& wsVal)
{
// verifico parametro di ritorno
if ( &wsVal == nullptr)
return false ;
// valuto l'espressione
string sVal ;
if ( ! LuaEvalStringExpr( wstrztoA( wsExpr), sVal))
return FALSE ;
wsVal = _wcsdup( stringtoW( sVal)) ;
return (( wsVal == nullptr) ? FALSE : TRUE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtLuaExecLine( const wchar_t* wsLine)
{
// disabilito log dei comandi e salvo stato precedente
bool bPrevCmdLog = SetCmdLog( false) ;
// eseguo il comando
string sLine = wstrztoA( wsLine) ;
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 ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtLuaExecFile( const wchar_t* wsFilePath)
{
// converto nome file
string sFilePath = wstrztoA( wsFilePath) ;
// emetto info
string sInfo = "Exec File = " + sFilePath ;
LOG_INFO( GetLogger(), sInfo.c_str())
// disabilito il log dei comandi
bool bPrevCmdLog = IsCmdLog() ;
EgtDisableCommandLogger() ;
// esecuzione script
bool bOk = LuaExecFile( sFilePath) ;
// ripristino lo stato originale del log dei comandi
if ( bPrevCmdLog)
EgtEnableCommandLogger() ;
// se richiesto, salvo il comando Lua
if ( IsCmdLog()) {
string sLuaPath = sFilePath ;
ReplaceString( sLuaPath, "\\", "\\\\") ;
string sLua = "dofile('" + sLuaPath + "')" +
" -- Ok=" + ToString( bOk) ;
LOG_INFO( GetCmdLogger(), sLua.c_str()) ;
}
// restituisco il risultato
return ( bOk ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtLuaRequire( const wchar_t* wsFilePath)
{
// converto nome file
string sFilePath = wstrztoA( wsFilePath) ;
// emetto info
string sInfo = "Require Library = " + sFilePath ;
LOG_INFO( GetLogger(), sInfo.c_str())
// eseguo il comando
return ( LuaRequire( sFilePath) ? TRUE : FALSE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtLuaGetLastError( wchar_t*& wsError)
{
wsError = _wcsdup( stringtoW( LuaGetLastError())) ;
return (( wsError == nullptr) ? FALSE : TRUE) ;
}