Advertisement
imk0tter

Untitled

Dec 12th, 2022
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.31 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;
  2. ; Class Header ;
  3. ;;;;;;;;;;;;;;;;
  4.  
  5. ;;;;;;;;;;;;;;;;;;;;;;;
  6. ; Public Declarations ;
  7. ;;;;;;;;;;;;;;;;;;;;;;;
  8. alias JSON.OPEN_ELEMENT.Public
  9. alias JSON.CLOSE_ELEMENT.Public
  10.  
  11. alias JSON.PROCESS_ELEMENT.Public
  12.  
  13. alias JSON.OPEN_LIST.Public
  14. alias JSON.CLOSE_LIST.Public
  15.  
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ; Exception Declarations ;
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. alias ClassName.EXCEPTION.ExceptionName {
  20. var %params $1, %object $2, %error $3, %message $6, %scriptLine $4, %scriptDir $5
  21. + Exception Caught on line $+($chr(40),%scriptLine,:,%scriptDir,$chr(41)) from Object ( $+ %object $+ : $+ $IsInstance(%object) $+ ):� %error $+ � - %message
  22. return $null
  23. }
  24. ;;;;;;;;;;;;;;;;;;;;;;;
  25. ; Main Class Function ;
  26. ;;;;;;;;;;;;;;;;;;;;;;;
  27. alias JSON {
  28. var %Class JSON
  29. var %prop $mprop($prop)
  30. if !%prop {
  31. if ($IsPrivate(%Class,INIT)) {
  32.  
  33. var %astart $MAKETOKCOUNT
  34. MAKETOK %Class
  35. MAKETOK INIT
  36. var %aend $MAKETOKCOUNT
  37.  
  38. var %bstart $MAKETOKCOUNT
  39. var %bend $MAKETOKCOUNT
  40.  
  41. var %cstart $MAKETOKCOUNT
  42. MAKETOK $*
  43. var %cend $MAKETOKCOUNT
  44.  
  45. var %dstart $MAKETOKCOUNT
  46. ; For what ever comes after the tokens
  47. var %dend $MAKETOKCOUNT
  48.  
  49. var %object $meval(%astart,%aend,%bstart,%bend,%cstart,%cend,%dstart,%dend)
  50. - $inheritsFrom(%object,%Class)
  51. UNMAKETOK
  52. return %object
  53. }
  54. UNMAKETOK
  55. }
  56. else if $IsPublic(%class,$fprop(%prop)) {
  57. var %object $1
  58.  
  59. var %astart $MAKETOKCOUNT
  60. MAKETOK %Class
  61. MAKETOK $prop
  62. MAKETOK %object
  63. var %aend $MAKETOKCOUNT
  64.  
  65. var %bstart $MAKETOKCOUNT
  66. var %bend $MAKETOKCOUNT
  67.  
  68. var %cstart $MAKETOKCOUNT + 1
  69. MAKETOK $*
  70. var %cend $MAKETOKCOUNT
  71.  
  72. var %dstart $MAKETOKCOUNT
  73. ; For what ever comes after the tokens
  74. var %dend $MAKETOKCOUNT
  75.  
  76. return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend,%dstart,%dend)
  77. }
  78. else {
  79. UNMAKETOK
  80. if $isinstance($1) {
  81. 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))
  82. }
  83. else {
  84. 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
  85. }
  86. }
  87. }
  88. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  89. ; Initialization Function ;
  90. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  91. alias -l JSON.INIT {
  92. var %instance $Class
  93. var %input_bvar $1
  94.  
  95. var %input_bvar_start $iif($2,$2,1)
  96. var %input_bvar_end $iif($3,$3,$bvar(%input_bvar,0))
  97.  
  98. var %input_bvar_current %input_bvar_start
  99.  
  100. var %last_element 0
  101.  
  102. - $Class(%instance, JSON_START, %input_bvar_start).set
  103.  
  104. while %input_bvar_current < %input_bvar_end {
  105. var %close_bracket $bfind(%input_bvar, %input_bvar_current, })
  106. var %open_bracket $bfind(%input_bvar, %input_bvar_current, {)
  107.  
  108. var %close_list $bfind(%input_bvar, %input_bvar_current, ])
  109. var %open_list $bfind(%input_bvar, %input_bvar_current, [)
  110.  
  111. if %open_list < %open_bracket && %open_list < %close_bracket && %open_list < %close_list {
  112. ;TODO: OPEN LIST SHIT
  113.  
  114. var %input_bvar_current %open_list
  115. }
  116. else if %close_list < %open_list && %close_list < %close_bracket && %close_list < %open_bracket {
  117. ;TODO: CLOSE LIST SHIT
  118.  
  119. var %input_bvar_current %close_list
  120. }
  121. else if %open_bracket < %close_bracket {
  122. var %last_element $JSON(%instance, $JSON(%input_bvar, %open_bracket)).OPEN_ELEMENT
  123. var %input_bvar_current %open_bracket
  124. }
  125. else {
  126. var %last_element $JSON(%instance, %close_bracket).CLOSE_ELEMENT
  127. return %instance
  128. }
  129.  
  130. }
  131. ;;;;;;;;;;;;;;;;;;;;;;;;
  132. ; Do Initializing here ;
  133. ;;;;;;;;;;;;;;;;;;;;;;;;
  134. return %instance
  135. }
  136. ;;;;;;;;;;;;;;;;;;;;
  137. ; END CLASS HEADER ;
  138. ;;;;;;;;;;;;;;;;;;;;
  139.  
  140.  
  141. ;;;;;;;;;;;;;;
  142. ; Class Body ;
  143. ;;;;;;;;;;;;;;
  144. alias -l JSON.OPEN_LIST {
  145. var %params $1
  146. var %object $2
  147.  
  148. var %list_position $3
  149. var %list_count $iif($Class(%object, JSON_LIST_COUNT).get,$v1,0) + 1
  150. - $Class(%object, JSON_LIST_COUNT, %list_count).set
  151. var %list_reference $Class(%object, JSON_LIST_ $+ %list_count, $List).set
  152.  
  153.  
  154.  
  155. }
  156.  
  157. alias -l JSON.CLOSE_LIST {
  158. var %params $1
  159. var %object $2
  160.  
  161. }
  162.  
  163. alias -l JSON.PARSE_LIST {
  164.  
  165. }
  166. alias -l JSON.OPEN_ELEMENT {
  167. var %params $1
  168. var %object $2
  169.  
  170. var %element_object $3
  171. var %element_object_name $4
  172.  
  173. var %element_object_count $calc($iif($Class(%object, JSON_ELEMENT_COUNT).get,$v1,0) + 1)
  174. var %element_object_id $iif($Class(%object,JSON_ELEMENT_NAME_ $+ %element_object_name).get != $null, $v1,%element_object_count)
  175.  
  176. if %element_object_count > %element_object_id {
  177. - $Class(%object,JSON_ELEMENT_COUNT,%element_object_count).set
  178. }
  179.  
  180. - $Class(%object, JSON_ELEMENT_ $+ %element_object_id, %element_object).set
  181.  
  182. if %element_object_name != $null {
  183. - $Class(%object, JSON_ELEMENT_NAME $+ %element_object_name, %element_object_id).set
  184. }
  185.  
  186. - $Class(%object, JSON_PREVIOUS_LAST_ELEMENT, $iif($Class(%object, JSON_LAST_ELEMENT).get,$v1,0)).set
  187. - $Class(%object, JSON_LAST_ELEMENT, %element_object_id).set
  188.  
  189. return %element_object_id
  190. }
  191.  
  192. alias -l JSON.CLOSE_ELEMENT {
  193. var %params $1
  194. var %object $2
  195.  
  196. var %element_object_end $3
  197.  
  198. var %element_object_id $Class(%object, JSON_LAST_ELEMENT).get
  199. var %element_object_reference $Class(%object, JSON_ELEMENT_ $+ %element_object_id).get
  200.  
  201. - $Class(%object, JSON_LAST_ELEMENT, $Class(%object, JSON_PREVIOUS_LAST_ELEMENT).get).set
  202.  
  203. var %element_object_start $Class(%element_object_reference, JSON_START).get
  204. - $Class(%element_object_reference, JSON_END, %element_object_end).set
  205.  
  206.  
  207.  
  208.  
  209. return $Class(%object, JSON_LAST_ELEMENT).get
  210. }
  211.  
  212. alias -l JSON.PARSE_ELEMENT {
  213. var %params $1
  214. var %object $2
  215.  
  216. var %element_object_id $3
  217.  
  218.  
  219. }
  220. ;;;;;;;;;;;;;;;;;;
  221. ; End Class Body ;
  222. ;;;;;;;;;;;;;;;;;;
  223.  
  224. ;;;;;;;;;;;;;;;;
  225. ; Class Footer ;
  226. ;;;;;;;;;;;;;;;;
  227. alias -l - { !noop $1- }
  228. alias -l + { $iif($Window(@Debug),echo @Debug,!noop) $iif($1-,$v1,$crlf) }
  229.  
  230. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  231. ; Description: Returns whether or not a class member ;
  232. ; is private. ;
  233. ; ;
  234. ; Usage: $IsPrivate(<Class>,<Member>) ;
  235. ; Example: if ($IsInstanceOf(%Player,Player)) .. ;
  236. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  237. alias -l IsPrivate return $iif($IsClass($1) && $isalias($+($1.,$2)),$true,$false)
  238.  
  239. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  240. ; Description: Returns whether or not a class member ;
  241. ; is an exception. ;
  242. ; ;
  243. ; Usage: $IsException(<Class>,<Member>) ;
  244. ; Example: if ($IsExceptiion(%class,Null)) .. ;
  245. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  246. alias -l IsException return $iif($isalias($+($1,.EXCEPTION.,$$2)),$true,$false)
  247.  
  248. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  249. ; Code for passing dynamic variables to the $meval function ;
  250. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  251. ; var %astart $MAKETOKCOUNT ; For passing variables to the $meval function (or your own function) ;
  252. ; MAKETOK ClassName ; ;
  253. ; MAKETOK $prop ; ;
  254. ; var %aend $MAKETOKCOUNT ; ;
  255. ; ; ;
  256. ; var %bstart $MAKETOKCOUNT ; For passing variables before the $N- tokens are passed (any number of variables allowed ;
  257. ; MAKETOK SomeValue ; these variables will be before the $N- tokens. ;
  258. ; MAKETOK SomeValue2 ; ;
  259. ; var %bend $MAKETOKCOUNT ; ;
  260. ; ; ;
  261. ; var %cstart $MAKETOKCOUNT + 1 ; Starting token number (if trying to pass $2- to a function you put + 2 instead of +1 ;
  262. ; MAKETOK $* ; (which is for tokens $1-) ;
  263. ; var %cend $MAKETOKCOUNT ; ;
  264. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  265. ; return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend) ;
  266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  267. alias -l meval {
  268. var %astart $1
  269. var %aend $2
  270. var %acount %aend - %astart
  271.  
  272. var %bstart $3
  273. var %bend $4
  274. var %bcount %bend - %bstart
  275.  
  276. var %cstart $5 - 1
  277. var %cend $$6
  278. var %ccount %cend - %cstart
  279.  
  280. var %dstart $7
  281. var %dend $8
  282. var %dcount %dend - %dstart
  283.  
  284. var %localVariables
  285.  
  286. var %x 1
  287. while %x <= %acount {
  288. var %y %x + %astart
  289. var %localVariables %localVariables $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
  290. inc %x
  291. }
  292.  
  293. tokenize 255 %localVariables
  294.  
  295. var %class [ [ $1 ] ]
  296. var %prop [ [ $2 ] ]
  297. var %object [ [ $3 ] ]
  298. var %isObjectCall [ [ $4 ] ]
  299.  
  300. var %header,%footer,%body
  301.  
  302. var %x 1
  303. while %x <= %bcount {
  304. var %y %x + %bstart
  305. var %header %header $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
  306. inc %x
  307. }
  308.  
  309. var %x 1
  310. while %x <= %ccount {
  311. var %y %x + %cstart
  312. var %body %body $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
  313. inc %x
  314. }
  315.  
  316. var %x 1
  317. while %x <= %dcount {
  318. var %y %x + %dstart
  319. var %footer %footer $+ $chr(255) $+ $ + getmaketok $+ [ ( ] $+ %y $+ [ ) ]
  320. }
  321.  
  322. var %eval,%endeval
  323.  
  324. ;;var %eval $ $+ %class $+ . $+ $fprop($mprop(%prop)) $+ [ ( ] $+ [ $fprop($mprop(%prop),2-) ] $+ [ , ]
  325. ;;var %endeval [ ) ] $+ . $+ [ $mprop(%prop,1) ]
  326.  
  327. ;;;;;;;;;;;;;;;
  328. if !%isObjectCall {
  329. if $isPublic(%class,$fprop($mprop(%prop))) || ($isPrivate(%class,$fprop($mprop(%prop))) && $fprop($mprop(%prop)) == INIT) {
  330. var %eval $ $+ %class $+ . $+ $fprop($mprop(%prop)) $+ [ ( ] $+ $fprop($mprop(%prop),2-) $+ [ , ]
  331. var %endeval [ ) ] $+ . $+ [ $mprop(%prop,1) ]
  332. }
  333. else if $IsException(%class, $fprop($mprop(%prop))) {
  334. var %eval $ $+ %class $+ .EXCEPTION. $+ $fprop($mprop(%prop)) $+ [ ( ] $+ $fprop($mprop(%prop),2-) $+ [ , ]
  335. var %endeval [ ) ] $+ . $+ $mprop(%prop,1)
  336. }
  337. else {
  338. if ($IsInstance(%obejct)) {
  339. UNMAKETOK
  340. 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))
  341. }
  342. else {
  343. UNMAKETOK
  344. 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
  345. }
  346. }
  347. }
  348. else {
  349. var %eval $ $+ OBJECT $+ [ ( ]
  350. var %endeval [ ) ] $+ . $+ $prop
  351. }
  352. ;;;;;;;;;;;;;;;;;
  353.  
  354. tokenize 255 %header $+ %body $+ %footer
  355.  
  356. var %x 1
  357. while %x <= $0 {
  358. if %x == $0 {
  359. var %eval %eval $+ [ $ $+ [ %x ] ]
  360. }
  361. else {
  362. var %eval %eval $+ [ $ $+ [ %x ] ] $+ [ , ]
  363. }
  364. inc %x
  365. }
  366. return [ [ %eval ] $+ [ %endeval ] ]
  367. }
  368. ;;;;;;;;;;;;;
  369. ; End meval ;
  370. ;;;;;;;;;;;;;
  371.  
  372. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  373. ; Description: Called when ever an error is caught ;
  374. ; ;
  375. ; Usage: $catch(<Instance>,<Error>,<Message>) ;
  376. ; Example: if (!$IsInstanceOf(%Player,Player)) { ;
  377. ; $catch(%Player,InstanceErr,Object %player is not ;
  378. ; an instance of class Player) ;
  379. ; } ;
  380. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  381. alias -l CATCH {
  382. var %error $2,%message $5,%instanceOrClass $1,%scriptLine $3, %scriptDir $4, %isClass $iif($mprop($prop) == class, $true,$false)
  383.  
  384. if $isInstance(%instanceOrClass) && !%isClass {
  385. var %x 1
  386. var %inheritance $hget(MSL++,$+(%instanceOrClass,_,INIT))
  387. while $token(%inheritance,%x,32) {
  388. var %currentClass $v1
  389. if $IsException(%currentClass,%error) {
  390. var %astart $MAKETOKCOUNT
  391. MAKETOK %currentClass
  392. MAKETOK $+(%error,:,$token($token($script,-1,92),1,46),.,$prop)
  393. MAKETOK %instanceOrClass
  394. var %aend $MAKETOKCOUNT
  395.  
  396. var %bstart $MAKETOKCOUNT
  397. var %bend $MAKETOKCOUNT
  398.  
  399. var %cstart $MAKETOKCOUNT + 1
  400. MAKETOK $*
  401. var %cend $MAKETOKCOUNT
  402.  
  403. var %dstart $MAKETOKCOUNT
  404. ; For what ever comes after the tokens
  405. var %dend $MAKETOKCOUNT
  406.  
  407. return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend,%dstart,%dend)
  408. }
  409. inc %x
  410. }
  411. }
  412. else if %isClass && $isClass(%instanceOrClass) {
  413. if $IsException(%instanceOrClass,%error) {
  414. var %astart $MAKETOKCOUNT
  415. MAKETOK %instanceOrClass
  416. MAKETOK $+(%error,:,$token($token($script,-1,92),1,46),.,$mprop($prop,1))
  417. var %aend $MAKETOKCOUNT
  418.  
  419. var %bstart $MAKETOKCOUNT
  420. var %bend $MAKETOKCOUNT
  421.  
  422. var %cstart $MAKETOKCOUNT + 1
  423. MAKETOK $*
  424. var %cend $MAKETOKCOUNT
  425.  
  426. var %dstart $MAKETOKCOUNT
  427. ; For what ever comes dynamic set of paramters that come after the tokens
  428. var %dend $MAKETOKCOUNT
  429.  
  430. return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend,%dstart,%dend)
  431. }
  432. }
  433. UNMAKETOK
  434. }
  435. ;;;;;;;;;;;;;
  436. ; End Catch ;
  437. ;;;;;;;;;;;;;
  438. ;;;;;;;;;;;;;;;;;;;;
  439. ; END CLASS FOOTER ;
  440. ;;;;;;;;;;;;;;;;;;;;
  441.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement