##// END OF EJS Templates
API call for FOR loop to make the main code less cluttered
API call for FOR loop to make the main code less cluttered

File last commit:

r18:6b72d87e default
r19:c40f6d7d default
Show More
intrinsics.ps
292 lines | 6.9 KiB | application/postscript | PostScriptLexer
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
(in-package sugar-qsp)
Tutorial game works!
r6 ;;;; Functions and procedures defined by the QSP language.
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 ;;;; They can call api and deal with locations and other data directly.
;;;; Except vars. Use VAR and SET or GET-VAR and SET-VAR api calls.
Tutorial game works!
r6 (setf (root lib) (ps:create))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 1loc
Properly handle stringly-indexed arrays
r16 (defm (root lib goto) (target args)
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 (api-call clear-text :main)
Properly handle stringly-indexed arrays
r16 (funcall (root lib xgoto) target (or args (list)))
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Properly handle stringly-indexed arrays
r16 (defm (root lib xgoto) (target args)
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 (api-call clear-act)
Menu, game saving
r11 (setf (root current-location) (ps:chain target (to-upper-case)))
Properly handle stringly-indexed arrays
r16 (api-call stash-state args)
(funcall (ps:getprop (root locs) (root current-location))
(or args (list)))
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 2var
;;; 3expr
;;; 4code
Menu, game saving
r11 (defm (root lib rand) (a &optional (b 1))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 (let ((min (min a b))
(max (max a b)))
(+ min (ps:chain *math (random (- max min))))))
;;; 5arrays
Tutorial game works!
r6 (defm (root lib copyarr) (to from start count)
Properly handle stringly-indexed arrays
r16 (multiple-value-bind (to-name to-slot)
(api-call var-real-name to)
(multiple-value-bind (from-name from-slot)
(api-call var-real-name from)
(ps:for ((i start))
((< i (min (api-call array-size from-name)
(+ start count))))
((incf i))
(api-call set-var to-name (+ start i) to-slot
(api-call get-var from-name (+ start i) from-slot))))))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib arrpos) (name value &optional (start 0))
Properly handle stringly-indexed arrays
r16 (multiple-value-bind (real-name slot)
(api-call var-real-name name)
(ps:for ((i start)) ((< i (api-call array-size name))) ((incf i))
(when (eq (api-call get-var real-name i slot) value)
(return i))))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 -1)
Tutorial game works!
r6 (defm (root lib arrcomp) (name pattern &optional (start 0))
Properly handle stringly-indexed arrays
r16 (multiple-value-bind (real-name slot)
(api-call var-real-name name)
(ps:for ((i start)) ((< i (api-call array-size name))) ((incf i))
(when (funcall (ps:getprop (api-call get-var real-name i slot) 'match) pattern)
(return i))))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 -1)
;;; 6str
Tutorial game works!
r6 (defm (root lib instr) (s subs &optional (start 1))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 (+ start (ps:chain s (substring (- start 1)) (search subs))))
Tutorial game works!
r6 (defm (root lib isnum) (s)
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 (if (is-na-n s)
0
-1))
Tutorial game works!
r6 (defm (root lib strcomp) (s pattern)
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 (if (s.match pattern)
-1
0))
Tutorial game works!
r6 (defm (root lib strfind) (s pattern group)
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 (let* ((re (ps:new (*reg-exp pattern)))
(match (re.exec s)))
(match.group group)))
Tutorial game works!
r6 (defm (root lib strpos) (s pattern &optional (group 0))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 (let* ((re (ps:new (*reg-exp pattern)))
(match (re.exec s))
(found (match.group group)))
(if found
(s.search found)
0)))
;;; 7if
Menu, game saving
r11 ;; Has to be a function because it always evaluates all three of its
;; arguments
Tutorial game works!
r6 (defm (root lib iif) (cond-expr then-expr else-expr)
Menu, game saving
r11 (if cond-expr then-expr else-expr))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 8sub
Tutorial game works!
r6 (defm (root lib gosub) (target &rest args)
Properly handle stringly-indexed arrays
r16 (funcall (ps:getprop (root locs) target) args)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib func) (target &rest args)
Properly handle stringly-indexed arrays
r16 (funcall (ps:getprop (root locs) target) args))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 9loops
;;; 10dynamic
Properly handle stringly-indexed arrays
r16 (defm (root lib dynamic) (block &rest args)
(funcall block args)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Properly handle stringly-indexed arrays
r16 (defm (root lib dyneval) (block &rest args)
(funcall block args))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 11main
Tutorial game works!
r6 (defm (root lib main-p) (s)
Menu, game saving
r11 (api-call add-text :main s)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib main-pl) (s)
(api-call add-text :main s)
Menu, game saving
r11 (api-call newline :main)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib main-nl) (s)
(api-call newline :main)
Menu, game saving
r11 (api-call add-text :main s)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib maintxt) (s)
Menu, game saving
r11 (api-call get-text :main)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Menu, game saving
r11 ;; For clarity (it leaves a lib.desc() call in JS)
Tutorial game works!
r6 (defm (root lib desc) (s)
Use flex in html
r10 "")
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib main-clear) ()
Menu, game saving
r11 (api-call clear-text :main)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 ;;; 12stat
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Menu, game saving
r11 (defm (root lib stat-p) (s)
(api-call add-text :stat s)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Menu, game saving
r11 (defm (root lib stat-pl) (s)
(api-call add-text :stat s)
(api-call newline :stat)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Menu, game saving
r11 (defm (root lib stat-nl) (s)
(api-call newline :stat)
(api-call add-text :stat s)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Menu, game saving
r11 (defm (root lib stattxt) (s)
(api-call get-text :stat)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Menu, game saving
r11 (defm (root lib stat-clear) ()
(api-call clear-text :stat)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Menu, game saving
r11 (defm (root lib cls) ()
(funcall (root lib stat-clear))
(funcall (root lib main-clear))
(funcall (root lib cla))
(funcall (root lib cmdclear))
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 13diag
;;; 14act
Menu, game saving
r11 (defm (root lib curacts) ()
(let ((acts (root acts)))
(lambda ()
(setf (root acts) acts)
(values))))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 15objs
Tutorial game works!
r6 (defm (root lib addobj) (name)
(ps:chain (root objs) (push name))
Menu, game saving
r11 (api-call update-objs)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib delobj) (name)
(let ((index (ps:chain (root objs) (index-of name))))
(when (> index -1)
Sounds, save/load UI buttons
r12 (funcall (root lib killobj) (1+ index))))
Menu, game saving
r11 (values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Sounds, save/load UI buttons
r12 (defm (root lib killobj) (&optional (num nil))
(if (eq nil num)
(setf (root objs) (list))
(ps:chain (root objs) (splice (1- num) 1)))
Menu, game saving
r11 (api-call update-objs)
(values))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 16menu
Menu, game saving
r11 (defm (root lib menu) (menu-name)
(let ((menu-data (list)))
Locals
r14 (loop :for item :in (api-call get-array (api-call var-real-name menu-name))
Menu, game saving
r11 :do (cond ((string= item "")
(break))
((string= item "-:-")
(ps:chain menu-data (push :delimiter)))
(t
(let* ((tokens (ps:chain item (split ":"))))
(when (= (length tokens) 2)
(tokens.push ""))
(let* ((text (ps:chain tokens (splice 0 (- tokens.length 2)) (join ":")))
(loc (ps:getprop tokens (- tokens.length 2)))
(icon (ps:getprop tokens (- tokens.length 1))))
(ps:chain menu-data
(push (ps:create text text
loc loc
icon icon))))))))
(api-call menu menu-data)
(values)))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 17sound
Sounds, save/load UI buttons
r12 (defm (root lib play) (filename &optional (volume 100))
(let ((audio (ps:new (*audio filename))))
(setf (ps:getprop (root playing) filename) audio)
(setf (ps:@ audio volume) (* volume 0.01))
(ps:chain audio (play))))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Sounds, save/load UI buttons
r12 (defm (root lib close) (filename)
(funcall (root playing filename) stop)
(ps:delete (root playing filename)))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Sounds, save/load UI buttons
r12 (defm (root lib closeall) ()
(loop :for k :in (*object.keys (root playing))
:for v := (ps:getprop (root playing) k)
:do (funcall v stop))
(setf (root playing) (ps:create)))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 18img
Some DOM stuff, VIEW
r18 (defm (root lib refint) ()
;; "Force interface update" Uh... what exactly do we do here?
)
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 19input
Tutorial game works!
r6 (defm (root lib showinput) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib usertxt) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib cmdclear) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib input) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
;;; 20time
Menu, game saving
r11 ;; I wonder if there's a better solution than busy-wait
(defm (root lib wait) (msec)
(let* ((now (ps:new (*date)))
(exit-time (+ (funcall now.get-time) msec)))
(loop :while (< (funcall now.get-time) exit-time))))
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib msecscount) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib settimer) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Locals
r14 ;;; 21local
Some DOM stuff, VIEW
r18 ;;; 22for
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1 ;;; misc
Tutorial game works!
r6 (defm (root lib rgb) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib openqst) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib addqst) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1
Tutorial game works!
r6 (defm (root lib killqst) ())
100% parser, 100% macros, 50% intrinsics, 10% api, 0% misc
r1