Sfoglia il codice sorgente

Adding a small macro

Can in theory help simplify the messy buy/sell functions
Simon Watson 1 anno fa
parent
commit
b51d80eee1
1 ha cambiato i file con 4 aggiunte e 0 eliminazioni
  1. 4 0
      game.lisp

+ 4 - 0
game.lisp

@@ -211,6 +211,10 @@ Actions:
 	  (sell-transaction item-to-sell quantity)
 	(trade-menu)))))
 
+(defmacro dynamic-slot-access (predicate slotname accessor)
+  "Given a predicate where the predicate is a struct slot accessor like 'market-price-of-',
+   an 'accessor' like 'petrofuel', and a struct location, return the slot accessor function"
+    `(funcall ,(symbol-function (find-symbol (string-upcase (concatenate 'string predicate slotname)))) ,accessor))
 
 (defun display-prices ()
 ;;; (funcall (symbol-function (find-symbol (string-upcase (concatenate 'string "market-price-of-" item)))) (sector-market *sector*)) ;;; A call by string reference method for function calls