Allow eval before run
technomancy opened this issue · 1 comments
Currently in order to use the eval
command, you have to first run
and then hit esc to close the game.
For normal development this is fine. However, if this restriction were lifted, it would make it possible to automate tests; for example, you could run something like this:
$ tic80 --cli --cmd "new fennel" \
--cmd "eval (fn _G.btnp [] (< 0.5 (math.random))) (set _G.btn _G.btnp)" \
--cmd "eval (for [_ 1 1024] (_G.TIC)) (trace \"Success\")"
This would set the keypad to return random values and run 1024 tics of the game. If I could do this with all the Fennel-based TIC-80 games I've found, it would help a lot with testing new versions of Fennel to identify crashes, but I'd imagine that it would also be helpful for testing other changes to TIC-80. In the future perhaps even a --randomize-input
flag could be added to further facilitate testing.
However when I tried a few different attempts of implementing this myself, I ran into dead ends. First I tried making changes in evalFennel
so that it would call initFennel
if the Lua VM was not yet initialized. This worked for basic code, but as soon as I went to call trace
it would segfault abruptly. Then I thought maybe I was solving the problem in the wrong place; it would be better if it could work with any language, so maybe handling it in onEvalCommand
was a better idea. I noticed that a lot of the initialization work was done in tic_core_tick
instead of tic_init_vm
, so that had to be moved. But it doesn't seem possible to call tic_init_vm
from onEvalCommand
anyway.
So, two questions:
- is this a good idea in the first place?
- if so, could I get some tips of where to start with the implementation?