Advertisement
imk0tter

mSL++

Jan 22nd, 2020
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 12.94 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. ;;;;;;;;;;;;
  14. ; Triggers ;
  15. ;;;;;;;;;;;;
  16.  
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. ; START                                   ;
  19. ;                                         ;
  20. ; Make sure all of the objects from the-  ;
  21. ; previous instance of MIRC get loaded    ;
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. on 1:start: {
  24.   if (!$window(@DEBUG)) window -e @DEBUG
  25.   var %objectsFile object/ $+ Objects.main
  26.   if ($exists(%objectsFile)) {
  27.     hmake Objects
  28.     .hload -b Objects %objectsFile
  29.     var %numberOfItems $hget(Objects, 0).item
  30.     var %x 1
  31.  
  32.     while (%x <= %numberOfItems) {
  33.       var %currentObject $hget(Objects, %x).item
  34.  
  35.       if ($right(%currentObject,5) == .INIT) {
  36.         var %object $left(%currentObject,-5)
  37.  
  38.         if ($exists(object/Object. $+ %object $+ .obj)) {
  39.           + $Object(%object).IMPORT
  40.         }
  41.       }
  42.       inc %x
  43.     }
  44.   }
  45.   .timerOOP 0 1 .ExportAllObjects
  46. }
  47.  
  48. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49. ; EXIT                                     ;
  50. ;                                          ;
  51. ; Make sure all of the objects from memory ;
  52. ; get exported before mIRC closes          ;
  53. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  54. on 1:exit: {
  55.   .ExportAllObjects
  56. }
  57.  
  58. alias ExportAllObjects {
  59.   if !$exists(object/) { mkdir object }
  60.   if ($hget(Objects)) {
  61.     .hsave -b Objects $+(object/,Objects $+ .main)
  62.     var %numberOfItems $hget(Objects, 0).item
  63.     var %x 1
  64.  
  65.     while (%x <= %numberOfItems) {
  66.       var %currentObject $hget(Objects,%x).item
  67.       if ($right(%currentObject,5) == .INIT) {
  68.         var %object $hget(Object. $+ $left(%currentObject,-5))
  69.  
  70.         if (%object != $null) {
  71.           var %object $right(%object,-7)
  72.           - $Object(%object).EXPORT
  73.         }
  74.       }
  75.       inc %x
  76.     }
  77.   }
  78. }
  79. ;;;;;;;;;;;;;;;;
  80. ; END TRIGGERS ;
  81. ;;;;;;;;;;;;;;;;
  82.  
  83.  
  84. ;;;;;;;;;;;;;;;;;;;;;;;
  85. ; Public Declarations ;
  86. ;;;;;;;;;;;;;;;;;;;;;;;
  87. alias Class.DELETE.Public
  88. alias Class.GETV.Public
  89. alias Class.SETV.Public
  90. alias Class.REMV.Public
  91.  
  92. alias Class.GETB.Public
  93. alias Class.SETB.Public
  94. alias Class.REMB.Public
  95.  
  96. alias Class.EXPORT.Public
  97. alias Class.IMPORT.Public
  98. alias Class.CLONE.Public
  99. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  100.  
  101. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  102. ; Exception Declarations ;
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  104. alias Class.EXCEPTION.Null {
  105.   var %object $1, %error $2, %message $5, %scriptLine $3, %scriptDir $4
  106.   return Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41))from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ): %error $+  - %message
  107. }
  108. alias Class.EXCEPTION.MemberErr {
  109.   var %object $1, %error $2, %message $5, %scriptLine $3, %scriptDir $4
  110.   return Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41))from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ): %error $+  - %message
  111. }
  112.  
  113. alias Class.EXCEPTION.ParamErr {
  114.   var %object $1, %error $2, %message $5, %scriptLine $3, %scriptDir $4
  115.   return Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41))from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ): %error $+  - %message
  116. }
  117. ;;;;;;;;;;;;;;;
  118. ; Class Alias ;
  119. ;;;;;;;;;;;;;;;
  120. alias Class {
  121.   var %class Class
  122.   if (!$prop) {
  123.     if ($IsPrivate(%class,INIT)) {
  124.       var %object $($+($,%class,.INIT,$chr(40),%object,$chr(44),$left($regsubex($str(.,$0),/(.)/g,$\n $+ $chr(44)),-1),$chr(41)),2)
  125.       - $inheritsFrom(%object,%class)
  126.       return %object
  127.     }
  128.   }
  129.   if ($IsPublic(%class,$prop)) {
  130.     return $($+($,%class,.,$prop,$chr(40),$left($regsubex($str(.,$0),/(.)/g,$\n $+ $chr(44)),-1),$chr(41)),2)
  131.  
  132.   }
  133.   return $catch(0,MemberErr, $scriptline, $token($script,-1,92), $qt($prop) is not a public member of %Class)
  134. }
  135. ;;;;;;;;;;;;;;;;;
  136. ; Class Methods ;
  137. ;;;;;;;;;;;;;;;;;
  138. alias Class.INIT {
  139.   hinc -m Objects ClassObjects
  140.   var %object $hget(Objects,ClassObjects)
  141.  
  142.   hadd -m Objects $+(%object,.INIT)
  143.   return %object
  144. }
  145. alias Class.SETV {
  146.   var %object $1
  147.   if ($isInstance($1)) {
  148.     hadd $iif($4,-mb,-m) Object. $+ $1 $2 $$3
  149.     return $3
  150.   }
  151.   return
  152. }
  153. alias Class.GETV {
  154.   return $iif($3,$hget(Object. $+ $1,$$2,$3),$hget(Object. $+ $1,$$2))
  155. }
  156. alias Class.REMV {
  157.   var %x $Class(%object, $$2).GetV
  158.   hdel Object. $+ $1 $2
  159.   if $3 {
  160.     $Object(%x).delete
  161.   }
  162. }
  163. alias Class.GETB {
  164.   if $3 { return $Class($1,$2,$3).GETV }
  165.   else { return $Catch($1,ParamErr,$scriptline, $token($script,-1,92),You have specified insufficent parameters) }
  166. }
  167. alias Class.SETB {
  168.   if $bvar($3,0) { return $Class($1,$2,$3,1).SetV }
  169.   else { $catch($1,ParamErr, $scriptline, $token($script,-1,92), You have specified insufficent parameters) }
  170. }
  171. alias Class.REMB {
  172.   return $Class($1,$2,$3).REMV
  173. }
  174. alias Class.DELETE {
  175.   ;;;;;;;;;;;;;;;;;;;;;;
  176.   ; Do Destroying here ;
  177.   ;;;;;;;;;;;;;;;;;;;;;;
  178.   var %x 1
  179.  
  180.   if ($2) {
  181.     while $hget(Object. $+ $1,%x).data {
  182.       var %y $v1
  183.       if $isinstance(%y) { $Object(%y).delete }
  184.       inc %x
  185.     }
  186.   }
  187.   - Deleting: Object ( $+ $1 $+ ): Object. $+ $1 INIT: $1.INIT
  188.   if $hget(Objects, $1.INIT) { hfree Object. $+ $1 }
  189.   hdel Objects $1.INIT
  190.   return
  191. }
  192.  
  193. ;;;;;;;;;;;;;;;;;
  194. ; Class Methods ;
  195. ;;;;;;;;;;;;;;;;;
  196. alias Class.IMPORT {
  197.   var %objectName Object. $+ $1
  198.   if !$exists(object/) { mkdir object }
  199.   if $hget(%objectName) { return }
  200.   hmake %objectName
  201.   hload -b %objectName $+(object/,%objectName $+ .obj)
  202.   if $hget(%objectName) { return $v1 }
  203.   return
  204. }
  205. alias Class.EXPORT {
  206.   var %objectName Object. $+ $1
  207.   if !$exists(object/) { mkdir object }
  208.   hsave -b %objectName $+(object/,%objectName $+ .obj)
  209.   return
  210. }
  211. alias Class.CLONE {
  212.   var %objectName Object. $+ $1
  213.   if !$exists(object/) { mkdir object }
  214.   if $IsInstance($1) {
  215.     var %x $Class
  216.     hsave -b %objectName $+(object/,%objectName $+ .cpy)
  217.     hload -b %x $+(object/,%objectName $+ .cpy)
  218.     .remove $+(object/,%objectName $+ .cpy)
  219.     return %x
  220.   }
  221.   return
  222. }
  223. ;;;;;;;;;;;;;
  224. ; End Class ;
  225. ;;;;;;;;;;;;;
  226. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  227. ; Description: Returns whether or not a class member ;
  228. ; is public.                                         ;
  229. ;                                                    ;
  230. ; Usage: $IsPublic(<Class>,<Member>)                 ;
  231. ; Example: if ($IsInstanceOf(%Player,Player)) ..     ;
  232. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  233. alias IsPublic return $isalias($+($1.,$2.,Public))
  234.  
  235. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  236. ; Description: Returns whether or not a class member ;
  237. ; is private.                                        ;
  238. ;                                                    ;
  239. ; Usage: $IsPrivate(<Class>,<Member>)                 ;
  240. ; Example: if ($IsInstanceOf(%Player,Player)) ..     ;
  241. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  242. alias IsPrivate return $isalias($+($1.,$2))
  243.  
  244.  
  245. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  246. ; Description: Called from the class constructor to  ;
  247. ; let the object know that the specified object      ;
  248. ; inherits from the specified class                  ;
  249. ;                                                    ;
  250. ; Usage: $InheritsFrom(<Object>,<Class>)             ;
  251. ; Example: $InheritsFrom(%instance,Player)           ;
  252. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  253. alias InheritsFrom hadd -m Objects $+($1.,INIT) $2 $hget(Objects,$+($1.,INIT))
  254.  
  255. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  256. ; Description: Returns whether or not an instance is ;
  257. ; an instance of the specified class                 ;
  258. ;                                                    ;
  259. ; Usage: $IsInstanceOf(<Instance>,<Class>)           ;
  260. ; Example: if ($IsInstanceOf(%Player,Player)) ..     ;
  261. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  262. alias IsInstanceOf return $findtok($hget(Objects,$1.INIT),$2,0,32)
  263.  
  264.  
  265. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  266. ; Description: Returns whether or not an instance    ;
  267. ; exists in memory                                   ;
  268. ;                                                    ;
  269. ; Usage: $IsInstance(<Instance>)                     ;
  270. ; Example: if (!$IsInstance(%x)) %x = $Player        ;
  271. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  272. alias IsInstance return $token($hget(Objects, $1.INIT),$iif($2 != $null,$2,1),32)
  273.  
  274. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  275. ; Description: Called when ever an error is caught   ;
  276. ;                                                    ;
  277. ; Usage: $catch(<Instance>,<Error>,<Message>)        ;
  278. ; Example: if (!$IsInstanceOf(%Player,Player)) {     ;
  279. ; $catch(%Player,InstanceErr,Object %player is not   ;
  280. ;  an instance of class Player)                      ;
  281. ; }                                                  ;
  282. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  283. alias Catch {
  284.   var %error $2,%message $5,%instance $1,%scriptLine $3, %scriptDir $4
  285.   if %instance {
  286.     var %x 1
  287.     while $token($hget(Objects,$+(%instance,.INIT)),%x,32) {
  288.       var %y $+($v1,.Exception.,%error)
  289.       if $isalias(%y) {
  290.         return $($+($,%y,$chr(40),%instance,$chr(44),%error,$chr(44),%scriptLine,$chr(44),%scriptDir,$chr(44),%message,$chr(41)),2)
  291.       }
  292.       inc %x
  293.     }
  294.   }
  295. }
  296. ;;;;;;;;;;;;;
  297. ; End Catch ;
  298. ;;;;;;;;;;;;;
  299.  
  300. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  301. ; Description: Used to call the first found method   ;
  302. ; associated with an objects inheritance tree...     ;
  303. ;                                                    ;
  304. ; Usage: $Object(<Instance>,..).<Method>             ;
  305. ; Example: $Object(%stack,$2).add                    ;
  306. ; Equivelent: $List(%stack,$2).add                   ;
  307. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  308. alias Object {
  309.   var %x 1,%y $hget(Objects,$1.INIT)
  310.   while $token(%y,%x,32) {
  311.     var %z $v1
  312.     if $isalias(%z $+ . $+ $prop $+ .Public) {
  313.       return $($+($,%z,( $regsubex($mid($str($chr(44),$0),2),//g,$\n) ).,$prop),2)
  314.  
  315.     }
  316.     inc %x
  317.   }
  318.   return $catch($1,MemberErr,$scriptline, $token($script,-1,92),$prop is not a public member of $isinstance($1))
  319. }
  320. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  321. ; Description: Exports and object to the hard-drive  ;
  322. ; to later be loaded with $ImportObject()            ;
  323. ;                                                    ;
  324. ; Usage: $ExportObject(<Instance>)                   ;
  325. ; Example: - $ExportObject(%instance)                ;
  326. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  327. alias ExportObject {
  328.   var %x $hget($1,INIT),%y 1
  329.   while $token(%x,%y,32) {
  330.     var %z $v1 $+ .EXPORT
  331.     if $isalias(%z) {
  332.       %z $1
  333.     }
  334.     inc %y
  335.   }
  336.   if %x { return 1 }
  337. }
  338.  
  339. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  340. ; Description: Imports an exported object into memory     ;
  341. ; and returns whether or not the operation has completed  ;
  342. ; successfully                                            ;
  343. ;                                                         ;
  344. ; Usage: $ImportObject(%StoredHandleToExportedObj)        ;
  345. ; Example: var %imported $ImportObject(%handle)           ;
  346. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  347. alias ImportObject {
  348.   var %x $Class.Import($1)
  349.   var %y $numtok(%x,32) - 1
  350.   if %x {
  351.     while %y  {
  352.       var %z $token(%x,%y,32) $+ .IMPORT
  353.       if $isalias(%z) {
  354.         %z $1
  355.       }
  356.       dec %y
  357.     }
  358.     return $token(%x,1,32)
  359.   }
  360.   $Catch(0,ImportErr,$scriptline, $token($script,-1,92),Failed to import object $qt($1))
  361. }
  362.  
  363. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  364. ; Description: Exports and object to the hard-drive  ;
  365. ; to later be loaded with $ImportObject()            ;
  366. ;                                                    ;
  367. ; Usage: $CopyObject(<Instance>)                     ;
  368. ; Example: var %newInstance $CopyObject(%instance)   ;
  369. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  370. alias CopyObject {
  371.   var %a $Class.Copy($1)
  372.   var %x $hget(%a,INIT)
  373.   var %y $numtok(%x,32) - 1
  374.   if %a {
  375.     while %y {
  376.       var %z $token(%x,%y,32) $+ .COPY
  377.       if $isalias(%z) {
  378.         %z $1
  379.       }
  380.       dec %y
  381.     }
  382.     return %a
  383.   }
  384.   $Catch(0,CopyErr,$scriptline, $token($script,-1,92),Failed to copy object $qt($1))
  385. }
  386.  
  387. ;;;;;;;;;;;;;;
  388. ; End Object ;
  389. ;;;;;;;;;;;;;;
  390. alias - { !noop $1- }
  391. alias + { $iif($Window(@Debug),echo @Debug,!noop) $iif($1-,$v1,$crlf) }
  392. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement