[texworks] Scripting: Libraries: FYI - compilation of equivalent PHP functions for Qt/JavaScript

Paul A Norman paul.a.norman at gmail.com
Sun Oct 31 22:59:33 CET 2010


On 1 November 2010 02:03, Stefan Löffler <st.loeffler at gmail.com> wrote:
> Hi,
>
> Am 2010-10-22 06:43, schrieb Paul A Norman:
>>       "Use PHP functions in JavaScript"
>>
>>   http://phpjs.org/pages/home
>>
>> Some very clever fellows have ported a considerable number of string
>> handling, array handling and other potentially very useful functions
>> across from php to EMCA style scripting, and made them all work as per
>> the PHP manual (documentation as it already exists).
>>
>>   http://phpjs.org/functions/index
>

With the .js I mentioned in the previous post there are at a guess
approximately 7-8,000 out of 10,000 lines of immediately useful code
(mostly Array and string handling) ready to go! (I'm using it
regularly now) This is because php obviously had to develop string
handling to something of an art being what it is.

The load-in time is surprisingly quick, especially given the route I
am using for now for getting it off disk and into memory as an object.

> Thanks for sharing. This is indeed very interesting! I'll have to look
> into this some time in more detail...
>
>> (I was thinking these may be useful for Qt scripting? There are of
>> course many things that would never be used - and perhaps a core set
>> of things we could tie into the TwApi perhaps thorugh a wrapper? like
>> a specialized  file_get_contents()  etc ...
>
> Is file_get_contents() working with Tw? As far as I can gather, it is
> based on an Ajax request - so, very internet specific. I wouldn't expect
> this to work with the normal Qt scripting engine, especially without the
> webbrowser control functionality, but maybe I'm wrong.

No you are absolutely right. But I'm not doing it from my $PhpJs = new
PHP_JS(),  those are some of the things that I alluded to in a
previous post on this which would need to be edited (left out even) in
PHP_JS(), I'm doing it like this with another wrapper object $Tw,

           alert : function(text){
                                 TW.information(null, "TeXWorks Message", text);

                                 },   // End. Tw.alert();

Tw.file_get_contents ...

        $Tw.alert( $Tw.file_get_contents("c:/windows/php.ini") );

http://dl.dropbox.com/u/13401476/general_images/texWorks_%24Tw.alert%28%20%24Tw.file_get_contents%28.jpg

and in $Tw it is defined for now, until we have various things in
scripting (the advantage of wrappers), as in this portion of
(mod_general.js):-

file_get_contents : function(fileNameFullPath){
                                var scriptRoot =
this.callingScript.scriptNamePath.substr(0,

this.callingScript.scriptNamePath.lastIndexOf("/")) ;
                                    scriptRoot =
scriptRoot.substr(0,scriptRoot.lastIndexOf("/") +1) ;

                                var loadFile =  "\"" + scriptRoot +
'mod_loadFile.php\" \"'
                                               + fileNameFullPath +
'\"';  // \" to quote spaces in files' paths

                                // Non-windows OSes won't need the cmd /c
                                var text = TW.app.system('cmd /c php '
+  loadFile);
                                return text;
                                 },

and using php (although people could do it in perl or anything else
they have) to avoid the present cluttering of the Tw file menu, and
the time, and distraction of  windows opening and closing in Tw - if
we try to get file contents off disk through current api scripting,

<?php
// mod_loadFile.php

       chdir( dirname ( __FILE__ ) ); // for JS library loading calls
thi is not __FILE__ of Tw but the .php

   $openThis =  $argv[1];

   $text = file_get_contents( $openThis);
   echo $text;

?>

I'm also hoping today to work through common routines for tapping
MySql databases for content, filling Tw drop down boxes etc, -- for
now until we can mix objects (Lua/Python/QtScript) thorugh
TW.system() anything Php/perl whatever  addresses can be used for a
database, .csv files even. Among other things, I'm using this process
for bibliographical references and copyright notices I need to place
frequently and consistently.

Extending TeXworks through scripting rocks!

Paul

>
> Cheers,
> Stefan
>



More information about the texworks mailing list