this implementation actually brings all 3 of those aspects of OOP to mIRC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description: This class can be used as a simulate a ;
; stack. It inherits from my List class, so any method ;
; that can be used on an list, can also be used on a ;
; stack. ;
; ;
; Usage: $Stack(<uID>,<Params>,...).<Member> ;
; Example: var %itemID = $stack(%x,%text).push ;
; Example: var %text = $stack(%x).pop ;
; Example: var %x $stack(%x).Count ;
; Example: $stack(%x).Clear ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Public Declarations ;
;;;;;;;;;;;;;;;;;;;;;;;
alias Stack.DELETE.Public
alias Stack.Push.Public
alias Stack.Pop.Public
alias Stack.Clear.Public
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Exception Declarations ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
alias Stack.Exception.RangeErr return Out of Bounds!
;;;;;;;;;;;;;;;;;;
; Stack Alias ;
;;;;;;;;;;;;;;;;;;
alias Stack {
if (!$prop) goto init
if ($IsPublic(Stack,$prop)) goto $prop
return $catch($1,MemberErr, $qt($prop) is not a public member of Stack)
:init
return $Stack.INIT($1)
:delete
return $Stack.DELETE($1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Put your own method handlers here ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:Push
var %x $list($1,$2).add
return
:Pop
if $list($1).count {
var %y $list($1,$v1).get
$list($1,$v1).remove
return %y
}
return
:Clear
while ($list($1).count) {
$list($1,1).remove
}
return
}
;;;;;;;;;;;;;;;;;;;;
; Stack Methods ;
;;;;;;;;;;;;;;;;;;;;
alias Stack.INIT {
if ($instanceOf($1,list)) return $inheritsFrom($1,Stack)
var %instance $List
$inheritsFrom(%instance,Stack)
;;;;;;;;;;;;;;;;;;;;;;;;
; Do Initializing here ;
;;;;;;;;;;;;;;;;;;;;;;;;
return %instance
}
alias Stack.DELETE {
;;;;;;;;;;;;;;;;;;;;;;
; Do Destroying here ;
;;;;;;;;;;;;;;;;;;;;;;
return $Class($1).DELETE
}
;;;;;;;;;;;;;;;;
; End Stack ;
;;;;;;;;;;;;;;;;
as you can see the Stack class inherits from the List class and List operations can be used on a stack object by using $List(%stackObject,..).listOperation or class operations by using $Class(%stackObject,..).classOperation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description: This class can be used as a dynamically sized ;
; List to store any data type ;
; ;
; Usage: $List(<ListPtr>,<Params>,...).<Member> ;
; Example: var %x = $List ;
; Example: var %itemID = $List(%x,$long(500)).add ;
; Example: $List(%x,%itemID,$long(499)).set ;
; Example: $List(%x,%ItemID).remdel ;
; Example: $List(%x).delete ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;
; Public Declarations ;
;;;;;;;;;;;;;;;;;;;;;;;
alias List.DELETE.Public
alias List.Add.PUBLIC
alias List.Remove.PUBLIC
alias List.Get.PUBLIC
alias List.Count.PUBLIC
alias List.Set.PUBLIC
alias List.Remdel.PUBLIC
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Exception Declarations ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;
; List Alias ;
;;;;;;;;;;;;;;
alias List {
if (!$prop) goto init
if ($IsPublic(List,$prop)) goto $prop
return $catch($1,MemberErr, $qt($prop) is not a public member of List)
:init
return $List.INIT($1)
:delete
return $List.DELETE($1,$2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Put your own method handlers here ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:MethodHandler
:add
return $List.Add($1,$2)
:Remdel
:Remove
return $List.Remove($1,$2)
:get
return $List.Get($1,$2)
:count
return $hget($1,COUNT)
:set
return $List.Set($1,$2,$3)
}
;;;;;;;;;;;;;;;;
; List Methods ;
;;;;;;;;;;;;;;;;
alias List.INIT {
var %instance $Class
$inheritsFrom(%instance,List)
;;;;;;;;;;;;;;;;;;;;;;;;
; Do Initializing here ;
;;;;;;;;;;;;;;;;;;;;;;;;
return %instance
}
alias List.REMOVE {
if $2 !isnum 1- $+ $hget($1,COUNT) { return $catch($1,RangeErr,$qt($2) is not a valid list index for object $qt($1)) }
hdec $1 COUNT
- $Class($1,ITEMS,&items).getb
var %x $calc(1 + (($2 - 1) * 32)),%y %x + 32,%z $bvar(&items,%x,32).text
if %y > $bvar(&items,0) { dec %y }
var %var $bvar(&items,%x,32).text
bcopy -c &items %x &items %y -1
- $Class($1,%var).remv
- $Class($1,ITEMS,&items).setb
}
alias List.ADD {
hinc $1 COUNT
hinc $1 TOTAL
var %x $md5($hget($1,TOTAL))
- $Class($1,ITEMS,&items).getb
bset -t &items $calc(1 + (($hget($1,COUNT) - 1) * 32)) %x
- $Class($1,ITEMS,&items).setb
- $iif($bvar($2,0),$Class($1,%x,$2).setb,$Class($1,%x,$2).setv)
return $hget($1,Count)
}
alias List.GET {
if $2 !isnum 0- $+ $hget($1,COUNT) { return $catch($1,RangeErr,$qt($2) is not a valid list index for object $qt($1) $chr(40) $+ Valid Ranges: 1- $+ $hget($1,COUNT) $+ $chr(41)) }
$iif($2 == 0,return $hget($1,COUNT))
- $hget($1,ITEMS,&items)
var %var2 $bvar(&items,$calc(1 + (($2 - 1) * 32)),32).text
return $hget($1,%var2)
}
alias List.SET {
var %z $bvar(&items,$calc(1 + (($2 - 1) * 32)),32).text
var %x $Class($1,%z).getv
if $IsInstance(%x) { noop $Object(%x).delete }
- $Class($1,%z,$3).setv
}
alias List.IMPORT {
var %x $List($1).count
while %x {
if $ImportObject($List($1,%x).get) {
+ Loaded object $qt($List($1,%x).get) of type $qt($IsInstance($List($1,%x).get))
}
dec %x
}
if $exists($+(object/,$1.bvr)) {
bread $+(object/,$1.bvr) 1 $file($+(object/,$1.bvr)).size &data
- $Class($1,ITEMS,&data).setb
}
}
alias List.EXPORT {
var %x $List($1).count
while %x {
var %y $List($1,%x).get
if $IsInstance(%y) {
- $ExportObject(%y)
+ Saved object $qt($List($1,%x).get)
}
dec %x
}
- $Class($1,ITEMS,&data).getb
if $exists($+(object/,$1.bvr)) {
.remove $+(object/,$1.bvr)
}
bwrite $+(object/,$1.bvr) 1 -1 &data
}
alias List.DELETE {
;;;;;;;;;;;;;;;;;;;;;;
; Do Destroying here ;
;;;;;;;;;;;;;;;;;;;;;;
- $Class($1,ITEMS).remv
- $Class($1,TOTAL).remv
- $Class($1,COUNT).remv
if $2 {
while $hget($1,1).item {
var %y $v1
var %x $hget($1,%y)
if $IsInstance(%x) {
- $Object(%x,1).delete
+ Removed object: $qt(%x) from list $qt($1)
}
- $Class($1,%y).remv
}
}
return $Class($1).DELETE
}
;;;;;;;;;;;;
; End List ;
;;;;;;;;;;;;
Here's an example of opening a socket and handeling socket events