Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: This is the base class, which every ;
- ; class inherits from... ;
- ; ;
- ; Usage: $Class(<uID>,<Params>,...).<Member> ;
- ; Example: var %x $Class ;
- ; Example: $Class.Delete(%x) ;
- ; Example: $Class(%x,Name,Some Text).set ;
- ; Example: $Class(%x,Name).get ;
- ; Example: $Class(%x,Name).unset ;
- ; Example: $Class(%x).FREE ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;
- ; Triggers ;
- ;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; START ;
- ; ;
- ; Make sure all of the objects from the- ;
- ; previous instance of MIRC get loaded ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- on 1:start: {
- if (!$window(@DEBUG)) window -e @DEBUG
- var %objectDir $mircdir $+ MSL++
- var %objectsFile $+(%objectDir,\,MSL++.main)
- if ($exists(%objectsFile)) {
- hmake MSL++
- .hload -b MSL++ %objectsFile
- var %numberOfItems $hget(MSL++, 0).item
- var %x 1
- while (%x <= %numberOfItems) {
- var %currentObject $hget(MSL++, %x).item
- if ($right(%currentObject,5) == _INIT) {
- var %object $left(%currentObject,-5)
- if $exists($+(%objectDir,\,%object,.obj)) {
- + $Class(%object).IMPORT
- }
- }
- inc %x
- }
- }
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; EXIT ;
- ; ;
- ; Make sure all of the objects from memory ;
- ; get exported before mIRC closes ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- on 1:exit: {
- .ExportAllObjects
- }
- alias ExportAllObjects {
- var %objectDir $mircdir $+ MSL++
- if !$exists(%objectDir) { mkdir %objectDir }
- if ($hget(MSL++)) {
- .hsave -b MSL++ $+(%objectDir,\,MSL++ $+ .main)
- var %numberOfItems $hget(MSL++, 0).item
- var %x 1
- while (%x <= %numberOfItems) {
- var %currentObject $hget(MSL++,%x).item
- if $right(%currentObject,5) == _INIT {
- var %object $hget($left(%currentObject,-5))
- if (%object != $null) {
- + $Class(%object).EXPORT
- }
- }
- inc %x
- }
- }
- }
- ;;;;;;;;;;;;;;;;
- ; END TRIGGERS ;
- ;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;
- ; Public Declarations ;
- ;;;;;;;;;;;;;;;;;;;;;;;
- alias Class.FREE.Public
- alias Class.GET.Public
- alias Class.SET.Public
- alias Class.UNSET.Public
- alias Class.EXPORT.Public
- alias Class.IMPORT.Public
- alias Class.CLONE.Public
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Exception Declarations ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias Class.EXCEPTION.Null {
- var %params $1, %object $2, %error $3, %message $6, %scriptLine $4, %scriptDir $5
- if ($hget(MAKETOK)) hfree MAKETOK
- return Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41)) from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ): %error $+ - %message
- }
- alias Class.EXCEPTION.NoOperation {
- var %params $1, %object $2, %error $3, %message $6, %scriptLine $4, %scriptDir $5
- if ($hget(MAKETOK)) hfree MAKETOK
- return Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41)) from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ): %error $+ - %message
- }
- alias Class.EXCEPTION.MemberErr {
- var %params $1, %object $2, %error $3, %message $6, %scriptLine $4, %scriptDir $5
- if ($hget(MAKETOK)) hfree MAKETOK
- return Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41)) from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ): %error $+ - %message
- }
- alias Class.EXCEPTION.ParamErr {
- var %params $1, %object $2, %error $3, %message $6, %scriptLine $4, %scriptDir $5
- if ($hget(MAKETOK)) hfree MAKETOK
- return Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41)) from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ): %error $+ - %message
- }
- ;;;;;;;;;;;;;;;
- ; Class Alias ;
- ;;;;;;;;;;;;;;;
- alias Class {
- var %class Class
- var %prop $mprop($prop)
- if !$mprop($prop) {
- if ($IsPrivate(%class,INIT)) {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V INIT
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- var %object $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- - $inheritsFrom(%object,%class)
- if ($hget(MAKETOK)) hfree MAKETOK
- return %object
- }
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- else if $IsPublic(%class,$fprop($mprop($prop))) {
- var %object $1
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %object
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- ;;maketok MAKETOK V $fprop($mprop($prop), 2-)
- maketok MAKETOK V %object
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 2
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- else {
- if ($hget(MAKETOK)) hfree MAKETOK
- if $isinstance($1) {
- return $catch($1,MemberErr, $scriptline, $token($script,-1,92), $qt($fprop($mprop($prop))) is not a public member of class $qt(%Class))
- }
- else {
- return $catch(%class,MemberErr, $scriptline, $token($script,-1,92), $qt($fprop($mprop($prop))) is not a public member of class $qt(%Class)).class
- }
- }
- }
- ;;;;;;;;;;;;;;;;;
- ; Class Methods ;
- ;;;;;;;;;;;;;;;;;
- alias Class.INIT {
- var %params $1
- var %htable MSL++
- hinc -m %htable OBJECT_NUMBER
- var %object $+(%htable,_,$hget(%htable,OBJECT_NUMBER))
- hadd -m %htable $+(%object,_,INIT)
- return %object
- }
- alias Class.SET {
- var %params $1
- var %object $2
- var %variable $3
- var %value $$4
- if ($isInstance(%object)) {
- var %prop $mprop(%params)
- if $cprop(%prop,BVAR) || $cprop(%prop, B) {
- hadd -mb %object %variable %value
- if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %object
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- ;maketok MAKETOK V %object
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 5
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- }
- else {
- echo -a Object: %object Varname: %variable Value: %value
- hadd -m %object %variable %value
- if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %object
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- ;maketok MAKETOK V %object
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 5
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- }
- }
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- alias Class.GET {
- var %params $1
- var %object $2
- var %variableName $3
- var %bvar $4
- if $cprop(%params,BVAR) || $cprop(%params,B) {
- var %hget $hget(%object,%variableName,%bvar)
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %object
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- ;maketok MAKETOK V %object
- $iif($cprop(%params,stack),maketok MAKETOK B %hget)
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 5
- maketok MAKETOK V $*
- $iif(!$cprop(%params,stack), maketok MAKETOK B %hget)
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- else {
- - DEBUG: $1- TOKENS: $0 OBJECT: %object VARIABLE_NAME: %variableName BVAR: $4 STACK: $cprop(%params,STACK)
- var %hget $hget(%object,%variableName)
- if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %object
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- ;maketok MAKETOK V %object
- $iif($cprop(%params,STACK),maketok MAKETOK V %hget)
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 4
- maketok MAKETOK V $*
- $iif(!$cprop(%params,STACK), maketok MAKETOK V %hget)
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- else {
- if ($hget(MAKETOK)) hfree MAKETOK
- return %hget
- }
- }
- }
- alias Class.UNSET {
- var %params $1
- var %object $2
- hdel %object $$3
- if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %object
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- ;maketok MAKETOK V %object
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 4
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- alias Class_FREE_STACK {
- if !$hfind(CLASS_FREE_STACK, $1-) {
- hadd -m CLASS_FREE_STACK $1- 1
- return 1
- }
- return 0
- }
- alias Class.FREE {
- ;;;;;;;;;;;;;;;;;;;;;;
- ; Do Destroying here ;
- ;;;;;;;;;;;;;;;;;;;;;;
- var %params $1
- var %object $2
- var %prop $mprop($prop)
- if $cprop(%params,ALL) || $cprop(%params,A) {
- if $hget(%object) {
- var %y $hget(%object,0).item
- while %y {
- var %currentObject $hget(%object, $hget(%object,%y).ITEM)
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V FREE#ALL
- maketok MAKETOK V %object
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %currentObject
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 3
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- if $CLASS_FREE_STACK(%currentObject) {
- - $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- dec %y
- }
- if ($hget(CLASS_FREE_STACK)) hfree CLASS_FREE_STACK
- }
- hdel MSL++ %object $+ _INIT
- if ($hget(%object)) hfree %object
- }
- else if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %object
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %object
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 3
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- if ($hget(MSL++,%object $+ _INIT)) hdel MSL++ %object $+ _INIT
- if ($hget(%object)) hfree %object
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- ;;;;;;;;;;;;;;;;;
- ; Class Methods ;
- ;;;;;;;;;;;;;;;;;
- alias Class.IMPORT {
- var %params $1
- var %objectDir $mircdir $+ MSL++
- var %objectName $2
- if !$exists(%objectDir) { mkdir %objectDir }
- if $hget(%objectName) { return }
- hmake %objectName
- hload -b %objectName $+(%objectDir,\,%objectName,.obj)
- if $hget(%objectName) {
- if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %objectName
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %objectName
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 3
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- }
- if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %objectName
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %objectName
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 3
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- alias Class.EXPORT {
- var %params $1
- var %objectDir $mircdir $+ MSL++
- var %objectName $2
- if !$exists(%objectDir) { mkdir %objectDir }
- hsave -b %objectName $+(%objectDir,\,%objectName $+ .obj)
- if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %objectName
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %objectName
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 3
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- else {
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- }
- alias Class.CLONE {
- var %params $1
- var %objectDir $mircdir $+ MSL++
- var %objectName $2
- if !$exists(%objectDir) { mkdir %objectDir }
- if $IsInstance(%objectName) {
- var %object $Class
- hsave -b %objectName $+(%objectDir,\,%objectName,.cpy)
- hload -mb %object $+(%objectDir,\,%objectName,.cpy)
- .remove $+(%objectDir,\,%objectName,.cpy)
- if ($hget(MAKETOK)) hfree MAKETOK
- return %object
- }
- if $prop {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V Class
- maketok MAKETOK V $prop
- maketok MAKETOK V %objectName
- maketok MAKETOK V $cprop(%params,IS_OBJECT_CALL)
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %objectName
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 3
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- ;;;;;;;;;;;;;
- ; End Class ;
- ;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Returns whether or not a class member ;
- ; is public. ;
- ; ;
- ; Usage: $IsPublic(<Class>,<Member>) ;
- ; Example: if ($IsInstanceOf(%Player,Player)) .. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias IsPublic return $isalias($+($1.,$2.,PUBLIC))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Returns whether or not a class member ;
- ; is private. ;
- ; ;
- ; Usage: $IsPrivate(<Class>,<Member>) ;
- ; Example: if ($IsInstanceOf(%Player,Player)) .. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias IsPrivate return $isalias($+($1.,$2))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Returns whether or not an instance ;
- ; exists in memory ;
- ; ;
- ; Usage: $IsInstance(<Instance>) ;
- ; Example: if (!$IsInstance(%x)) %x = $Player ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias IsClass return $isalias($1)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Called from the class constructor to ;
- ; let the object know that the specified object ;
- ; inherits from the specified class ;
- ; ;
- ; Usage: $InheritsFrom(<Object>,<Class>) ;
- ; Example: $InheritsFrom(%instance,Player) ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias InheritsFrom hadd -m MSL++ $+($1_,INIT) $2 $hget(MSL++,$+($1.,INIT))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Returns whether or not an instance is ;
- ; an instance of the specified class ;
- ; ;
- ; Usage: $IsInstanceOf(<Instance>,<Class>) ;
- ; Example: if ($IsInstanceOf(%Player,Player)) .. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias IsInstanceOf return $findtok($hget(MSL++,$1_INIT),$2,0,32)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Returns whether or not an instance ;
- ; exists in memory ;
- ; ;
- ; Usage: $IsInstance(<Instance>) ;
- ; Example: if (!$IsInstance(%x)) %x = $Player ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias IsInstance return $token($hget(MSL++, $1_INIT),$iif($2 != $null,$2,1),32)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Called when ever an error is caught ;
- ; ;
- ; Usage: $catch(<Instance>,<Error>,<Message>) ;
- ; Example: if (!$IsInstanceOf(%Player,Player)) { ;
- ; $catch(%Player,InstanceErr,Object %player is not ;
- ; an instance of class Player) ;
- ; } ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias CATCH {
- var %error $2,%message $5,%instanceOrClass $1,%scriptLine $3, %scriptDir $4, %isClass $iif($mprop($prop) == class, $true,$false)
- if $isInstance(%instanceOrClass) && !%isClass {
- var %x 1
- var %inheritance $hget(MSL++,$+(%instanceOrClass,_,INIT))
- while $token(%inheritance,%x,32) {
- var %currentClass $v1
- var %currentClassException $+(%currentClass,.EXCEPTION.,%error)
- if $isalias(%currentClassException) {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %currentClass $+ .EXCEPTION
- maketok MAKETOK V $+(%error,.,$prop)
- maketok MAKETOK V %instanceOrClass
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- inc %x
- }
- }
- else if %isClass && $isClass(%instanceOrClass) {
- if $isalias($+(%instanceOrClass,.EXCEPTION.,%error)) {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %instanceOrClass $+ .EXCEPTION
- maketok MAKETOK V $+(%error,.,$mprop($prop,1))
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- }
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- ;;;;;;;;;;;;;
- ; End Catch ;
- ;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Used to call the first found method ;
- ; associated with an objects inheritance tree... ;
- ; ;
- ; Usage: $Object(<Instance>,..).<Method> ;
- ; Example: $Object(%stack,$2).add ;
- ; Equivelent: $List(%stack,$2).add ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias OBJECT {
- var %object $1
- var %inheritance $hget(MSL++,$+(%object,_,INIT))
- var %iterator 1
- if $mprop($prop) {
- while $token(%inheritance,%iterator,32) {
- var %currentClass $v1
- if $isalias(%currentClass $+ . $+ $fprop($mprop($prop)) $+ .PUBLIC) {
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V %currentClass
- ;echo -a PROP IS: $+($mprop($prop),$chr(35),IS_OBJECT_CALL,$iif($mprop($prop,1),. $+ $v1))
- maketok MAKETOK V $+($mprop($prop),$chr(35),IS_OBJECT_CALL,$iif($mprop($prop,1),. $+ $v1))
- maketok MAKETOK V %object
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- inc %iterator
- }
- }
- else {
- if ($hget(MAKETOK)) hfree MAKETOK
- return $catch(%object,NoOperation,$scriptline, $token($script,-1,92),there is no operation specified for this object call!)
- }
- if ($hget(MAKETOK)) hfree MAKETOK
- return $catch($%object,MemberErr,$scriptline, $token($script,-1,92),$mprop($prop) is not a public member of $isinstance($1))
- }
- ;;;;;;;;;;;;;;
- ; End Object ;
- ;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;
- ; Helper Functions ;
- ;;;;;;;;;;;;;;;;;;;;
- alias - { !noop $1- }
- alias + { $iif($Window(@Debug),echo @Debug,!noop) $iif($1-,$v1,$crlf) }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Code for passing dynamic variables to the $meval function ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; var %astart $iif($hget(MAKETOK, COUNT),$v1,0) ; For passing variables to the $meval function (or your own function) ;
- ; maketok MAKETOK V ClassName ; ;
- ; maketok MAKETOK V $prop ; ;
- ; var %aend $iif($hget(MAKETOK, COUNT),$v1,0) ; ;
- ; ; ;
- ; var %bstart $iif($hget(MAKETOK, COUNT),$v1,0) ; For passing variables before the $N- tokens are passed (any number of variables allowed ;
- ; maketok MAKETOK V SomeValue ; these variables will be before the $N- tokens. ;
- ; maketok MAKETOK V SomeValue2 ; ;
- ; var %bend $iif($hget(MAKETOK, COUNT),$v1,0) ; ;
- ; ; ;
- ; var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1 ; Starting token number (if trying to pass $2- to a function you put + 2 instead of +1 ;
- ; maketok MAKETOK V $* ; (which is for tokens $1-) ;
- ; var %cend $iif($hget(MAKETOK,COUNT),$v1,0) ; ;
- ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend) ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias meval {
- var %tokentable $1
- var %astart $2 + 1
- var %aend $3
- var %acount $calc(%aend - %astart + 1)
- var %bstart $4 + 1
- var %bend $5
- var %bcount $calc(%bend - %bstart + 1)
- var %cstart $6
- var %cend $$7
- var %ccount $calc(%cend - %cstart + 1)
- var %aregex $regsubex($str(.,%acount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %astart - 1),$chr(41),$chr(35)))
- var %bregex $regsubex($str(.,%bcount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %bstart - 1),$chr(41),$chr(35)))
- var %cregex $regsubex($str(.,%ccount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %cstart - 1),$chr(41),$chr(35)))
- tokenize 35 %aregex
- var %class [ [ $1 ] ]
- var %prop [ [ $2 ] ]
- var %object [ [ $3 ] ]
- var %isObjectCall [ [ $4 ] ]
- - CLASS: %class PROP: %prop OBJECT: %object FPROP: $fprop($mprop(%prop)) ISOBJECTCALL: %isObjectCall
- if !%isObjectCall {
- if $isPublic(%class,$fprop($mprop(%prop))) || ($isPrivate(%class,$fprop($mprop(%prop))) && ($fprop($mprop(%prop)) == INIT || $token(%class,2,46) == EXCEPTION)) {
- var %regex $+($,%class,.,$fprop($mprop(%prop)),$chr(40),$iif($fprop($mprop(%prop),2-),$v1 $+ $chr(44),$null $+ $chr(44)), $left($replace(%bregex %cregex,$chr(35),$chr(32) $chr(44) $chr(32)),-5),$chr(41),$iif($mprop(%prop,1),$+(.,$v1)))
- - REGEX1 %regex MAKETOK COUNT: $hget(MAKETOK,COUNT)
- return [ [ %regex ] ]
- }
- }
- else {
- var %regex $+($,OBJECT,$chr(40),$left($replace(%bregex %cregex,$chr(35),$chr(32) $chr(44) $chr(32)),-5),$chr(41),$iif(%prop,$+(.,$v1)))
- return [ [ %regex ] ]
- }
- + 4ERROR: NOT PUBLIC OR (PRIVATE && INIT)
- if $isInstance(%object) {
- return $catch(%object,MemberErr, $scriptline, $token($script,-1,92), $qt($fprop($mprop($prop))) is not a public member of %Class)
- }
- else {
- return $catch(%class, MemberErr, $scriptline, $token($script,-1,92), $qt($fprop($mprop($prop))) is not a public member of %Class).class
- }
- }
- alias cprop {
- return $istok($1,$$2,35)
- }
- alias mprop {
- return $iif($2,$token($1,2-,46),$token($1,1,46))
- }
- alias fprop {
- return $token($1,$iif($2,$2,1),35)
- }
- alias maketok {
- hinc -m $1 COUNT
- hadd -m $+ $iif($2 == B,b) $1 $hget($1,COUNT) $3-
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;
- ; END HELPER FUNCTIONS ;
- ;;;;;;;;;;;;;;;;;;;;;;;;
- alias example {
- ;inputs:
- ;any number of inputs / 4
- var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V MAKETOKTEST
- maketok MAKETOK V $str(TEST., $floor($calc($0 / 4)))
- var %aend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
- maketok MAKETOK V OBJECT_REFERENCE
- var %bend $iif($hget(MAKETOK, COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- alias MAKETOKTEST.TEST {
- var %object $1
- echo -a -TEST-
- echo -a OBJECT: %object
- echo -a $+ $2 @ $3
- echo -a $+ $4 @ $5
- echo -a -END TEST-
- if $prop {
- var %astart $iif($hget(MAKETOK,COUNT),$v1,0)
- maketok MAKETOK V maketoktest
- maketok MAKETOK V $prop
- var %aend $iif($hget(MAKETOK,COUNT),$v1,0)
- var %bstart $iif($hget(MAKETOK,COUNT),$v1,0)
- maketok MAKETOK V %object
- var %bend $iif($hget(MAKETOK,COUNT),$v1,0)
- var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 6
- maketok MAKETOK V $*
- var %cend $iif($hget(MAKETOK,COUNT),$v1,0)
- echo -a TOKEN-COUNT $0 : A-START: %astart A-END: %aend B-START: %bstart B-END: %bend C-START: %cstart CEND: %cend
- return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
- }
- if ($hget(MAKETOK)) hfree MAKETOK
- }
- ;;;;;;;;;;;;;;;;;;;;;;
- ; END TEST FUNCTIONS ;
- ;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; mSL++ Class Downloader and Installer ;
- ; code... ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- dialog -l mslPlusPlusDownloaderAndInstaller {
- title "mSL++ Downloader and Installer"
- size -1 -1 340 256
- option dbu
- list 1, 3 13 203 72, size
- text List of mSL++ Classes not Installed, 7, 4 4 201 9, center
- button "Download", 3, 2 147 202 12
- text List of mSL++ Classes Installed, 10, 4 161 333 10, center
- button "Uninstall", 6, 4 243 333 12
- edit "", 4, 206 13 131 145
- text "Class Information", 9, 208 4 129 9, center
- text "Classes Dependant on Selected Class not Installed that are not Installed", 8, 3 86 202 8, center
- list 2, 3 96 202 50, size
- list 5, 3 171 335 72, size
- }
Add Comment
Please, Sign In to add comment