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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Tue Jul 06, 2010 6:08 am   

Alternative methods of concatting a function name?
 
In the following example, on the last line, is there any way to get rid of the %eval function? I do need to use the value of @prefix as part of the functions name.

Code:
#var prefix "test"
#var testvar "variable"
#function testfunction "#return function"
#print @{%concat(@prefix, "var")}
#print %eval(@%concat(@prefix, "function()"))
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4701
Location: Pensacola, FL, USA

PostPosted: Tue Jul 06, 2010 7:35 am   
 
$test=%concat("@", @prefix, "function()")
#PRINT $test

Untested, but it seems sound to me
_________________
Discord: Shalimarwildcat
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Tue Jul 06, 2010 7:38 am   
 
Nope, that simply prints out '@testfunction()'
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4701
Location: Pensacola, FL, USA

PostPosted: Tue Jul 06, 2010 7:46 am   
 
#EXEC {#PRINT @%concat(@prefix, "function()")}
#EXEC {#PRINT @@{prefix}function()}
_________________
Discord: Shalimarwildcat
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Tue Jul 06, 2010 8:21 am   
 
Hrm, that indeed works. Not sure that's any better than %eval, though.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Jul 06, 2010 2:09 pm   
 
No, this is one of the few situations that you actually need to use %eval or #exec.
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Jul 06, 2010 5:00 pm   
 
Yeah, no way to avoid some sort of %eval or exec in this case. Since CMUD can't know the name of the function at compile time, it needs %eval to get it at runtime.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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