[rkward-cvs] SF.net SVN: rkward:[2684] trunk/rkward/rkward/scriptbackends

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Oct 5 14:06:39 UTC 2009


Revision: 2684
          http://rkward.svn.sourceforge.net/rkward/?rev=2684&view=rev
Author:   tfry
Date:     2009-10-05 14:06:39 +0000 (Mon, 05 Oct 2009)

Log Message:
-----------
Better compatibility with PHP

Modified Paths:
--------------
    trunk/rkward/rkward/scriptbackends/common.js
    trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
    trunk/rkward/rkward/scriptbackends/qtscriptbackend.h

Modified: trunk/rkward/rkward/scriptbackends/common.js
===================================================================
--- trunk/rkward/rkward/scriptbackends/common.js	2009-10-05 14:02:33 UTC (rev 2683)
+++ trunk/rkward/rkward/scriptbackends/common.js	2009-10-05 14:06:39 UTC (rev 2684)
@@ -27,7 +27,7 @@
 	echo ("rk.header(" + quote (title));
 	if (parameters.length) {
 		echo (", parameters=list(");
-		for (p = 0; p < parameters.length; ++p) {
+		for (var p = 0; p < parameters.length; ++p) {
 			if (p) {
 				echo (", ");
 				if (!(p % 2)) echo ("\n\t");
@@ -52,31 +52,41 @@
 }
 
 function flushOutput () {
-	string = this._script_output + "\n";
+	var string = this._script_output;
 	this._script_output = "";
 	return (string);
 }
 
 function do_preprocess () {
-	if (typeof (preprocess) == "undefined") return;
+	if (typeof (preprocess) == "undefined") return ("");
 	preprocess ();
 	return (flushOutput ());
 }
 
 function do_calculate () {
-	if (typeof (calculate) == "undefined") return;
+	if (typeof (calculate) == "undefined") return ("");
 	calculate ();
 	return (flushOutput ());
 }
 
 function do_printout () {
-	if (typeof (printout) == "undefined") return;
+	if (typeof (printout) == "undefined") return ("");
 	printout ();
 	return (flushOutput ());
 }
 
 function do_preview () {
-	if (typeof (preview) == "undefined") return;
+	if (typeof (preview) == "undefined") return ("");
 	preview ();
 	return (flushOutput ());
 }
+
+// for compatibility with the converted PHP code
+function trim (text) {
+	var ret = text.replace (/^\s*/, "").replace (/\s*$/, "");
+	return (ret);
+}
+
+function str_replace (needle, replacement, haystack) {
+	return (haystack.split (needle).join (replacement));
+}

Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp	2009-10-05 14:02:33 UTC (rev 2683)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp	2009-10-05 14:06:39 UTC (rev 2684)
@@ -39,7 +39,7 @@
 QtScriptBackend::~QtScriptBackend () {
 	RK_TRACE (PHP);
 
-	if (script_thread) script_thread->terminate ();
+	if (script_thread && script_thread->isRunning ()) script_thread->terminate ();
 }
 
 bool QtScriptBackend::initialize (RKComponentPropertyCode *code_property, bool add_headings) {
@@ -70,7 +70,7 @@
 	RK_TRACE (PHP);
 	if (!dead) {
 		dead = true;
-		if (script_thread) script_thread->terminate ();
+		if (script_thread) script_thread->kill ();
 		QTimer::singleShot (10000, this, SLOT (deleteLater()));	// don't wait for ever for the process to die, even if it's somewhat dangerous
 	}
 
@@ -138,6 +138,7 @@
 
 	_commonfile = commonfile;
 	_scriptfile = scriptfile;
+	killed = false;
 }
 
 QtScriptBackendThread::~QtScriptBackendThread () {
@@ -164,13 +165,15 @@
 	mutex.unlock ();
 }
 
-QString QtScriptBackendThread::getValue (const QString &identifier) {
+QVariant QtScriptBackendThread::getValue (const QString &identifier) {
 	RK_TRACE (PHP);
 
 	emit (needData (identifier));
 
 	QString ret;
 	while (1) {
+		if (killed) return QVariant ();
+
 		mutex.lock ();
 		if (!_data.isNull ()) {
 			ret = _data;
@@ -178,10 +181,14 @@
 		}
 		mutex.unlock ();
 
-		if (!ret.isNull ()) return (ret);
+		if (!ret.isNull ()) break;
 
 		usleep (20);	// getValue () may be called very often, and we expect an answer very soon, so we don't sleep too long.
 	}
+
+	// return "0" as numeric constant. Many plugins rely on this form PHP times.
+	if (ret == "") return (QVariant (0.0));
+	else return (QVariant (ret));
 }
 
 bool QtScriptBackendThread::scriptError () {
@@ -234,6 +241,8 @@
 
 	QString command;
 	while (1) {
+		if (killed) return;
+
 		mutex.lock ();
 		if (!_command.isNull ()) {
 			command = _command;

Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.h
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.h	2009-10-05 14:02:33 UTC (rev 2683)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.h	2009-10-05 14:06:39 UTC (rev 2684)
@@ -67,12 +67,13 @@
 
 	void setCommand (const QString &command);
 	void setData (const QString &data);
+	void kill () { killed = true; };
 signals:
 	void commandDone (const QString &result);
 	void needData (const QString &identifier);
 	void error (const QString &error);
 protected slots:
-	QString getValue (const QString &identifier);
+	QVariant getValue (const QString &identifier);
 	bool includeFile (const QString &filename);
 protected:
 	void run ();
@@ -87,6 +88,8 @@
 
 	QScriptEngine engine;
 
+	bool killed;
+
 	QMutex mutex;
 };
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list