[PATCH 3/3] * exposed the GameObject constructor and object factory= to script code * stripped hyphens from asset names when building identifiers * better error reporting when a script can't be compiled

[ Thread Index | Date Index | More lists.tuxfamily.org/gluon Archives ]


---
 engine/components/scripting/scriptingengine.cpp |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/engine/components/scripting/scriptingengine.cpp b/engine/compon=
ents/scripting/scriptingengine.cpp
index 4618cd6..5b1e5df 100644
--- a/engine/components/scripting/scriptingengine.cpp
+++ b/engine/components/scripting/scriptingengine.cpp
@@ -22,6 +22,8 @@
 #include "scriptingasset.h"
 #include "scriptingcomponent.h"
=20
+#include "core/gluonobjectfactory.h"
+
 #include <QtScript>
 // #include <QScriptEngineDebugger>
=20
@@ -43,6 +45,12 @@ namespace GluonEngine
                 qScriptRegisterMetaType( engine, gluonObjectToScriptValue, =
gluonObjectFromScriptValue );
                 qScriptRegisterMetaType( engine, gameObjectToScriptValue, g=
ameObjectFromScriptValue );
=20
+                QScriptValue gameObjectClass =3D engine->scriptValueFromQMe=
taObject<GameObject>();
+=09=09engine->globalObject().setProperty("GameObject", gameObjectClass);
+
+                QScriptValue objectFactory =3D engine->newQObject( GluonCor=
e::GluonObjectFactory::instance());
+                engine->globalObject().setProperty("Factory", objectFactory=
 );
+
                 DEBUG_TEXT2( "Imported extensions: %1", engine->importedExt=
ensions().join( ", " ) );
=20
                 QScriptValue extensionObject =3D engine->globalObject();
@@ -103,12 +111,18 @@ ScriptingEngine::registerAsset( const ScriptingAsset* =
asset )
     if( result.state() =3D=3D QScriptSyntaxCheckResult::Valid )
     {
         // Fix up the asset's name so as to be useable as a class name
-        QString className( asset->fullyQualifiedName().remove( ' ' ).replac=
e( '/', '_' ) );
+        QString className( asset->fullyQualifiedName().remove( ' ' ).replac=
e( '/', '_' ).replace('-', '_') );
         // Add that to the classes listing
         d->classNames.insert( asset, className );
         // Build the new code
         d->buildScript();
     }
+    else
+    {
+        DEBUG_TEXT(QString("Asset %1 didn't pass the syntax checker (%2)\n"=
)
+                   .arg(asset->fullyQualifiedName())
+                   .arg(result.errorMessage()));
+    }
=20
     return result;
 }
@@ -162,7 +176,8 @@ ScriptingEngine::instantiateClass( const ScriptingAsset*=
 asset ) const
         QScriptValue instance =3D val.construct();
         if( d->engine->hasUncaughtException() )
         {
-            DEBUG_TEXT2( "Exception on class instantiation: %1", d->engine-=
>uncaughtExceptionBacktrace().join( " --> " ) );
+=09=09=09QScriptValue exception =3D d->engine->uncaughtException();
+            DEBUG_TEXT( QString("Exception on class instantiation: %2\n at =
%1").arg(d->engine->uncaughtExceptionBacktrace().join( " --> " )).arg(except=
ion.toString()));
         }
=20
         return instance;
--=20
1.7.1


--=_5td3elsvnk4k--

---
+----------------------------------------------+
Gluon is a high-level game development library for the KDE desktop enviornment.
http://gluon.tuxfamily.org/
http://gitorious.org/gluon



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/