[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  PhpScript (bug report?)

PhpScript (bug report?)

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Faux   United Kingdom  (77 posts)  [Biography] bio
Date Sun 26 Dec 2004 10:30 PM (UTC)
Message
I have PhpScript working (to a degree), as I said in another thread.

I'm now trying, however, to get it called from an alias. This is my first time doing this, so it's posisble I'm doing something wrong...

The problem I'm having is that a variant class is being passed. I have no idea how to get the value out of this. I'm rather confused as to why I have it in the first place seeing as a normal variable in php is a variant anyway.

Any suggestions, is this a bug in MUSH, a bug in the activestate implementation (see end for versions), or me being silly?



Background:

Plan (irrelevant):
I want an alias (randsoul) to call this code, and then to send-to-world a value the function generates (which I think should be pretty standard..?).

Alias:
<aliases>
<alias
script="randsoul"
match="^randsoul(.+)$"
enabled="y"
echo_alias="y"
regexp="y"
sequence="100"
>
</alias>
</aliases>


Script file (yes, the entire script file (no <? seems to be accepted)):

function randsoul($alias_name, $alias_output, $wildcards)
{
ob_start();
print_r($alias_name);
$a=ob_get_contents();
$world->Note($a);
}

And this writes:
variant Object



Note:
function randsoul()
{
co... .... ...de();
}

is valid, so it apparently isn't checking the function specifications.



Versions:
PHP 5.03.
php5ts.dll: 5.0.3.3
php5activescript.dll: 5.0.4.4
mushclient.exe: 3.6.3.0

Winxpprosp2, fully up-to-date.


Faux, from Discworld. Feel free to come talk to me =)

http://faux.servebeer.com/
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 27 Dec 2004 01:11 AM (UTC)

Amended on Mon 27 Dec 2004 01:13 AM (UTC) by Nick Gammon

Message
I tried this with some variable results. First, the PHP implementation is pretty experimental. It *should* work, as it basically uses exactly the same calls internally as other scripts that do work, like VBscript, Jscript, Perlscript.

However ...



  1. A syntax error seems to just make MUSHclient exit, which it shouldn't. (Like, leaving off a semicolon). This is the only language that does that.

  2. If you turn on "warn if scripting inactive" in the scripting configuration, I get an error when calling the alias, that "randsoul" is not found.

  3. When saving the script file I get the error:

    The alias subroutine named "randsoul" could not be found.

  4. I have this version in my script file:

    
    function randsoul ($alias_name, $alias_output, $wildcards)
    {
    //ob_start();
    //print_r($alias_name);
    //$a=ob_get_contents();
    //$world->Note($a);
    $world->Note("test");
    $world->Note("name = " . $alias_name);
    
    }
    


    This should at least print "test", which it does if you put this line into the command window:


    /$world->Note("test");


    Note that if you leave off the semicolon, MUSHclient exits, so save your work first.

  5. If I type (in the command window):


    /randsoul ();


    I get this:

    Call to undefined function randsoul()

    This would seem to agree with the fact that the alias doesn't find it. Which is strange, as it is in the script file.

  6. If I type (in the command window):


    /RANDSOUL ();


    I get this:


    Missing argument 1 for randsoul()
    Missing argument 2 for randsoul()
    Missing argument 3 for randsoul()


    This is 3 separate error boxes, which is also a bit strange. Notice however that although I used the upper-case version to call it, it echoes the lower-case version in the error.


  7. If I type (in the command window):


    /RANDSOUL ("nick", 2, 3);


    I get this:


    test
    name = nick


    So it seems possible to call a PHP function, using the upper-case version, however that does not seem to be exposed by the scripting engine as a COM object, hence the alias can't find it.


It seems to me that the PHP scripting is flaky to say the least.


  • It causes the host application to crash if you have a syntax error.

  • It doesn't expose functions to the COM interface.

  • It seems confused about whether functions are upper or lower-case.

  • It generates multiple error messages when arguments are missing.



As I haven't yet managed to call a script from an alias, the issue of whether or not variants are handled correctly can't be put to the test yet.

Finally I tried to do a "send to script" to do immediate scripting rather than a script file. Here is the modified alias:


<aliases>
  <alias
   match="^randsoul(.+)$"
   enabled="y"
   echo_alias="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>$world-&gt;Note ("Inside alias randsoul");
$world-&gt;Note ("Wildcard 1 is %1");</send>
  </alias>
</aliases>



This seems to work better:


Inside alias randsoul
Wildcard 1 is 5


So, if you do "send to script" scripting, and save each time before testing, you might get somewhere. :)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Faux   United Kingdom  (77 posts)  [Biography] bio
Date Reply #2 on Mon 27 Dec 2004 02:18 AM (UTC)

Amended on Mon 27 Dec 2004 02:31 AM (UTC) by Nick Gammon

Message

  1. I meant to say, I was getting that "The alias subroutine named "randsoul" could not be found." message, but a clean restart of MUSH seemed to fix it (boggle). It now doesn't do this..

  2. I just tried adding another trigger going to another function in the script file, and this runs without whining, too.

  3. It does, however, whine about not being able to find the script function in some old triggers that I have lying around (which arne't enabled). Surely that's a bug (checking functions in disabled triggers)?


  4. On the syntax error things, I've had quite a few where it doesn't. And I'm pretty sure I'm yet to have an error in a script called by an alias that causes MUSH to terminate. Are they called in different ways?

  5. Edit as I'm playing: I just deleted those triggers, and now it can't find randsoul again. And a clean restart didn't fix it.

  6. Just an interesting point.. if you modify the script while a "terminal" error message is on the screen, ie.. after you've typed:
    /functionname()

    And the "Unexpected $end.. etc." dialog is on the screen, the recompile msgbox comes up. Clicking yes to this means that MUSH doesn't crash when you close the script error dialog, but afterwards pretty much everything is broken. Like, scriping (won't even let you press return when there's something begining with "/" (assuming script character) is on the line), and, interestingly, hotkeys (ie. numpad types numbers). You can still (apparently) cleanly shutdown mush, though. It's far to late/early for me to play with a debugger, I'm afraid :). This does, however, give you an oppotunity to save if you forget, so, if you could just leave it in for a little while longer... :p
    Hope that makes sense..

  7. Another thing, not all syntax errors seem to cause a crash, anyway...
    /randymonkey();

    brings up the error dialog with:
    
    No.: 1000
    Call to undefined function randymonkey()
    Line in error: 
    

    Maybe it only dies on.. hmm.. code it can't understand enough to give meaningful debug messages (ie. where the {}s are misformed)?

  8. Next, I haven't noticed any effect with changing the case of the function names.. what version of things are you running?
    I might get the nightly version of both at some point...

    I get the same results as you for 6. and 7.


  9. For your 4 points..

    Quote:
    It causes the host application to crash if you have a syntax error.


    I hate to suggest this, but the reload hack means that.. it might.. just possibly.. be an error on your part? :/

    Quote:
    It doesn't expose functions to the COM interface.


    It must do sometimes, as it was working quitely on mine (for a while) (I promise)... no idea on the conditions though, yet.
    Quote:
    It seems confused about whether functions are upper or lower-case.


    Not afaict...
    Quote:
    It generates multiple error messages when arguments are missing.


    This is possibly a limitation (bug) in the php interpreter.
    Terminal excerpt:
    
    C:\php>php testg.php
    PHP Warning:  Missing argument 1 for test() in C:\php\testg.php on line 2
    
    Warning: Missing argument 1 for test() in C:\php\testg.php on line 2
    PHP Warning:  Missing argument 2 for test() in C:\php\testg.php on line 2
    
    Warning: Missing argument 2 for test() in C:\php\testg.php on line 2
    PHP Warning:  Missing argument 3 for test() in C:\php\testg.php on line 2
    
    Warning: Missing argument 3 for test() in C:\php\testg.php on line 2
    


    testg.php being:
    
    <?
    function test($a, $b, $c)
    {
        echo $a . $b . $c;
    }
    
    test();
    

    Ie. it is actually generating plenty of error messages. To fix this, it'd be a specific case in activeState, or a re-write of the php parser, neither of which sounds particularily tempting.

    Another option is, I suppose.. you could "cache" the error messages until they stop comming in, and then display them in one dialog (assuming the source (to the line number) was the same)?

  10. And, just out of interest.. what's the difference between (faked xml (hope you get what I mean), so bare with me):

    This:
    
    <aliases>
      <alias
       script="randsoul"
       match="^randsoul (.*)$"
       enabled="y"
       regexp="y"
       sequence="100"
      >
      </alias>
    </aliases>
    


    and this?:

    
    <aliases>
      <alias
       match="^randsoul(.+)$"
       enabled="y"
       echo_alias="y"
       regexp="y"
       send_to="12"
       sequence="100"
      >
      <send>randsoul("no idea what these args are..", 
        "no idea what these args are..", 
         array("%1","%2","%3 ...etc...."));
    </send>
      </alias>
    </aliases>
    



  11. And, I can promise you that variants aren't being handled correctly :) Any ideas what functions/methods/values this class has on it, so (if I get it running again) I can call them?



Faux
*prays that she got the forum codes right*

edits: Trying to spot typos in tags.

Faux, from Discworld. Feel free to come talk to me =)

http://faux.servebeer.com/
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Mon 27 Dec 2004 02:36 AM (UTC)
Message
Quote:

Another thing, not all syntax errors seem to cause a crash, anyway...

/randymonkey();

brings up the error dialog with:

No.: 1000
Call to undefined function randymonkey()


That's not a syntax error, it's a semantic error.

This is a syntax error:


/randymonkey(


(no closing bracket or semicolon).

This is a semantic error:


/randymonkey();


Function randymonkey does not exist. Syntactically it is correct.


Quote:

And, just out of interest.. what's the difference between (faked xml (hope you get what I mean), ...


The difference is one calls a script in your script file, which it locates in advance of being needed (ie, it is precompiled).

The second one calls the script engine in "immediate" mode to parse the commands when needed. Thus the script file technique is slightly faster, but requires a separate script file, and it complains if it can't find the function.

The "send to script" will work without a script file, and any errors are only detected when the alias actually executes.

Quote:

I hate to suggest this, but the reload hack means that.. it might.. just possibly.. be an error on your part? :/


Well, maybe. But I didn't re-code everything for PHP script. The same code works for Jscript and VBscript, and it is all basically the same except for the name of the script engine it is calling.



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sat 03 Dec 2005 08:28 PM (UTC)
Message
For an update on this, see PHP Engine In MUSHclient 3.65.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,070 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]