106 lines
2.8 KiB
Fennel
106 lines
2.8 KiB
Fennel
(require "editor")
|
|
(local util (require "lib.util"))
|
|
(local lume (require "lib.lume"))
|
|
(local imgui (require "imgui"))
|
|
(local link (require "link"))
|
|
(local core (require "core"))
|
|
(local command (require "core.command"))
|
|
(local keymap (require "core.keymap"))
|
|
(local translate (require "core.doc.translate"))
|
|
|
|
(command.add #(not= link.name :serial) {
|
|
"serial:switch-machine" #(link:switch :serial)
|
|
})
|
|
(command.add #(not= link.name :gsplus) {
|
|
"gsplus:switch-machine" #(link.switch :gsplus)
|
|
})
|
|
(command.add #(link.machine:connected?) {
|
|
"honeylisp:upload" (fn []
|
|
(local p (util.reload "game"))
|
|
(p:upload link.machine)
|
|
(core.log (string.format "%x" (p:lookup-addr p.start-symbol))))
|
|
"honeylisp:reload" (fn []
|
|
(local p-before (require :game))
|
|
(local p (util.reload :game))
|
|
(if (link.machine:do p-before #(p:upload $1))
|
|
(core.log "Reloaded!")
|
|
(core.log "Reload failed")))
|
|
})
|
|
(command.add (fn [] true) {
|
|
"honeylisp:rebuild" #(util.reload "game")
|
|
})
|
|
|
|
(fn selected-symbol []
|
|
(local ldoc core.active_view.doc)
|
|
(var (aline acol bline bcol) (ldoc:get_selection))
|
|
(when (and (= aline bline) (= acol bcol))
|
|
(set (aline acol) (translate.start_of_word ldoc aline acol))
|
|
(set (bline bcol) (translate.end_of_word ldoc bline bcol)))
|
|
(ldoc:get_text aline acol bline bcol))
|
|
|
|
(command.add "core.docview" {
|
|
"fennel:eval" (fn []
|
|
(let [ldoc core.active_view.doc
|
|
(aline acol bline bcol) (ldoc:get_selection)
|
|
options {:env _G :compiler-env _G}
|
|
inject #(ldoc:insert bline bcol (fv (fennel.eval $1 options) {}))]
|
|
(if (and (= aline bline) (= acol bcol))
|
|
(inject (ldoc:get_text aline 1 aline 10000000))
|
|
(inject (ldoc:get_text aline acol bline bcol)))))
|
|
"lume:hotswap" (fn []
|
|
(local modname
|
|
(-> core.active_view.doc.filename
|
|
(: :gsub "%.%a+$" "")
|
|
(: :gsub "/" ".")
|
|
(: :gsub "^data%." "")
|
|
(: :gsub "%.init$" "")))
|
|
(core.log (.. "Hotswapping " modname))
|
|
(local (mod err) (util.hotswap modname))
|
|
(when (not= err nil) (print err) (error err)))
|
|
"honeylisp:address" (fn []
|
|
(local word (selected-symbol))
|
|
(local p (require "game"))
|
|
(core.log (string.format "%s %x" word (or (p:lookup-addr word) -1)))
|
|
)
|
|
})
|
|
(keymap.add {
|
|
"alt+e" "fennel:eval"
|
|
"alt+r" "lume:hotswap"
|
|
"alt+a" "honeylisp:address"
|
|
"alt+l" "honeylisp:reload"
|
|
})
|
|
|
|
(fn love.load [])
|
|
|
|
(fn love.update [dt]
|
|
(imgui.NewFrame))
|
|
|
|
(fn love.draw []
|
|
(imgui.Render))
|
|
|
|
(fn love.quit []
|
|
(imgui.ShutDown))
|
|
|
|
(fn love.textinput [t]
|
|
(imgui.TextInput t))
|
|
|
|
(fn love.keypressed [key]
|
|
(imgui.KeyPressed key))
|
|
|
|
(fn love.keyreleased [key]
|
|
(imgui.KeyReleased key))
|
|
|
|
(fn love.mousemoved [x y]
|
|
(imgui.MouseMoved x y))
|
|
|
|
(fn love.mousepressed [x y button]
|
|
(imgui.MousePressed button))
|
|
|
|
(fn love.mousereleased [x y button]
|
|
(imgui.MouseReleased button))
|
|
|
|
(fn love.wheelmoved [x y]
|
|
(imgui.WheelMoved y))
|
|
|
|
{}
|