mIRC Home    About    Download    Register    News    Help

Print Thread
References! - Crazy #29957 15/06/03 11:48 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline OP
Hoopy frood
OP Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Ok this is something I've been working on coming up with a way to do it in mIRC, and I think I've finally gotten a decent method. Any C++, Perl, or PHP programmers should already be familiar with pass-by-reference type of things, but I'll clarify for those who aren't. Ever had an identifier that you needed to return multiple values, and since mIRC can't do that, you had to make it write to global vars/hash tables/etc? Example that comes to mind would be something like $disecturl(http://www.test.com:80/file.html) Where you want to split that up into the protocol (http), the hostname (www.test.com) the port (80) and the file (file.html) and return all of that information to the user with a single call. Reference passing allows you to do this in a pretty easy way.

For example the user would do $disecturl(http://www.test.com:80/file.html,%protocol,%hostname,%port,%file) and each of those variables would be filled with the appropriate information. Now the first think you're going to say is mIRC uses $N for the parameters, and you can't write to $N. Well reference support will implement a way that you can.

$reference($N) - returns $true if $N is referencable and $false if it is not.

Only certain things are able to be referenced, for example if I specified "foobar" as the parameter, that can't be referenced, it is text, not something that can have its value changed, similarly if I specified "$foobar" it can't be changed since identifiers can't have their value changed. The only things that $reference would return $true on are variables and binvars. For example:

alias blah {
return $iif($reference($1),yes,no)
}
.echo -a $blah(testing) - returns no
.echo -a $blah(%testing) - returns yes
.echo -a $blah(&testing) - returns yes
.echo -a $blah($testing) - returns no

The next thing needed is to determine if a binvar or a variable was passed, so we know if we actually can write our data to it. To determine this, all that is needed is a property for $reference. $reference($N).type which returns var, binvar, or $null if it is a variable, a binary variable, or not referencable.

Lastly, since you can't write to a $N identifier, there needs to be some way to write to a reference, again $reference can be used. $reference($N,value). What value actually is depends on whether $N was a binvar or a variable. A sample of how this would work:

alias blah {
if (!$reference($1) || $reference($1) != var) return
.echo -q $reference($1,$calc($1 + 1))
return $true
}

var %t = 3
.echo -a $blah(%t)
.echo -a %t -- displays 4, not 3.

This would also have the added ability of letting commands "return" values, i.e. in that last alias blah:

var %t = 6
/blah %t
.echo -a %t -- displays 7.

Re: References! - Crazy #29958 16/06/03 05:21 AM
Joined: Feb 2003
Posts: 309
C
CloCkWeRX Offline
Fjord artisan
Offline
Fjord artisan
C
Joined: Feb 2003
Posts: 309
codemastr! bad!

Ok there are we uber-leet scripters who get such marvels as COM automation and DLLS, and have disocvered coding beyond mIRC.

But what of the rest of the scripters out there? Those, who for want of a better word, suck. Those, who do silly stupid things like:

alias myThing {
/do $what $I $say
}

and barely struggle with the concept of $identifier returns ONE plain STRING thats actualyl rather friendly.

And you want to unleash passing by reference? Its gonna be messy when I get coders asking me
"Whats this error mean:"
* Error: Type mismatch; expects uberCoder, found lameCoder
But still, it would change the way the language works into a more OO fashion, so I guess I'll support it in a limp manner

Re: References! - Crazy #29959 16/06/03 02:53 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline OP
Hoopy frood
OP Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Umm that has to be the most ridiculous comment I've ever heard. You say it shouldn't be implemented, because basic scripters won't understand it? Am I supposed to actually take that response seriously? If they don't understand it, then they don't use it, simple as that.

Re: References! - Crazy #29960 16/06/03 06:46 PM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
actually i like the idea. Passing by refference is done alot in other languages. Id also like to see aggregates of some sort. It would be nice if these and others were integrated however. I think id preffer them over controls


Have Fun smile
Re: References! - Crazy #29961 17/06/03 10:29 AM
Joined: Dec 2002
Posts: 19
M
MiSsInGnO Offline
Pikka bird
Offline
Pikka bird
M
Joined: Dec 2002
Posts: 19
Really interesting...
I hope this will be added in future versions!

Just a few notes:
codemastr, you're not forced to use global vars/hashtables etc... if you want to return multiple values, you can simply use something like that:
Use: $decrypturl(http://www.nospam.here:80/path/to/my/favourite.files)

alias decryptURL {
; Notes:
; - See /help $gettok for help on functions used
; - Actually, %domaine & %fullpath are here just as a demo and won't be used...
; - $chr(47) is "/" and $chr(58) is ":", we use ASCII codes...

var %protocol $gettok($1,1,58), %domaine $gettok($1,2,47), %hote $gettok(%domaine,1,58), %port $gettok(%domaine,2,58), %fullpath $gettok($1,3-,47), %path $deltok(%fullpath,$numtok(%fullpath,47),47), %file $remove(%fullpath,%path,/)

; for %path we do the following:
; - get everything after http://www.nospam.here:80/ (we already stored that in %fullpath, that's why we use it...)
; - remove the part of the string after the last "/" (ie: we remove the file from the %fullpath to get the %path to files smile)

; for %file, it's not a secure way to get the filename, but it works in this demo (we could also do a $gettok($1,$numtok($1,47),47) which is safer, but i wanted a change...)

return %protocol %hote $iif(%port == $null,80,%port) / $+ %path $+ / %file
}

And we could have the following:
alias myURL {

; see /help /tokenize for help on that topic...
; basically, we put each part of the URL in $1, $2, $3 etc...
tokenize 32 $decrypturl(http://www.nospam.here:80/path/to/my/favourite.files)

; we "echo" how to access the page on a channel/query...
say To get to my secret page, you have to connect to $2 on port $3 using the $upper($1) protocol, then browse through $4 until you reach $5 !

; Here is what should show up:
; To get to my secret page, you have to connect to www.nospam.here on port 80 using the HTTP protocol, then browse through /path/to/my/ until you reach favourite.files !
}


++, MiSsInGnO
$gettok, je t'adore wink)

Note: sorry for my bad english
Note 2: this snippet hasn't been tested but should work fine...

Re: References! - Crazy #29962 18/06/03 09:11 AM
Joined: Feb 2003
Posts: 309
C
CloCkWeRX Offline
Fjord artisan
Offline
Fjord artisan
C
Joined: Feb 2003
Posts: 309
I'm not being flamey, but I'm just trying to point out that mIRC is aimed at users who by and large don't script. Those that do, most don't script at a level thats overly high.

K-I-S-S << Keep It Simple Stupid is the whole point behind what I was saying. Thems wisdoms in thems words *solemn nod*.

If they don't get it and don't use it, fine for them. I actually like the idea, I like it a lot. But this (I feel) is where we nutcases need to stop, and think, and go 'does mIRC really need to do...'