Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Fri Dec 08, 2006 10:49 am   

[1.24] #EXEC stripping spaces from matches
 
If you assign a variable inside an #EXEC then it removes any spaces

Code:
#TRIGGER {test123 (*)} {
  var1 = %-1
  #EXEC {var2 = %-1}
  #SAY @var1
  #SAY @var2
}


using
Quote:
test123 asd asd asd


returns
Quote:
asd asd asd
asdasdasd
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)

Last edited by Guinn on Sat Dec 16, 2006 3:10 pm; edited 1 time in total
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Dec 08, 2006 9:57 pm   
 
Well, it's an odd result, but what you are doing is undefined.

Remember that the %-1 will get filled in when creating the string sent to #exec. So when you type

test123 this is a test

then you are calling this:

var2 = this is a test

And this is where the problem is. You don't have quotes or anything around your string. So what should CMUD do with this? Should it include the space after the = sign in the value? If not, then what about other whitespace? Unless you put quotes or {} around your string, whitespace isn't preserved.

So, the correct script would have:

#EXEC {var2 = "%1"}
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Dec 08, 2006 10:46 pm   
 
This actually becomes very confusing. You are saying that we should revert to the old zMud kludge of shoving %xx into quotes whenever we have to put it into an #EXECUTE. #EXECUTE should parse and evaluate its parameters the same as every other script portion, this has always been the case. What you said in your last post would make #EXEC an exception and I don't really want to see such an inconsistency in CMud. Please reconsider how you view this, even if it it something to be addressed after the public release.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Dec 08, 2006 11:24 pm   
 
No. It's not #EXEC that is parsing it's parameters. You are calling #EXEC with a single parameter, which is a string value. The %-1 gets evaluated when this string is formed.

Look at this test alias:

#ALIAS test {#EXEC {var = %-1}}

If you look at the compiled code for the alias, you will see something like this:
Code:
0000   LINE   1   ; #EXEC {var = %-1}
0012   PUSHSTRLOC   0028
0020   JUMP   0056
0028   STR   'var = '
0044   PARAMREF   -1
0052   CONCAT   
0056   ARGSTR   var = %-1
0076   CMD   execute   (1)

OK, look at lines 28, 44, and 52. This is creating the argument for the #EXEC command. It pushes the literal string "var = " onto the stack, then pushes the %-1 (PARAMREF) onto the stack, then CONCATs them. Then this is passed to the execute CMD. (ignore the ARGSTR...it's just a comment field for my debugging).

This is *exactly* what you want. Using #EXEC is a way to simulate the old zMUD way of handling %-1. It forces it to get expanded before the string itself is parsed and executed.

So, when you call this alias with:

test hello world

then it pushes "var = " onto the stack, then pushes the value of %-1 onto the stack (which is the string "hello world"), then does a CONCAT. So now the stack hold the string value "var = hello world" and this is passed to #EXEC.

So, #EXEC is *not* an exception to this. #EXEC takes a single STRING argument which is then executed.

With the script

#ALIAS test {#EXEC {var = "%-1"}}

you get the compiled code:
Code:
0000   LINE   0   ; #EXEC {var2 = "%-1"}
0012   PUSHSTRLOC   0028
0020   JUMP   0048
0028   STR   'var2 = %-1'
0048   ARGSTR   var2 = "%-1"
0068   CMD   execute   (1)

Here, notice the the quotes around %-1 prevented it from being expanded as a variable. It was parsed as a literal string and appended to the "var2 = " string. So now #EXEC is executing "var2 = %-1" which gives the correct result.

So, there isn't any inconsistency here. It's working normally as it should with no exceptions.
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Sat Dec 16, 2006 3:10 pm   
 
I'm with Vij on this, it does seem counter intuitive. Anyway, got another example, please see
http://forums.zuggsoft.com/phpbb/viewtopic.php?t=25966
for where putting a value in quotes breaks what #EXEC was trying to fix
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net