46c5fce044
- ora si imposta un context corrente anche per le API come per LUA - il context corrente di LUA coincide con quello delle API.
108 lines
3.0 KiB
C++
108 lines
3.0 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : LUA_General.cpp Data : 27.09.14 Versione : 1.5i5
|
|
// Contenuto : Funzioni generali per LUA.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 27.09.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LUA.h"
|
|
#include "API.h"
|
|
#include "/EgtDev/Include/EInAPI.h"
|
|
#include "/EgtDev/Include/EgnStringUtils.h"
|
|
#include "/EgtDev/Extern/Lua/Include/lua.hpp"
|
|
|
|
using namespace std ;
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaSetDefaultMaterial( lua_State* L)
|
|
{
|
|
// un solo parametro, il colore
|
|
Color colDef ;
|
|
if ( ! LuaGetParam( L, 1, colDef))
|
|
return luaL_error( L, "Invalide first parameter") ;
|
|
LuaClearStack( L) ;
|
|
// imposto il colore di default
|
|
bool bOk = ( EgtSetDefaultMaterial( colDef.GetIntRed(), colDef.GetIntGreen(), colDef.GetIntBlue()) != FALSE) ;
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaNewFile( lua_State* L)
|
|
{
|
|
// nessun parametro
|
|
LuaClearStack( L) ;
|
|
// nuovo progetto
|
|
bool bOk = ( EgtNewFile() != FALSE) ;
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaOpenFile( lua_State* L)
|
|
{
|
|
// 1 parametro : path del file da aprire
|
|
string sFilePath ;
|
|
LuaCheckParam( L, 1, sFilePath)
|
|
LuaClearStack( L) ;
|
|
// apro il file
|
|
bool bOk = ( EgtOpenFile( sFilePath) != FALSE) ;
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaSaveFile( lua_State* L)
|
|
{
|
|
// 1 o 2 parametri : path del file [, flag("T","B","CT")]
|
|
string sFilePath ;
|
|
LuaCheckParam( L, 1, sFilePath)
|
|
int nFlag = GDB_SV_CMPTXT ;
|
|
string sFlag ;
|
|
if ( LuaGetParam( L, 2, sFlag)) {
|
|
ToUpper( sFlag) ;
|
|
if ( sFlag == "T")
|
|
nFlag = GDB_SV_TXT ;
|
|
else if ( sFlag == "B")
|
|
nFlag = GDB_SV_BIN ;
|
|
LuaClearStack( L) ;
|
|
}
|
|
// salvo il file
|
|
bool bOk = ( EgtSaveFile( sFilePath, nFlag) != FALSE) ;
|
|
// restituisco il risultato
|
|
LuaSetReturn( L, bOk) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
LuaInstallGeomDB( lua_State* L)
|
|
{
|
|
try {
|
|
lua_register( L, "EgtSetDefaultMaterial", LuaSetDefaultMaterial) ;
|
|
lua_register( L, "EgtNewFile", LuaNewFile) ;
|
|
lua_register( L, "EgtOpenFile", LuaOpenFile) ;
|
|
lua_register( L, "EgtSaveFile", LuaSaveFile) ;
|
|
}
|
|
catch ( ...) {
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|