Advertisement
imk0tter

Untitled

Apr 9th, 2011
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 5.73 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; Description: This is the base class, which every   ;
  3. ; class inherits from...                             ;
  4. ;                                                    ;
  5. ; Usage: $Class(<uID>,<Params>,...).<Member>         ;
  6. ; Example: var %x $Class                             ;
  7. ; Example: $Class.Delete(%x)                         ;
  8. ; Example: $Class(%x,Name,Some Text).setv            ;
  9. ; Example: $Class(%x,Name).getv                      ;
  10. ; Example: $Class(%x,Name).removev                   ;
  11. ; Example: $Class.Delete(%x)                         ;
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13. ; Public Declarations ;
  14. ;;;;;;;;;;;;;;;;;;;;;;;
  15. alias Class.DELETE.Public
  16. alias Class.GETV.Public
  17. alias Class.SETV.Public
  18. alias Class.REMOVEV.Public
  19.  
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ; Exception Declarations ;
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. alias Class.EXCEPTION.Null
  24.  
  25. ;;;;;;;;;;;;;;;
  26. ; Class Alias ;
  27. ;;;;;;;;;;;;;;;
  28. alias Class {
  29.   if (!$prop) goto init
  30.   if ($IsPublic(Class,$prop)) goto $prop
  31.   return $catch(0,MemberErr,$qt($prop) is not a public member of Class)
  32.   :init
  33.   hinc -m Objects ClassObjects
  34.   return $Class.INIT($md5($hget(Objects,ClassObjects)),Class)
  35.   :delete
  36.   return $Class.DELETE($1)
  37.   :getv
  38.   return $Class.GETV($1,$2)
  39.   :setv
  40.   return $Class.SETV($1,$2,$3,$4)
  41.   :removev
  42.   return $Class.REMOVEV($1,$2,$3)
  43. }
  44. ;;;;;;;;;;;;;;;;;
  45. ; Class Methods ;
  46. ;;;;;;;;;;;;;;;;;
  47. alias Class.INIT {
  48.   hadd -m Objects $1.INIT $2
  49.   return $1
  50. }
  51. alias Class.SETV {
  52.   var %x $hget($1,$2)
  53.   hadd -m $1 $2 $3
  54.   if $4 { $Object(%x).delete }
  55.   return %x
  56. }
  57. alias Class.GETV {
  58.   return $hget($1,$2)
  59. }
  60. alias Class.REMOVEV {
  61.   var %x $hget($1,$2)
  62.   hdel $1 $2
  63.   if $3 {
  64.     $Object(%x).delete
  65.   }
  66. }
  67. alias Class.DELETE {
  68.   ;;;;;;;;;;;;;;;;;;;;;;
  69.   ; Do Destroying here ;
  70.   ;;;;;;;;;;;;;;;;;;;;;;
  71.   var %x 1
  72.   while $hget($1,%x).data {
  73.     var %y $v1
  74.     if $isinstance(%y) { $Object(%y).delete }
  75.     inc %x
  76.   }
  77.   if $hget($1) { hfree $1 }
  78.   hdel -w Objects $1*
  79.   return
  80. }
  81. ;;;;;;;;;;;;;
  82. ; End Class ;
  83. ;;;;;;;;;;;;;
  84. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  85. ; Description: Returns whether or not a class member ;
  86. ; is public.                                         ;
  87. ;                                                    ;
  88. ; Usage: $IsPublic(<Class>,<Member>)                 ;
  89. ; Example: if ($IsInstanceOf(%Player,Player)) ..     ;
  90. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  91. alias IsPublic return $isalias($+($1.,$2.,Public))
  92.  
  93. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  94. ; Description: Called from the class constructor to  ;
  95. ; let the object know that the specified object      ;
  96. ; inherits from the specified class                  ;
  97. ;                                                    ;
  98. ; Usage: $InheritsFrom(<Object>,<Class>)             ;
  99. ; Example: $InheritsFrom(%instance,Player)           ;
  100. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  101. alias InheritsFrom hadd -m Objects $+($1.,INIT) $2 $hget(Objects,$+($1.,INIT))
  102.  
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104. ; Description: Returns whether or not an instance is ;
  105. ; an instance of the specified class                 ;
  106. ;                                                    ;
  107. ; Usage: $IsInstanceOf(<Instance>,<Class>)           ;
  108. ; Example: if ($IsInstanceOf(%Player,Player)) ..     ;
  109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  110. alias IsInstanceOf return $findtok($hget(Objects,$1.INIT),$2,0,32)
  111.  
  112.  
  113. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  114. ; Description: Returns whether or not an instance    ;
  115. ; exists in memory                                   ;
  116. ;                                                    ;
  117. ; Usage: $IsInstance(<Instance>)                     ;
  118. ; Example: if (!$IsInstance(%x)) %x = $Player        ;
  119. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  120. alias IsInstance return $token($hget(Objects, $1.INIT),1,32)
  121.  
  122. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  123. ; Description: Called when ever an error is caught   ;
  124. ;                                                    ;
  125. ; Usage: $catch(<Instance>,<Error>,<Message>)        ;
  126. ; Example: if (!$IsInstanceOf(%Player,Player)) {     ;
  127. ; $catch(%Player,InstanceErr,Object %player is not   ;
  128. ;  an instance of class Player)                      ;
  129. ; }                                                  ;
  130. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  131. alias Catch {
  132.   var %error $2,%message $3,%instance $1
  133.   if $window(@Debug) { echo @Debug Caught $qt(%error) exception: %message }
  134.   if %instance {
  135.     var %x 1
  136.     while $token($hget(Objects,$+(%instance,.INIT)),%x,32) {
  137.       var %y $+($v1,.Exception.,%error)
  138.       if $isalias(%y) {
  139.         return $($+($,%y,$chr(40),%instance,$chr(44),%message,$chr(41)),2)
  140.       }
  141.       inc %x
  142.     }
  143.   }
  144. }
  145. ;;;;;;;;;;;;;
  146. ; End Catch ;
  147. ;;;;;;;;;;;;;
  148.  
  149. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  150. ; Description: Used to call the first found method   ;
  151. ; associated with an objects inheritance tree...     ;
  152. ;                                                    ;
  153. ; Usage: $Object(<Instance>,..).<Method>             ;
  154. ; Example: $Object(%stack,$2).add                    ;
  155. ; Equivelent: $List(%stack,$2).add                   ;
  156. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  157. alias Object {
  158.   var %x 1,%y $hget(Objects,$1.INIT),%a ,,
  159.   while $token(%y,%x,32) {
  160.     var %z $v1
  161.     if $isalias(%z $+ . $+ $prop $+ .Public) {
  162.       return $($ $+ %z $+ $chr(40) $+ $1 %a $2 %a $3 %a $4 %a $5 %a $6 %a $7 %a $8 %a $9 %a $+ $chr(41) $+ . $+ $prop,2)
  163.     }
  164.     inc %x
  165.   }
  166.   return $catch($1,MemberErr,$prop is not a public member of $isinstance($1))
  167. }
  168. ;;;;;;;;;;;;;;
  169. ; End Object ;
  170. ;;;;;;;;;;;;;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement