|
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: 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()")) |
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4701 Location: Pensacola, FL, USA
|
Posted: Tue Jul 06, 2010 7:35 am |
$test=%concat("@", @prefix, "function()")
#PRINT $test
Untested, but it seems sound to me |
|
_________________ Discord: Shalimarwildcat |
|
|
|
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Tue Jul 06, 2010 7:38 am |
Nope, that simply prints out '@testfunction()'
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4701 Location: Pensacola, FL, USA
|
Posted: Tue Jul 06, 2010 7:46 am |
#EXEC {#PRINT @%concat(@prefix, "function()")}
#EXEC {#PRINT @@{prefix}function()} |
|
_________________ Discord: Shalimarwildcat |
|
|
|
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Tue Jul 06, 2010 8:21 am |
Hrm, that indeed works. Not sure that's any better than %eval, though.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Tue Jul 06, 2010 2:09 pm |
No, this is one of the few situations that you actually need to use %eval or #exec.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: 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.
|
|
|
|
|
|