inspired from Imk0tter's msl++ this demonstrates how you can use oop-style coding in mIRC
mIRC OOP protocals
the purpose of this script is not to give true, 100% OOP support, instead it is to create a more user-friendly
style of coding that is syntactically similar and can be easily executed with minimal loss in run-time (in some instances is actually faster)
processing and is designed to require no foreign functions in order for ease of use and stability across mIRC versions
Examples:
Method visibility:[ul]
[li] Methods are functions declared in an object[/il]
[] Methods may either be public or private (they cannot be declared 'protected' as there is no support for class extentions)
[] Declaring a method public is not necissary as all methods not declared private are assumed to be public
[] All properties are public and may not be declared private due to the simplicity and lack of security for retrieving data
[] Declaring visibility of a method: alias class.example.PRIVATE
Properties:
[] For future reference a property is simply a variable declared in an object
[] Declaring a property: $class(united states).country ($class().country will return "united states")
Notes:
[] $class().function(a,b) is a valid method, however, $class().function is interpreted as property and not a method
[] Data may be passed in two ways, 1) $class().function(data) 2) $class(data).function() (Method 2 is recommended)
[] Note that () is still required to symbolize that you are passing a method and not a property, and due to the way
[*] mIRC works, if you choose the first method all data passed must be one word and may not be an identifier, i.e. $time
[/ul]
Credits:
Imk0tter - original concept (that i was able to find) | http://forum.swiftirc.net/viewtopic.php?f=34&t=22909
/*
mIRC OOP protocals
@@DISCLAIMER the purpose of this script is not to give true, 100% OOP support, instead it is to create a more user-friendly
style of coding that is syntactically similar and can be easily executed with minimal loss in run-time (in some instances is actually faster)
processing and is designed to require no foreign functions in order for ease of use and stability across mIRC versions
Examples:
* Initialization example (w/o params): $class().init()
* Init example (w/ params): $class().init(date,user,data)
Method visibility:
* Methods are functions declared in an object
* Methods may either be public or private (they cannot be declared 'protected' as there is no support for class extentions)
* Declaring a method public is not necissary as all methods not declared private are assumed to be public
* All properties are public and may not be declared private due to the simplicity and lack of security for retrieving data
* Declaring visibility of a method: alias class.example.PRIVATE
Properties:
* For future reference a property is simply a variable declared in an object
* Declaring a property: $class(united states).country ($class().country will return "united states")
Notes:
* $class().function(a,b) is a valid method, however, $class().function is interpreted as property and not a method
* Data may be passed in two ways, 1) $class().function(data) 2) $class(data).function() *(Method 2 is recommended)
* Note that () is still required to symbolize that you are passing a method and not a property, and due to the way
* mIRC works, if you choose the first method all data passed must be one word and may not be an identifier, i.e. $time
Credits:
Imk0tter - original concept (that i was able to find) | http://forum.swiftirc.net/viewtopic.php?f=34&t=22909
*/
alias class.example.PRIVATE
alias class {
var %this = class | ; Name of object (alias name)
var %hashSize = 5 | ; Default size of hash table that stores properties
/*
* Start of data parsing
* Do not edit
*/
.noop $regex(prop,$prop,/^(\w+)(\x28(.+)?\x29)?/)
var %prop = $iif($regml(prop,1),$regml(prop,1),init),%param = $iif($regml(prop,3),$v1,$null)
if (%param) { .tokenize 44 %param }
if (!$hget(%this) && %prop != init) { echo -a * Error: Object not initialized | halt }
if ($isalias($+(%this,.,%prop,.PRIVATE))) { echo -a * ERROR: Unable to access Method $qt(%prop) | halt }
if ($regml(prop,0) == 1) { $iif($1,.hadd %this %prop $1,return $hget(%this,$prop)) | halt }
$iif($isalias($+(%this,.,%prop)),noop $+($,%this,.,%prop,$chr(40),%prop,$chr(44),$1-,$chr(41)),.goto %prop)
halt ; | prevent script from passing this point
/*
* Class methods
* Start editing here
*/
:init
if ($hget(%this)) {
echo -a * Error: Object $qt(%this) already exists.
halt
}
.hmake %this %hashSize
return 1
:destroy
if ($hget(%this)) { .hfree %this }
return 1
:error
echo -a $iif($error,$v1,Unknown error) in Class: $qt(%this)
if ($hget(%this)) { .hfree %this }
.reseterror
return 0
}
alias class.example {
echo -a Example alias, cannot be called from outside of the class alias
}
example demonstrating its use in sockets to retrieve the title of a web page
alias socket {
; name of object (alias name)
var %this = socket
/*
* start of data parsing
* do not edit
*/
.noop $regex(prop,$prop,/^(\w+)(\x28(.+)?\x29)?/)
var %prop = $iif($regml(prop,1),$regml(prop,1),init),%param = $iif($regml(prop,3),$v1,$null)
if (%param) { .tokenize 44 %param }
if (!$hget(%this)) { .hmake %this 5 }
if (!$1 && $regml(prop,0) == 1) { return $hget(%this,$prop) }
.goto %prop
/*
* start of class methods
*/
:init
if (!$sock($$1) || !$3) {
.noop $regex($2,/(?:https?\x3A\/\/)?(?:www\.)?([\w]+\..{2,3})(\/[\w]+(?:\..{1,})?)?/)
if (!$regml(1)) {
echo -a Invalid URI
.noop $socket().destroy()
return 0
}
var %a = $+(www.,$regml(1)),%b = $iif($regml(2),$v1,/)
.sockopen $1 %a $iif($4,$4,80)
.hadd %this sockData $(GET %b HTTP/1.1,|,HOST: %a)
.hadd %this sockname $1
.hadd %this cb_funct $3
}
else {
echo -a socket $qt($1) already exists
.noop $socket().destroy()
return 0
}
return 1
:addData
if (!$3) { .hadd %this $1 $$2 }
elseif ($3) { .hadd %this $1 $addtok($hget(%this,$1),$2 $3,124) }
return 1
:destroy
if ($sock($hget(%this,sockname))) { .sockclose $hget(%this,sockname) }
if ($hget(%this)) { .hfree %this }
return 1
:open
var %a = .sockwrite -n $1,%b = $hget(%this,sockData),%c = 1
.tokenize 124 %b
while ($ [ $+ [ %c ] ]) {
%a $v1
inc %c
}
%a $crlf
return 1
:read
var %socket = $hget(%this,sockname),%cb = $hget(%this,cb_funct)
%cb %socket
return 1
:error
echo -a $iif($error,$v1,Unknown error) in Class: $qt(%this)
.noop $socket().destroy()
.reseterror
return 0
}
alias socket_example {
var %a = $socket(sockex,$$1,socket_read)
if (!%a) {
echo -a Unable to connect.
.noop $socket().destroy()
}
}
alias socket_read {
sockread &data
if ($regex($bvar(&data,1-).text,/<title>(.+?)<\/title>/)) {
echo -a $regml(1)
.noop $socket().destroy()
}
}
on *:sockopen:sockex:.noop $socket($sockname).open()
on *:sockread:sockex:.noop $socket().read()
usage: /socket_example www.google.com