Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;
- ; Class Header ;
- ;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;
- ; Public Declarations ;
- ;;;;;;;;;;;;;;;;;;;;;;;
- alias JSON.OPEN_ELEMENT.Public
- alias JSON.CLOSE_ELEMENT.Public
- alias JSON.PROCESS_ELEMENT.Public
- alias JSON.OPEN_LIST.Public
- alias JSON.CLOSE_LIST.Public
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Exception Declarations ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias ClassName.EXCEPTION.ExceptionName {
- var %params $1, %object $2, %error $3, %message $6, %scriptLine $4, %scriptDir $5
- + Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41)) from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ):� %error $+ � - %message
- return $null
- }
- ;;;;;;;;;;;;;;;;;;;;;;;
- ; Main Class Function ;
- ;;;;;;;;;;;;;;;;;;;;;;;
- alias JSON {
- var %Class JSON
- var %prop $mprop($prop)
- if !%prop {
- if ($IsPrivate(%Class,INIT)) {
- var %astart $MAKETOKCOUNT
- MAKETOK %Class
- MAKETOK INIT
- var %aend $MAKETOKCOUNT
- var %bstart $MAKETOKCOUNT
- var %bend $MAKETOKCOUNT
- var %cstart $MAKETOKCOUNT
- MAKETOK $*
- var %cend $MAKETOKCOUNT
- var %dstart $MAKETOKCOUNT
- ; For what ever comes after the tokens
- var %dend $MAKETOKCOUNT
- var %object $meval(%astart,%aend,%bstart,%bend,%cstart,%cend,%dstart,%dend)
- - $inheritsFrom(%object,%Class)
- UNMAKETOK
- return %object
- }
- UNMAKETOK
- }
- else if $IsPublic(%class,$fprop(%prop)) {
- var %object $1
- var %astart $MAKETOKCOUNT
- MAKETOK %Class
- MAKETOK $prop
- MAKETOK %object
- var %aend $MAKETOKCOUNT
- var %bstart $MAKETOKCOUNT
- var %bend $MAKETOKCOUNT
- var %cstart $MAKETOKCOUNT + 1
- MAKETOK $*
- var %cend $MAKETOKCOUNT
- var %dstart $MAKETOKCOUNT
- ; For what ever comes after the tokens
- var %dend $MAKETOKCOUNT
- return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend,%dstart,%dend)
- }
- else {
- UNMAKETOK
- if $isinstance($1) {
- return $catch($1,MemberErr, $scriptline, $token($token($script,-1,92),1,46), $qt($fprop($mprop($prop))) is not a public member of class $qt(%class))
- }
- else {
- return $catch(%class,MemberErr, $scriptline, $token($token($script,-1,92),1,46), $qt($fprop($mprop($prop))) is not a public member of class $qt(%Class)).class
- }
- }
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Initialization Function ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias -l JSON.INIT {
- var %instance $Class
- var %input_bvar $1
- var %input_bvar_start $iif($2,$2,1)
- var %input_bvar_end $iif($3,$3,$bvar(%input_bvar,0))
- var %input_bvar_current %input_bvar_start
- var %last_element 0
- - $Class(%instance, JSON_START, %input_bvar_start).set
- while %input_bvar_current < %input_bvar_end {
- var %close_bracket $bfind(%input_bvar, %input_bvar_current, })
- var %open_bracket $bfind(%input_bvar, %input_bvar_current, {)
- var %close_list $bfind(%input_bvar, %input_bvar_current, ])
- var %open_list $bfind(%input_bvar, %input_bvar_current, [)
- if %open_list < %open_bracket && %open_list < %close_bracket && %open_list < %close_list {
- ;TODO: OPEN LIST SHIT
- var %input_bvar_current %open_list
- }
- else if %close_list < %open_list && %close_list < %close_bracket && %close_list < %open_bracket {
- ;TODO: CLOSE LIST SHIT
- var %input_bvar_current %close_list
- }
- else if %open_bracket < %close_bracket {
- var %last_element $JSON(%instance, $JSON(%input_bvar, %open_bracket)).OPEN_ELEMENT
- var %input_bvar_current %open_bracket
- }
- else {
- var %last_element $JSON(%instance, %close_bracket).CLOSE_ELEMENT
- return %instance
- }
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;
- ; Do Initializing here ;
- ;;;;;;;;;;;;;;;;;;;;;;;;
- return %instance
- }
- ;;;;;;;;;;;;;;;;;;;;
- ; END CLASS HEADER ;
- ;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;
- ; Class Body ;
- ;;;;;;;;;;;;;;
- alias -l JSON.OPEN_LIST {
- var %params $1
- var %object $2
- var %list_position $3
- var %list_count $iif($Class(%object, JSON_LIST_COUNT).get,$v1,0) + 1
- - $Class(%object, JSON_LIST_COUNT, %list_count).set
- var %list_reference $Class(%object, JSON_LIST_ $+ %list_count, $List).set
- }
- alias -l JSON.CLOSE_LIST {
- var %params $1
- var %object $2
- }
- alias -l JSON.PARSE_LIST {
- }
- alias -l JSON.OPEN_ELEMENT {
- var %params $1
- var %object $2
- var %element_object $3
- var %element_object_name $4
- var %element_object_count $calc($iif($Class(%object, JSON_ELEMENT_COUNT).get,$v1,0) + 1)
- var %element_object_id $iif($Class(%object,JSON_ELEMENT_NAME_ $+ %element_object_name).get != $null, $v1,%element_object_count)
- if %element_object_count > %element_object_id {
- - $Class(%object,JSON_ELEMENT_COUNT,%element_object_count).set
- }
- - $Class(%object, JSON_ELEMENT_ $+ %element_object_id, %element_object).set
- if %element_object_name != $null {
- - $Class(%object, JSON_ELEMENT_NAME $+ %element_object_name, %element_object_id).set
- }
- - $Class(%object, JSON_PREVIOUS_LAST_ELEMENT, $iif($Class(%object, JSON_LAST_ELEMENT).get,$v1,0)).set
- - $Class(%object, JSON_LAST_ELEMENT, %element_object_id).set
- return %element_object_id
- }
- alias -l JSON.CLOSE_ELEMENT {
- var %params $1
- var %object $2
- var %element_object_end $3
- var %element_object_id $Class(%object, JSON_LAST_ELEMENT).get
- var %element_object_reference $Class(%object, JSON_ELEMENT_ $+ %element_object_id).get
- - $Class(%object, JSON_LAST_ELEMENT, $Class(%object, JSON_PREVIOUS_LAST_ELEMENT).get).set
- var %element_object_start $Class(%element_object_reference, JSON_START).get
- - $Class(%element_object_reference, JSON_END, %element_object_end).set
- return $Class(%object, JSON_LAST_ELEMENT).get
- }
- alias -l JSON.PARSE_ELEMENT {
- var %params $1
- var %object $2
- var %element_object_id $3
- }
- ;;;;;;;;;;;;;;;;;;
- ; End Class Body ;
- ;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;
- ; Class Footer ;
- ;;;;;;;;;;;;;;;;
- alias -l - { !noop $1- }
- alias -l + { $iif($Window(@Debug),echo @Debug,!noop) $iif($1-,$v1,$crlf) }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Returns whether or not a class member ;
- ; is private. ;
- ; ;
- ; Usage: $IsPrivate(<Class>,<Member>) ;
- ; Example: if ($IsInstanceOf(%Player,Player)) .. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias -l IsPrivate return $iif($IsClass($1) && $isalias($+($1.,$2)),$true,$false)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Description: Returns whether or not a class member ;
- ; is an exception. ;
- ; ;
- ; Usage: $IsException(<Class>,<Member>) ;
- ; Example: if ($IsExceptiion(%class,Null)) .. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias -l IsException return $iif($isalias($+($1,.EXCEPTION.,$$2)),$true,$false)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Code for passing dynamic variables to the $meval function ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; var %astart $MAKETOKCOUNT ; For passing variables to the $meval function (or your own function) ;
- ; MAKETOK ClassName ; ;
- ; MAKETOK $prop ; ;
- ; var %aend $MAKETOKCOUNT ; ;
- ; ; ;
- ; var %bstart $MAKETOKCOUNT ; For passing variables before the $N- tokens are passed (any number of variables allowed ;
- ; MAKETOK SomeValue ; these variables will be before the $N- tokens. ;
- ; MAKETOK SomeValue2 ; ;
- ; var %bend $MAKETOKCOUNT ; ;
- ; ; ;
- ; var %cstart $MAKETOKCOUNT + 1 ; Starting token number (if trying to pass $2- to a function you put + 2 instead of +1 ;
- ; MAKETOK $* ; (which is for tokens $1-) ;
- ; var %cend $MAKETOKCOUNT ; ;
- ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend) ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias -l meval {
- var %astart $1
- var %aend $2
- var %acount %aend - %astart
- var %bstart $3
- var %bend $4
- var %bcount %bend - %bstart
- var %cstart $5 - 1
- var %cend $$6
- var %ccount %cend - %cstart
- var %dstart $7
- var %dend $8
- var %dcount %dend - %dstart
- var %localVariables
- var %x 1
- while %x <= %acount {
- var %y %x + %astart
- var %localVariables %localVariables $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
- inc %x
- }
- tokenize 255 %localVariables
- var %class [ [ $1 ] ]
- var %prop [ [ $2 ] ]
- var %object [ [ $3 ] ]
- var %isObjectCall [ [ $4 ] ]
- var %header,%footer,%body
- var %x 1
- while %x <= %bcount {
- var %y %x + %bstart
- var %header %header $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
- inc %x
- }
- var %x 1
- while %x <= %ccount {
- var %y %x + %cstart
- var %body %body $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
- inc %x
- }
- var %x 1
- while %x <= %dcount {
- var %y %x + %dstart
- var %footer %footer $+ $chr(255) $+ $ + getmaketok $+ [ ( ] $+ %y $+ [ ) ]
- }
- var %eval,%endeval
- ;;var %eval $ $+ %class $+ . $+ $fprop($mprop(%prop)) $+ [ ( ] $+ [ $fprop($mprop(%prop),2-) ] $+ [ , ]
- ;;var %endeval [ ) ] $+ . $+ [ $mprop(%prop,1) ]
- ;;;;;;;;;;;;;;;
- if !%isObjectCall {
- if $isPublic(%class,$fprop($mprop(%prop))) || ($isPrivate(%class,$fprop($mprop(%prop))) && $fprop($mprop(%prop)) == INIT) {
- var %eval $ $+ %class $+ . $+ $fprop($mprop(%prop)) $+ [ ( ] $+ $fprop($mprop(%prop),2-) $+ [ , ]
- var %endeval [ ) ] $+ . $+ [ $mprop(%prop,1) ]
- }
- else if $IsException(%class, $fprop($mprop(%prop))) {
- var %eval $ $+ %class $+ .EXCEPTION. $+ $fprop($mprop(%prop)) $+ [ ( ] $+ $fprop($mprop(%prop),2-) $+ [ , ]
- var %endeval [ ) ] $+ . $+ $mprop(%prop,1)
- }
- else {
- if ($IsInstance(%obejct)) {
- UNMAKETOK
- return $catch(%object, NoOperation, $scriptline, $token($token($script,-1,96),1,46), $qt($fprop($mprop(%prop))) is not a public member of class $qt(%class))
- }
- else {
- UNMAKETOK
- return $catch(Class, NoOperation, $scriptline, $token($token($script,-1,96),1,46), $qt($fprop($mprop(%prop))) is not a public member of class $qt(%class)).class
- }
- }
- }
- else {
- var %eval $ $+ OBJECT $+ [ ( ]
- var %endeval [ ) ] $+ . $+ $prop
- }
- ;;;;;;;;;;;;;;;;;
- tokenize 255 %header $+ %body $+ %footer
- var %x 1
- while %x <= $0 {
- if %x == $0 {
- var %eval %eval $+ [ $ $+ [ %x ] ]
- }
- else {
- var %eval %eval $+ [ $ $+ [ %x ] ] $+ [ , ]
- }
- inc %x
- }
- return [ [ %eval ] $+ [ %endeval ] ]
- }
- ;;;;;;;;;;;;;
- ; End meval ;
- ;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; 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 -l 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
- if $IsException(%currentClass,%error) {
- var %astart $MAKETOKCOUNT
- MAKETOK %currentClass
- MAKETOK $+(%error,:,$token($token($script,-1,92),1,46),.,$prop)
- MAKETOK %instanceOrClass
- var %aend $MAKETOKCOUNT
- var %bstart $MAKETOKCOUNT
- var %bend $MAKETOKCOUNT
- var %cstart $MAKETOKCOUNT + 1
- MAKETOK $*
- var %cend $MAKETOKCOUNT
- var %dstart $MAKETOKCOUNT
- ; For what ever comes after the tokens
- var %dend $MAKETOKCOUNT
- return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend,%dstart,%dend)
- }
- inc %x
- }
- }
- else if %isClass && $isClass(%instanceOrClass) {
- if $IsException(%instanceOrClass,%error) {
- var %astart $MAKETOKCOUNT
- MAKETOK %instanceOrClass
- MAKETOK $+(%error,:,$token($token($script,-1,92),1,46),.,$mprop($prop,1))
- var %aend $MAKETOKCOUNT
- var %bstart $MAKETOKCOUNT
- var %bend $MAKETOKCOUNT
- var %cstart $MAKETOKCOUNT + 1
- MAKETOK $*
- var %cend $MAKETOKCOUNT
- var %dstart $MAKETOKCOUNT
- ; For what ever comes dynamic set of paramters that come after the tokens
- var %dend $MAKETOKCOUNT
- return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend,%dstart,%dend)
- }
- }
- UNMAKETOK
- }
- ;;;;;;;;;;;;;
- ; End Catch ;
- ;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;
- ; END CLASS FOOTER ;
- ;;;;;;;;;;;;;;;;;;;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement