X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=if.lisp;h=447f69787db91d9ae9364c3290072654903bc4ec;hb=HEAD;hp=dd8d31ae82e56a99d3aba7d3394afba901632796;hpb=a55a923ba8e14bae6a6590c2b28b379f773f8760;p=lifp.git diff --git a/if.lisp b/if.lisp index dd8d31a..447f697 100644 --- a/if.lisp +++ b/if.lisp @@ -36,18 +36,17 @@ :addword :word2dic :addword2dic :split-to-words :sprint :parser :description :article :glance - :initnames :addnames - :read-property :read-property-string :read-property-number - :read-property-integer :read-property-object :read-property-execute - :read-property-other :read-property-list :exec :exec* + :initnames :addnames + :read-property :rp :read-property- + :exec :exec* :abstractobject :name :names :parent :children :flags - :initflags :add-flags :has :hasnt :-> :give + :initflags :add-flags :has :hasnt :-> :give :child :ifclass :object :defaction :*meta* - :move :rmv :ofclass :among + :move :rmv :ofclass :among :below :verb :extend-verb :extend-verb-first :extend-verb-only :extend-verb-only-first :deftoken :string== :matchp :!last! - :in :objectloop :provides + :in :notin :objectloop :provides :wordlist :tokenlist :nosuchword :nosuchword-word :parse-command :unknown-verb :run-action :run-action-after @@ -89,7 +88,7 @@ "make defvars for names" `(progn ,@(loop for x in names - collect `(defvar ,x)))) + collect `(defvar ,x nil)))) ;;SECTION 2: Global parameters and definitions @@ -359,7 +358,7 @@ word in dictionary, add it." (defun give (obj &rest flags) "Informish synonim to add-flags." - (setf (flags obj) (combine-flags (append (flags obj) flags)))) + (setf (flags obj) (combine-flags (append (flags obj) flags))) nil) (defun has (obj &rest flags) "Informish macro has. Unlike Inform, can accept several flags." @@ -370,6 +369,10 @@ word in dictionary, add it." (not (intersection flags (flags obj)))) ;(not (subsetp flags (flags obj)))) +(defun child (obj) + "Returns the first child of the object" + (car (children obj))) + (defmethod parser ((obj abstractobject) words) "Default parser. Really bad one." (when (zerop (length words)) (return-from parser 0)) @@ -478,6 +481,17 @@ word in dictionary, add it." (glance (apply #'read-property-string (slot-value self property) args)) (t (slot-value self property)))) +(defun read-property- (method self property &rest args) + "read-property using specific method. method is one of keywords: + :string :number :object :integer :execute :list" + (case method + (:string (apply #'read-property-string (slot-value self property) args)) + (:number (apply #'read-property-number (slot-value self property) args)) + (:integer (apply #'read-property-integer (slot-value self property) args)) + (:object (apply #'read-property-object (slot-value self property) args)) + (:execute (apply #'read-property-execute (slot-value self property) args)) + (:list (apply #'read-property-list (slot-value self property) args)) + (t (slot-value self property)))) ;;SECTION 7: IfClass macro and its hairy surroundings @@ -730,7 +744,14 @@ word in dictionary, add it." (defun notin (obj &rest what) "Test whether the object is not in any of other arguments" (notany (lambda (x) (eql (parent obj) x)) what)) - + +(defun below (obj1 obj2) + "Tests whether obj1 is strictly below obj2 in object structure" + (loop for x = obj1 then (parent x) + while x + when (eql x obj2) do (return t) + finally (return nil))) + ;;SECTION 9: Verb functions (defstruct patternlist value) @@ -937,14 +958,15 @@ word in dictionary, add it." ;;React after? t) -(defun run-action (action args &key (time 0)) +(defun run-action (action args &key (time 0) no-output) "Run an action with a given args" (unless (listp args) (setf args (list args))) (setf *after* nil) (let ((*action* action) (*args* args) (*noun* (first args)) - (*second* (second args))) + (*second* (second args)) + (*no-output* no-output)) (when *debug* (format t "[running action: ~a ~a]~%" *action* *args*)) (when *meta* ;;Just do the darn thing!