Include :
- aggiunti prototipi e funzioni per lua.
This commit is contained in:
+340
@@ -0,0 +1,340 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2015-2015
|
||||
//----------------------------------------------------------------------------
|
||||
// File : EGkLuaAux.h Data : 21.03.15 Versione : 1.6c6
|
||||
// Contenuto : Funzioni per gestione parametri geometrici con LUA.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 21.03.15 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "/EgtDev/Include/EGkVector3d.h"
|
||||
#include "/EgtDev/Include/EGkPoint3d.h"
|
||||
#include "/EgtDev/Include/EGkFrame3d.h"
|
||||
#include "/EgtDev/Include/EGkColor.h"
|
||||
#include "/EgtDev/Include/EGkGeoCollection.h"
|
||||
#include "/EgtDev/Include/EgnLuaAux.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, Vector3d& vtPar)
|
||||
{
|
||||
if ( ! lua_istable( L, nInd))
|
||||
return false ;
|
||||
for ( int i = 1 ; i <= 3 ; ++ i) {
|
||||
lua_rawgeti( L, nInd, i) ;
|
||||
if ( ! lua_isnumber( L, -1))
|
||||
return false ;
|
||||
vtPar.v[i-1] = lua_tonumber( L, -1) ;
|
||||
lua_pop( L, 1) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, Point3d& ptPar)
|
||||
{
|
||||
if ( ! lua_istable( L, nInd))
|
||||
return false ;
|
||||
for ( int i = 1 ; i <= 3 ; ++ i) {
|
||||
lua_rawgeti( L, nInd, i) ;
|
||||
if ( ! lua_isnumber( L, -1))
|
||||
return false ;
|
||||
ptPar.v[i-1] = lua_tonumber( L, -1) ;
|
||||
lua_pop( L, 1) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, POINTU& ptParW)
|
||||
{
|
||||
if ( ! lua_istable( L, nInd))
|
||||
return false ;
|
||||
for ( int i = 1 ; i <= 4 ; ++ i) {
|
||||
lua_rawgeti( L, nInd, i) ;
|
||||
if ( ! lua_isnumber( L, -1))
|
||||
return false ;
|
||||
if ( i <= 3)
|
||||
ptParW.first.v[i-1] = lua_tonumber( L, -1) ;
|
||||
else
|
||||
ptParW.second = lua_tonumber( L, -1) ;
|
||||
lua_pop( L, 1) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, Frame3d& frPar)
|
||||
{
|
||||
if ( ! lua_istable( L, nInd))
|
||||
return false ;
|
||||
// recupero l'origine
|
||||
lua_rawgeti( L, nInd, 1) ;
|
||||
Point3d ptOrig ;
|
||||
if ( ! LuaGetParam( L, -1, ptOrig))
|
||||
return false ;
|
||||
lua_pop( L, 1) ;
|
||||
// recupero il versore X
|
||||
lua_rawgeti( L, nInd, 2) ;
|
||||
Vector3d vtDirX ;
|
||||
if ( ! LuaGetParam( L, -1, vtDirX))
|
||||
return false ;
|
||||
lua_pop( L, 1) ;
|
||||
// recupero il versore Y
|
||||
lua_rawgeti( L, nInd, 3) ;
|
||||
Vector3d vtDirY ;
|
||||
if ( ! LuaGetParam( L, -1, vtDirY))
|
||||
return false ;
|
||||
lua_pop( L, 1) ;
|
||||
// recupero il versore Z
|
||||
lua_rawgeti( L, nInd, 4) ;
|
||||
Vector3d vtDirZ ;
|
||||
if ( ! LuaGetParam( L, -1, vtDirZ))
|
||||
return false ;
|
||||
lua_pop( L, 1) ;
|
||||
// assegno il riferimento
|
||||
return frPar.Set( ptOrig, vtDirX, vtDirY, vtDirZ) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, Color& colPar)
|
||||
{
|
||||
if ( ! lua_istable( L, nInd))
|
||||
return false ;
|
||||
int nCol[4] ;
|
||||
// red, gree, blue
|
||||
for ( int i = 1 ; i <= 3 ; ++ i) {
|
||||
lua_rawgeti( L, nInd, i) ;
|
||||
if ( ! lua_isnumber( L, -1))
|
||||
return false ;
|
||||
nCol[i-1] = int( lua_tonumber( L, -1) + 0.5) ;
|
||||
lua_pop( L, 1) ;
|
||||
}
|
||||
// alpha opzionale
|
||||
lua_rawgeti( L, nInd, 4) ;
|
||||
if ( lua_isnumber( L, -1))
|
||||
nCol[3] = int( lua_tonumber( L, -1) + 0.5) ;
|
||||
else
|
||||
nCol[3] = 100 ;
|
||||
lua_pop( L, 1) ;
|
||||
// assegno il colore
|
||||
colPar.Set( nCol[0], nCol[1], nCol[2], nCol[3]) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, INTVECTOR& vPar)
|
||||
{
|
||||
vPar.clear() ;
|
||||
if ( lua_isnumber( L, nInd)) {
|
||||
int nVal = int( lua_tointeger( L, nInd)) ;
|
||||
vPar.push_back( nVal) ;
|
||||
return true ;
|
||||
}
|
||||
else if ( lua_istable( L, nInd)) {
|
||||
// lunghezza della tavola
|
||||
lua_len( L, nInd) ;
|
||||
if ( ! lua_isnumber( 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_isnumber( L, -1))
|
||||
return false ;
|
||||
int nVal = int( lua_tointeger( L, -1)) ;
|
||||
vPar.push_back( nVal) ;
|
||||
lua_pop( L, 1) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, PNTVECTOR& vPar)
|
||||
{
|
||||
vPar.clear() ;
|
||||
Point3d ptP ;
|
||||
if ( LuaGetParam( L, nInd, ptP)) {
|
||||
vPar.push_back( ptP) ;
|
||||
return true ;
|
||||
}
|
||||
else if ( lua_istable( L, nInd)) {
|
||||
// lunghezza della tavola
|
||||
lua_len( L, nInd) ;
|
||||
if ( ! lua_isnumber( 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) ;
|
||||
Point3d ptP ;
|
||||
if ( ! LuaGetParam( L, -1, ptP))
|
||||
return false ;
|
||||
vPar.push_back( ptP) ;
|
||||
lua_pop( L, 1) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, PNTUVECTOR& vParW)
|
||||
{
|
||||
vParW.clear() ;
|
||||
POINTU ptPW ;
|
||||
if ( LuaGetParam( L, nInd, ptPW)) {
|
||||
vParW.push_back( ptPW) ;
|
||||
return true ;
|
||||
}
|
||||
else if ( lua_istable( L, nInd)) {
|
||||
// lunghezza della tavola
|
||||
lua_len( L, nInd) ;
|
||||
if ( ! lua_isnumber( L, -1))
|
||||
return false ;
|
||||
int nLen = int( lua_tointeger( L, -1)) ;
|
||||
lua_pop( L, 1) ;
|
||||
vParW.reserve( nLen) ;
|
||||
for ( int i = 1 ; i <= nLen ; ++ i) {
|
||||
lua_rawgeti( L, nInd, i) ;
|
||||
POINTU ptPW ;
|
||||
if ( ! LuaGetParam( L, -1, ptPW))
|
||||
return false ;
|
||||
vParW.push_back( ptPW) ;
|
||||
lua_pop( L, 1) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L, const Vector3d& vtPar)
|
||||
{
|
||||
try {
|
||||
lua_createtable( L, 3, 0) ;
|
||||
for ( int i = 1 ; i <= 3 ; ++ i) {
|
||||
lua_pushnumber( L, vtPar.v[i-1]) ;
|
||||
lua_rawseti( L, -2, i) ;
|
||||
}
|
||||
}
|
||||
catch( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L, const Point3d& ptPar)
|
||||
{
|
||||
try {
|
||||
lua_createtable( L, 3, 0) ;
|
||||
for ( int i = 1 ; i <= 3 ; ++ i) {
|
||||
lua_pushnumber( L, ptPar.v[i-1]) ;
|
||||
lua_rawseti( L, -2, i) ;
|
||||
}
|
||||
}
|
||||
catch( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L, const Frame3d& frPar)
|
||||
{
|
||||
try {
|
||||
// creo tavola per frame
|
||||
lua_createtable( L, 4, 0) ;
|
||||
// creo tavola per origine
|
||||
lua_createtable( L, 3, 0) ;
|
||||
lua_pushnumber( L, frPar.Orig().x) ;
|
||||
lua_rawseti( L, -2, 1) ;
|
||||
lua_pushnumber( L, frPar.Orig().y) ;
|
||||
lua_rawseti( L, -2, 2) ;
|
||||
lua_pushnumber( L, frPar.Orig().z) ;
|
||||
lua_rawseti( L, -2, 3) ;
|
||||
// la metto nel frame
|
||||
lua_rawseti( L, -2, 1) ;
|
||||
// creo tavola per versore X
|
||||
lua_createtable( L, 3, 0) ;
|
||||
lua_pushnumber( L, frPar.VersX().x) ;
|
||||
lua_rawseti( L, -2, 1) ;
|
||||
lua_pushnumber( L, frPar.VersX().y) ;
|
||||
lua_rawseti( L, -2, 2) ;
|
||||
lua_pushnumber( L, frPar.VersX().z) ;
|
||||
lua_rawseti( L, -2, 3) ;
|
||||
// la metto nel frame
|
||||
lua_rawseti( L, -2, 2) ;
|
||||
// creo tavola per versore Y
|
||||
lua_createtable( L, 3, 0) ;
|
||||
lua_pushnumber( L, frPar.VersY().x) ;
|
||||
lua_rawseti( L, -2, 1) ;
|
||||
lua_pushnumber( L, frPar.VersY().y) ;
|
||||
lua_rawseti( L, -2, 2) ;
|
||||
lua_pushnumber( L, frPar.VersY().z) ;
|
||||
lua_rawseti( L, -2, 3) ;
|
||||
// la metto nel frame
|
||||
lua_rawseti( L, -2, 3) ;
|
||||
// creo tavola per versore Z
|
||||
lua_createtable( L, 3, 0) ;
|
||||
lua_pushnumber( L, frPar.VersZ().x) ;
|
||||
lua_rawseti( L, -2, 1) ;
|
||||
lua_pushnumber( L, frPar.VersZ().y) ;
|
||||
lua_rawseti( L, -2, 2) ;
|
||||
lua_pushnumber( L, frPar.VersZ().z) ;
|
||||
lua_rawseti( L, -2, 3) ;
|
||||
// la metto nel frame
|
||||
lua_rawseti( L, -2, 4) ;
|
||||
}
|
||||
catch( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L, const Color& colPar)
|
||||
{
|
||||
try {
|
||||
lua_createtable( L, 4, 0) ;
|
||||
lua_pushinteger( L, colPar.GetIntRed()) ;
|
||||
lua_rawseti( L, -2, 1) ;
|
||||
lua_pushinteger( L, colPar.GetIntGreen()) ;
|
||||
lua_rawseti( L, -2, 2) ;
|
||||
lua_pushinteger( L, colPar.GetIntBlue()) ;
|
||||
lua_rawseti( L, -2, 3) ;
|
||||
lua_pushinteger( L, colPar.GetIntAlpha()) ;
|
||||
lua_rawseti( L, -2, 4) ;
|
||||
}
|
||||
catch( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2015-2015
|
||||
//----------------------------------------------------------------------------
|
||||
// File : EGnLuaAux.h Data : 21.03.15 Versione : 1.6c6
|
||||
// Contenuto : Funzioni per gestione parametri generali con LUA.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 21.03.15 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//--------------------------- Include ----------------------------------------
|
||||
#include "/EgtDev/Extern/Lua/Include/lua.hpp"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
#define LuaCheckParam(L,I,P) { if ( ! LuaGetParam(L,I,P)) return luaL_error( L, " Invalid Parameter # " #I) ;}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, bool& bPar)
|
||||
{
|
||||
if ( ! lua_isboolean( L, nInd))
|
||||
return false ;
|
||||
bPar = ( lua_toboolean( L, nInd) != 0) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, int& nPar)
|
||||
{
|
||||
if ( ! lua_isnumber( L, nInd))
|
||||
return false ;
|
||||
double dVal = lua_tonumber( L, nInd) ;
|
||||
nPar = int( dVal + (( dVal > 0) ? 0.5 : - 0.5)) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, double& dPar)
|
||||
{
|
||||
if ( ! lua_isnumber( L, nInd))
|
||||
return false ;
|
||||
dPar = lua_tonumber( L, nInd) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaGetParam( lua_State* L, int nInd, std::string& sPar)
|
||||
{
|
||||
if ( ! lua_isstring( L, nInd))
|
||||
return false ;
|
||||
sPar = lua_tostring( L, nInd) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaClearStack( lua_State* L)
|
||||
{
|
||||
int n = lua_gettop( L) ;
|
||||
if ( n > 0)
|
||||
lua_pop( L, n) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L)
|
||||
{
|
||||
try {
|
||||
lua_pushnil( L) ;
|
||||
}
|
||||
catch ( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L, bool bPar)
|
||||
{
|
||||
try {
|
||||
lua_pushboolean( L, ( bPar ? 1 : 0)) ;
|
||||
}
|
||||
catch ( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L, int nPar)
|
||||
{
|
||||
try {
|
||||
lua_pushinteger( L, nPar) ;
|
||||
}
|
||||
catch ( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L, double dPar)
|
||||
{
|
||||
try {
|
||||
lua_pushnumber( L, dPar) ;
|
||||
}
|
||||
catch ( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool
|
||||
LuaSetReturn( lua_State* L, const std::string& sPar)
|
||||
{
|
||||
try {
|
||||
lua_pushstring( L, sPar.c_str()) ;
|
||||
}
|
||||
catch ( ...) {
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2015-2015
|
||||
//----------------------------------------------------------------------------
|
||||
// File : EgnLuaMgr.h Data : 21.03.15 Versione : 1.6c6
|
||||
// Contenuto : Dichiarazione della classe LuaMgr.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 21.03.15 DS Creazione modulo.
|
||||
//
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
//----------------------- Macro per import/export -----------------------------
|
||||
#undef EGN_EXPORT
|
||||
#if defined( I_AM_EGN) // da definirsi solo nella DLL
|
||||
#define EGN_EXPORT __declspec( dllexport)
|
||||
#else
|
||||
#define EGN_EXPORT __declspec( dllimport)
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
struct lua_State ;
|
||||
typedef int(*PFLUA) ( lua_State*) ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class LuaMgr
|
||||
{
|
||||
public :
|
||||
EGN_EXPORT LuaMgr( void)
|
||||
: m_pL( nullptr) {}
|
||||
EGN_EXPORT ~LuaMgr( void)
|
||||
{ Exit() ; }
|
||||
EGN_EXPORT bool Init( void) ;
|
||||
EGN_EXPORT bool Exit( void) ;
|
||||
EGN_EXPORT bool GetVersion( std::string& sLuaVer) ;
|
||||
EGN_EXPORT bool SetLuaLibsDir( const std::string& sDir) ;
|
||||
EGN_EXPORT bool Require( const std::string& sFile) ;
|
||||
EGN_EXPORT bool RegisterFunction( const std::string& sFunName, PFLUA pFun) ;
|
||||
EGN_EXPORT bool EvalNumExpr( const std::string& sExpr, double& dVal) ;
|
||||
EGN_EXPORT bool EvalStringExpr( const std::string& sExpr, std::string& sVal) ;
|
||||
EGN_EXPORT bool ExecLine( const std::string& sLine) ;
|
||||
EGN_EXPORT bool ExecFile( const std::string& sFile) ;
|
||||
EGN_EXPORT const std::string& GetLastError( void) ;
|
||||
|
||||
private :
|
||||
lua_State* m_pL ;
|
||||
std::string m_sLastError ;
|
||||
} ;
|
||||
Reference in New Issue
Block a user