I was doing just that, only it was the whole string :]
Like:
var %cmd = echo -a first line
%cmd = %cmd $chr(124) echo -a second line
%cmd = %cmd $chr(124) echo -a last line
$eval(%cmd)
That evaluates the whole thing as a single line command, thus treating everything after the first
echo as plain text.
$eval'ing each command really does the trick, except for when a
if or
while appears =/. I think
$eval is not meant to process command blocks, or maybe it wasn't ever thought through; there's nothing at all about it on the help file, and I haven't found anything similar on the web. In fact, the documentation says it
"(...) allows you to recursively evaluate identifiers and variables in a line of text.", so I'm starting to think code batchs isn't
$eval stuff.
As an alternative, I thought about declaring aliases on the fly, which btw I never imagined to be possible, but it is - the downside: only single-line aliases.
The particular work I'm willing to use it in is an OO interface for mIRCScript, so I'm thinking of using that on declaring methods. Right now I'm using external aliases, but I want to make it possible to declare it inside the class definition.
These are the only methods I could think of for storing blocks of code to execute them later.
I wouldn't say it is a design flaw on
$eval, as surprisingly I've seen no request or anything on that matter, maybe it was never needed. That was the first thing I tried because I'm also a PHP developer and I thought it would be similar to
PHP eval hehe, which interprets a string as normal source code.
But if anyone knows some other way, that would be great help.
Thanks for the help, by the way.
UPDATE: Actually, I just tested, if you "serialize" a block of code into a line and do
$eval(alias someName %code)
and later call the alias, it does the trick; that works well as far as I've tried, but it will add the alias to the default alias file, i.e. aliases.ini
As a workaround, you may remove the alias later by adding it empty (
/alias my_alias), but it's kinda ugly to fill the user aliases file with lots of strange aliases.
Maybe creating a file only for those aliases, or even creating the alias, running it and removing it right away (crazy), I'll see what happens and then I tell the story.
If anybody has a better idea than all this stuff let me know lol