mSL++ - Object Oriented mSL

Want to show off your scripts? Release them here and bask in the glory as the users give their opinions of your work.

Moderators: IRC Operators, Support Team, mIRC Gurus

Imk0tter
User
User
Posts: 241
Joined: Thu Mar 08, 2007 4:45 am

mSL++ - Object Oriented mSL

Postby Imk0tter » Sun Aug 02, 2009 6:27 am

Today I decided to design some sort of interface to integrate OOP style coding with mSL.. This thread is going to be dedicated to the progression of mSL++.

Below is some framework code followed by a fairly detailed description on how to use it, and what it does.

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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).setv            ;
; Example: $Class(%x,Name).getv                      ;
; Example: $Class(%x,Name).removev                   ;
; Example: $Class.Delete(%x)                         ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Public Declarations ;
;;;;;;;;;;;;;;;;;;;;;;;
alias Class.DELETE.Public
alias Class.GETV.Public
alias Class.SETV.Public
alias Class.GETB.Public
alias Class.SETB.Public
alias Class.REMV.Public
alias Class.REMB.Public
alias Class.COPY.Public
alias Class.IMPORT.Public
alias Class.EXPORT.Public
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Exception Declarations ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
alias Class.EXCEPTION.Null {
}

;;;;;;;;;;;;;;;
; Class Alias ;
;;;;;;;;;;;;;;;
alias Class {
  var %ClassName Class

  var %Prop $iif($prop,$prop,init)
  if ($IsPublic(%ClassName,%prop) || %prop == init) {
    if (%prop == init) {
      goto Execute
    }
    else if ($IsInstanceOf($1, %ClassName)) {
      goto Execute
    }
    else {
      return $Catch($1,ClassErr,$qt($1) is not an instance of $qt(%ClassName))
    }
  }
  else {
    return $catch(0,MemberErr,$qt(%prop) is not a public member of %ClassName)
  }
  :Execute
  return $($+($,%ClassName,.,%prop,( $iif($0,$regsubex($mid($str($chr(44),$0),2),//g,$\n)) )),2)
}
;;;;;;;;;;;;;;;;;
; Class Methods ;
;;;;;;;;;;;;;;;;;
alias Class.SETB {
  if $bvar($3,0) { return $Class.SETV($1,$2,$3,0,1) }
  else { $catch($1,ParamErr,You have specified insufficent parameters) }
}
alias Class.GETB {
  if $3 { return $Class.GETV($1,$2,$3) }
  else { return $Catch($1,ParamErr,You have specified insufficent parameters) }
}

alias Class.REMV {
  return $Class.REMOVEV($1,$2,$3)
}
alias Class.REMB {
  return $Class.REMOVEV($1,$2,$3)
}
alias Class.IMPORT {
  if !$exists(object/) { mkdir object }
  if $hget($1,INIT) { return }
  hmake $1
  hload -b $1 $+(object/,$1.obj)
  if $hget($1,INIT) { return $v1 }
  return
}
alias Class.EXPORT {
  if !$exists(object/) { mkdir object }
  hsave -b $1 $+(object/,$1.obj)
  return
}
alias Class.COPY {
  if !$exists(object/) { mkdir object }
  if $IsInstance($1) {
    var %x $Class
    hsave -b $1 $+(object/,$1.cpy)
    hload -b %x $+(object/,$1.cpy)
    .remove $+(object/,$1.cpy)
    return %x
  }
  return
}

alias Class.INIT {
  var %ClassName Class
  inc %InstanceNumber
  var %ClassIdentifier $md5($ctime $+ $ticks $+ %InstanceNumber)
  hadd -m %ClassIdentifier INIT %ClassName
  - $iif($1,$InheritsFrom(%ClassIdentifier,$1))
  return %ClassIdentifier
}
alias Class.SETV {
  var %x $hget($1,$2)
  hadd $iif($5,-mb,-m) $1 $2 $3
  if $4 { $Object(%x).delete }
  return %x
}
alias Class.GETV {
  return $iif($3,$hget($1,$2,$3),$hget($1,$2))
}
alias Class.REMOVEV {
  var %x $hget($1,$2)
  hdel $1 $2
  if $3 {
    $Object(%x).delete
  }
}
alias Class.DELETE {
  ;;;;;;;;;;;;;;;;;;;;;;
  ; Do Destroying here ;
  ;;;;;;;;;;;;;;;;;;;;;;
  var %x 1
  while $hget($1,%x).data {
    var %y $v1
    if $isinstance(%y) && $2 { $Object(%y).delete }
    inc %x
  }
  .hfree $1
  return
}
;;;;;;;;;;;;;
; 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: 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 { - $Class($1,INIT,$2 $hget($1,INIT)).setv }

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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($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($1,INIT),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 $3,%instance $1
  + Caught $qt(%error) exception: %message
  if %instance {
    var %x 1,%z $hget($1,INIT)
    while $token(%z,%x,32) {
      var %y $+($v1,.Exception.,%error)
      if $isalias(%y) {
        return $($+($,%y,( %instance,$chr(44),%message )),2)
      }
      inc %x
    }
  }
}
;;;;;;;;;;;;;
; 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 %x 1,%y $Class($1,INIT).getv
  while $token(%y,%x,32) {
    var %z $v1
    if $isalias(%z $+ . $+ $prop $+ .Public) {
      return $($+($,%z,( $regsubex($mid($str($chr(44),$0),2),//g,$\n) ).,$prop),2)
    }
    inc %x
  }
  return $catch($1,MemberErr,$qt($prop) is not a public member of $qt($isinstance($1)))
}
;;;;;;;;;;;;;;
; End Object ;
;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description: Exports and object to the hard-drive  ;
; to later be loaded with $ImportObject()            ;
;                                                    ;
; Usage: $ExportObject(<Instance>)                   ;
; Example: - $ExportObject(%instance)                ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias ExportObject {
  var %x $hget($1,INIT),%y 1
  while $token(%x,%y,32) {
    var %z $v1 $+ .EXPORT
    if $isalias(%z) {
      %z $1
    }
    inc %y
  }
  if %x { return 1 }
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description: Imports an exported object into memory     ;
; and returns whether or not the operation has completed  ;
; successfully                                            ;
;                                                         ;
; Usage: $ImportObject(%StoredHandleToExportedObj)        ;
; Example: var %imported $ImportObject(%handle)           ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias ImportObject {
  var %x $Class.Import($1)
  var %y $numtok(%x,32) - 1
  if %x {
    while %y  {
      var %z $token(%x,%y,32) $+ .IMPORT
      if $isalias(%z) {
        %z $1
      }
      dec %y
    }
    return $token(%x,1,32)
  }
  $Catch(0,ImportErr,Failed to import object $qt($1))
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description: Exports and object to the hard-drive  ;
; to later be loaded with $ImportObject()            ;
;                                                    ;
; Usage: $CopyObject(<Instance>)                     ;
; Example: var %newInstance $CopyObject(%instance)   ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias CopyObject {
  var %a $Class.Copy($1)
  var %x $hget(%a,INIT)
  var %y $numtok(%x,32) - 1
  if %a {
    while %y {
      var %z $token(%x,%y,32) $+ .COPY
      if $isalias(%z) {
        %z $1
      }
      dec %y
    }
    return %a
  }
  $Catch(0,CopyErr,Failed to copy object $qt($1))
}

alias - { !noop $1- }
alias + { $iif($Window(@Debug),echo @Debug,!noop) [[ $+ $date($ctime) $time($ctime) $+ ]] $1- }


This is the class in which every class should inherit from. The Class class is divided into four sections:

[*]Public Declarations
[*]Exception Declarations
[*]Class Methods
[*]Class Alias

In Public Declarations, we declare which methods should be accessible outside of the class

In Exception Declarations, we declare methods that handle specific Exceptions caught by the Catch Alias (The Catch alias will be explained later, amongst other supporting methods)

Accompanied by the Class class are some supporting methods (We mentioned Catch earlier) which consist of:

[*]Catch
[*]IsInstanceOf
[*]InheritFrom
[*]IsInstance

Catch is called any time we want to let the class know that an error has been found.. The error will then be handled by class specific Exception handlers, if they exist..

IsInstanceOf returns whether or not the specified instance is an instance of the specified class.. We use this when we try to call a super class' public member functions... I will soon add "Protected" member functions, which are functions that are only accessible internally, or from child classes..

InheritFrom is what we use when we want to specify that a class inherits from another class.. We use this in the constructor of the class that's trying to Inherit From..

IsInstance returns whether or not the specified instance exists in memory, and returns the type of object the instance is associated with.. You can use this to check whether an instance exists, and if it doesn't, have it create a new object..

The following posts will contain some more useful classes.

Updates:
[*]Added Object method
Last edited by Imk0tter on Wed Sep 20, 2017 11:41 am, edited 10 times in total.
Image
Imk0tter
User
User
Posts: 241
Joined: Thu Mar 08, 2007 4:45 am

Re: mSL++ - Object Oriented mSL

Postby Imk0tter » Sun Aug 02, 2009 6:33 am

Here are some basic classes:


Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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 {
  var %ClassName List

  var %Prop $iif($prop,$prop,init)
  if ($IsPublic(%ClassName,%prop) || %prop == init) {
    if (%prop == init) {
      goto Execute
    }
    else if ($IsInstanceOf($1, %ClassName)) {
      goto Execute
    }
    else {
      return $Catch($1,ClassErr,$qt($1) is not an instance of $qt(%ClassName))
    }
  }
  else {
    return $catch(0,MemberErr,$qt(%prop) is not a public member of %ClassName)
  }
  :Execute
  return $($+($,%ClassName,.,%prop,( $iif($0,$regsubex($mid($str($chr(44),$0),2),//g,$\n)) )),2)
}

;;;;;;;;;;;;;;;;
; List Methods ;
;;;;;;;;;;;;;;;;
alias List.INIT {
  var %instance $Class
  - $inheritsFrom(%instance,List)
  ;;;;;;;;;;;;;;;;;;;;;;;;
  ; Do Initializing here ;
  ;;;;;;;;;;;;;;;;;;;;;;;;
  return %instance
}

alias List.REMDEL {
  return $List.Remove($1,$2)
}
alias List.COUNT {
  return $Class($1,COUNT).getv
}
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 ;
;;;;;;;;;;;;


Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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 {
  var %ClassName Stack

  var %Prop $iif($prop,$prop,init)
  if ($IsPublic(%ClassName,%prop) || %prop == init) {
    if (%prop == init) {
      goto Execute
    }
    else if ($IsInstanceOf($1, %ClassName)) {
      goto Execute
    }
    else {
      return $Catch($1,ClassErr,$qt($1) is not an instance of $qt(%ClassName))
    }
  }
  else {
    return $catch(0,MemberErr,$qt(%prop) is not a public member of %ClassName)
  }
  :Execute
  return $($+($,%ClassName,.,%prop,( $iif($0,$regsubex($mid($str($chr(44),$0),2),//g,$\n)) )),2)
}
;;;;;;;;;;;;;;;;;;;;
; Stack Methods    ;
;;;;;;;;;;;;;;;;;;;;
alias Stack.INIT {
  echo -a PENIS $1-
  if ($IsInstanceOf($1,List)) return $iif(!$IsInstanceOf($1,Stack),$inheritsFrom($1,Stack))
  var %instance $List
  - $inheritsFrom(%instance,Stack)
  ;;;;;;;;;;;;;;;;;;;;;;;;
  ; Do Initializing here ;
  ;;;;;;;;;;;;;;;;;;;;;;;;
  return %instance
}
alias Stack.PUSH {
  var %x $list($1,$2).add
  return
}

alias Stack.POP {
  if $list($1).count {
    var %y $list($1,$v1).get
    $list($1,$v1).remove
    return %y
  }
  return
}

alias Stack.CLEAR {
  while ($list($1).count) {
    $list($1,1).remove
  }
  return
}

alias Stack.DELETE {
  ;;;;;;;;;;;;;;;;;;;;;;
  ; Do Destroying here ;
  ;;;;;;;;;;;;;;;;;;;;;;
  return $List($1).DELETE
}
;;;;;;;;;;;;;;;;
; End Stack    ;
;;;;;;;;;;;;;;;;


Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description: This is a Socket class which contains   ;
; the basic structure of a class                       ;
; Usage: $Socket(<Instance>,<Params>,..).<Method>      ;
; Example: var %x $Socket(127.0.0.1,1337,LocalSock)    ;
; Example: $Socket(%x,SockOpenAlias).sockopen          ;
; Example: $Socket(%x,SockReadAlias).sockread          ;
; Example: $Socket(%x).connect                         ;
; Example: $Socket(%x).close                           ;
; Example: $Socket(%x).delete                          ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Public Declarations ;
;;;;;;;;;;;;;;;;;;;;;;;
alias Socket.DELETE.Public
alias Socket.PORT.Public
alias Socket.IP.Public
alias Socket.OPEN.Public
alias Socket.CONNECT.Public
alias Socket.LISTEN.Public
alias Socket.CLOSE.Public
alias Socket.SOCKREAD.Public
alias Socket.SOCKOPEN.Public
alias Socket.SOCKCLOSE.Public
alias Socket.SOCKACCEPT.Public
alias Socket.TAG.Public
alias Socket.SETTAG.Public
alias Socket.SETIP.Public
alias Socket.SETPORT.Public
alias Socket.WRITE.Public
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Exception Declarations ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
alias Socket.EXCEPTION.SockErr {
  $Class($1,SockErr).getv $2-
  return $iif($bvar(&SockErr,0),$bvar(&SockErr,1-).text)
}
;;;;;;;;;;;;;;;;
; Socket Alias ;
;;;;;;;;;;;;;;;;
alias Socket {
  var %ClassName Socket

  var %Prop $iif($prop,$prop,init)
  if ($IsPublic(%ClassName,%prop) || %prop == init) {
    if (%prop == init) {
      goto Execute
    }
    else if ($IsInstanceOf($1, %ClassName)) {
      goto Execute
    }
    else {
      return $Catch($1,ClassErr,$qt($1) is not an instance of $qt(%ClassName))
    }
  }
  else {
    return $catch(0,MemberErr,$qt(%prop) is not a public member of %ClassName)
  }
  :Execute
  return $($+($,%ClassName,.,%prop,( $iif($0,$regsubex($mid($str($chr(44),$0),2),//g,$\n)) )),2)
}

;;;;;;;;;;;;;;;;;;
; Socket Methods ;
;;;;;;;;;;;;;;;;;;
alias Socket.INIT {
  var %instance $Class
  - $inheritsFrom(%instance,Socket)
  - $Class(%instance,IP,$1).setv
  - $Class(%instance,PORT,$2).setv
  - $Class(%instance,OPEN,Socket.DefaultSockOpen).setv
  - $Class(%instance,CLOSE,Socket.DefaultSockClose).setv
  - $Class(%instance,ACCEPT,Socket.DefaultSockAccept).setv
  - $Class(%instance,READ,Socket.DefaultSockRead).setv
  - $Class(%instance,SockErr,Socket.DefaultSockErr).setv
  - $Class(%instance,Tag,$3).setv
  ;;;;;;;;;;;;;;;;;;;;;;;;
  ; Do Initializing here ;
  ;;;;;;;;;;;;;;;;;;;;;;;;
  return %instance
}
alias Socket.OPEN {
  Socket.Connect $1-
}
alias Socket.CONNECT {
  if ($sock($1).status) $catch($1,SockOpenErr,Socket $1 is already open)
  else sockopen $1 $Class($1,IP).getv $Class($1,PORT).getv
}
alias Socket.CLOSE {
  if ($sock($1).status) sockclose $1
  else return $catch($1,SockCloseErr,Sock $1 was not open)
  return
}
alias Socket.LISTEN {
  if ($sock($1).status) $catch($1,SockOpenErr,Socket $1 is already open)
  var %x $iif($Class($1,IP).getv,$v1),%y $iif(%x,-d)
  socklisten %y %x $1 $Class($1,PORT).getv
  return
}
alias Socket.SOCKCLOSE {
  return $Class($1,CLOSE,$2).setv
}
alias Socket.SOCKOPEN {
  return $Class($1,OPEN,$2).setv
}
alias Socket.SOCKACCEPT {
  return $Class($1,ACCEPT,$2).setv
}
alias Socket.SOCKREAD {
  return $Class($1,READ,$2).setv
}
alias Socket.SETTAG {
  return $Class($1,Tag,$2).setv
}
alias Socket.TAG {
  return $Class($1,Tag).getv
}
alias Socket.SETIP {
  return $Class($1,IP,$2).setv
}
alias Socket.SETPORT {
  return $Class($1,PORT,$2).setv
}
alias Socket.IP {
  return $Class($1,IP).getv
}
alias Socket.PORT {
  return $Class($1,PORT).getv
}
alias Socket.WRITE {
  if ($sock($1).status != active) return $catch($1,SockErr,Socket $1 is not connected)
  sockwrite $1 $2
  return
}
alias Socket.DELETE {
  ;;;;;;;;;;;;;;;;;;;;;;
  ; Do Destroying here ;
  ;;;;;;;;;;;;;;;;;;;;;;
  if ($sock($1).status) sockclose $1
  return $class($1).DELETE
}
;;;;;;;;;;;;;;;;;;;;;;;;;;
; Default Event Handlers ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
alias Socket.DefaultSockOpen {
  if ($Window(@Debug)) echo @Debug Successfully connected to $sock($sockname).ip $+ : $+ $sock($sockname).port
}
alias Socket.DefaultSockClose {
  if ($Window(@Debug)) echo @Debug Successfully disconnected from $sock($sockname).ip $+ : $+ $sock($sockname).port
  $Socket($1).delete
}
alias Socket.DefaultSockRead {
  sockread %temp
  if ($window(@Debug)) echo @Debug %temp
}
alias Socket.DefaultSockAccept {
}
alias Socket.DefaultSockErr {
  sockclose $1
}
alias SockErr {
  bset -t &SockErr $1-
}
;;;;;;;;;;;;;;;;;;;;
; Trigger Handlers ;
;;;;;;;;;;;;;;;;;;;;
on 1:sockopen:*: $class($left($sockname,-1),OPEN).getv $left($sockname,-1)
on 1:sockclose:*: $class($left($sockname,-1),CLOSE).getv $left($sockname,-1)
on 1:socklisten:*: $class($left($sockname,-1),ACCEPT).getv $left($sockname,-1)
on 1:sockread:*: $class($left($sockname,-1),READ).getv $left($sockname,-1)
;;;;;;;;;;;;;;
; End Socket ;
;;;;;;;;;;;;;;
Last edited by Imk0tter on Wed Sep 20, 2017 3:23 am, edited 2 times in total.
Image
Imk0tter
User
User
Posts: 241
Joined: Thu Mar 08, 2007 4:45 am

Re: mSL++ - Object Oriented mSL

Postby Imk0tter » Sun Aug 02, 2009 6:40 am

Bump
Last edited by Imk0tter on Wed Sep 20, 2017 3:20 am, edited 3 times in total.
Image
Imk0tter
User
User
Posts: 241
Joined: Thu Mar 08, 2007 4:45 am

Re: mSL++ - Object Oriented mSL

Postby Imk0tter » Thu Aug 13, 2009 4:35 pm

Bump
Last edited by Imk0tter on Wed Sep 20, 2017 3:20 am, edited 2 times in total.
Image
Imk0tter
User
User
Posts: 241
Joined: Thu Mar 08, 2007 4:45 am

Re: mSL++ - Object Oriented mSL

Postby Imk0tter » Thu Aug 13, 2009 4:37 pm

Bump
Last edited by Imk0tter on Wed Sep 20, 2017 3:20 am, edited 5 times in total.
Image
Imk0tter
User
User
Posts: 241
Joined: Thu Mar 08, 2007 4:45 am

Re: mSL++ - Object Oriented mSL

Postby Imk0tter » Sat Dec 19, 2009 4:25 pm

Bump!
Image
Imk0tter
User
User
Posts: 241
Joined: Thu Mar 08, 2007 4:45 am

Re: mSL++ - Object Oriented mSL

Postby Imk0tter » Mon Jul 28, 2014 4:30 pm

Bump!
Image
SReject
User
User
Posts: 29
Joined: Fri May 14, 2010 5:52 pm

Re: mSL++ - Object Oriented mSL

Postby SReject » Thu Jul 31, 2014 3:33 am

The real question is what does adding OOP into mIRC achieve. What benefit/value does it bring to the scripting language? Is it faster? Easier to use? Better at managing things like memory?



As far as I can see, it doesn't have merit as mIRC stands. As mSL is about 90% re-active/event-driven, and can't see how such would feasibly translate into OOP other than 'looks'
Jerrysutton
Newbie
Newbie
Posts: 1
Joined: Sat Aug 02, 2014 10:26 am

Re: mSL++ - Object Oriented mSL

Postby Jerrysutton » Sat Aug 02, 2014 10:48 am

By using the class concept in C++ its easy to do coding and also it is easily understandable.
----------
Click here
SReject
User
User
Posts: 29
Joined: Fri May 14, 2010 5:52 pm

Re: mSL++ - Object Oriented mSL

Postby SReject » Mon Aug 04, 2014 8:28 am

Jerrysutton wrote:By using the class concept in C++ its easy to do coding and also it is easily understandable.


How does this make the code more understandable? If the user knows mSL, then this actually makes the code more convoluted. Not only am I digging around trying to figure out where something like $Socket() came from, but I have to read through an entire script to get it's pretext.


"As far as easy to do coding", how exactly? As far as I can tell, all this does is give the aesthetics, instead of actual OOP
Imk0tter
User
User
Posts: 241
Joined: Thu Mar 08, 2007 4:45 am

Re: mSL++ - Object Oriented mSL

Postby Imk0tter » Wed Sep 20, 2017 3:24 am

Bump
Image

Return to “Scripts”

Who is online

Users browsing this forum: No registered users and 4 guests