Introduced sample-macros.fnl to demonstrate how import-macros works.

This commit is contained in:
Alexander Griffith 2021-09-14 01:11:55 -04:00
parent 11087a53df
commit ea38605427
2 changed files with 17 additions and 1 deletions

View file

@ -1,3 +1,5 @@
(import-macros {: incf} :sample-macros)
(var counter 0)
(var time 0)
@ -8,7 +10,8 @@
(if (< counter 65535)
(set counter (+ counter 1))
(set counter 0))
(set time (+ time dt))
(incf time dt)
;;(set time (+ time dt))
(when (> time 3)
(love.event.quit)))
:keypressed (fn keypressed [key set-mode]

13
sample-macros.fnl Normal file
View file

@ -0,0 +1,13 @@
(fn incf [value ?by]
`(set ,value (+ ,value (or ,?by 1))))
(fn decf [value ?by]
`(set ,value (+ ,value (or ,?by 1))))
(fn with [t keys ?body]
`(let [,keys ,t]
(if ,?body
,?body
,keys)))
{: incf : decf : with}