oakes / play-clj

A Clojure game library
The Unlicense
940 stars 72 forks source link

key-code shouldn't be a macro #103

Closed marad closed 7 years ago

marad commented 7 years ago

The key-code function is defined as a macro here: https://github.com/oakes/play-clj/blob/894040fae0ced31568f464753bb780dee49f679f/src/play_clj/core_basics.clj#L110

This causes this code to fail:

(key-code (:up controls))

I'ts because key-code body is not quoted, so it's executed at macro expansion time and the argument is unevaluated '(:up controls) instead of the actual value I'd like to have there. Then it breaks on key->upper function because it cannot convert the list '(:up controls) to a name.

Fix could be simple:

(defn key-code [k]
  (eval (u/gdx-field "Input$Keys" (u/key->upper k))))
oakes commented 7 years ago

Fixed, thanks.