2020-11-08 20:36:38 +00:00
|
|
|
(local editor (require :editor))
|
|
|
|
(local util (require :lib.util))
|
|
|
|
(local lume (require :lib.lume))
|
|
|
|
(local link (require :link))
|
|
|
|
(require :link.command)
|
|
|
|
(local core (require :core))
|
|
|
|
(local command (require :core.command))
|
2021-06-26 01:55:15 +00:00
|
|
|
(local common (require :core.common))
|
2020-11-08 20:36:38 +00:00
|
|
|
(local keymap (require :core.keymap))
|
|
|
|
(local translate (require :core.doc.translate))
|
2021-06-26 01:55:15 +00:00
|
|
|
(local files (require :game.files))
|
|
|
|
|
2021-08-02 18:49:29 +00:00
|
|
|
(setmetatable _G nil)
|
|
|
|
|
2021-06-26 01:55:15 +00:00
|
|
|
(command.add nil {
|
|
|
|
"honeylisp:open-project" (fn []
|
|
|
|
(core.command_view:enter "Open Project"
|
|
|
|
(fn [text item]
|
|
|
|
(files.reload (or (and item item.text) text))
|
|
|
|
(core.log "Opened"))
|
|
|
|
(fn [text]
|
|
|
|
(local files [])
|
|
|
|
(each [_ item (pairs core.project_files)]
|
|
|
|
(when (and (= item.type :file) (item.filename:find "^.*/game%.json"))
|
|
|
|
(table.insert files item.filename)))
|
|
|
|
(common.fuzzy_match files text))))})
|
2020-09-17 02:34:36 +00:00
|
|
|
|
2021-09-06 03:29:16 +00:00
|
|
|
(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))
|
|
|
|
|
2020-10-15 03:40:01 +00:00
|
|
|
(command.add #(link.machine:connected?) {
|
2020-09-27 18:53:16 +00:00
|
|
|
"honeylisp:upload" (fn []
|
2020-10-12 15:48:14 +00:00
|
|
|
(local p (util.reload "game"))
|
2020-10-15 03:40:01 +00:00
|
|
|
(p:upload link.machine)
|
2020-11-10 03:58:57 +00:00
|
|
|
(when link.machine.launch (link.machine:launch p))
|
2020-09-27 18:53:16 +00:00
|
|
|
(core.log (string.format "%x" (p:lookup-addr p.start-symbol))))
|
2020-10-15 03:40:01 +00:00
|
|
|
"honeylisp:reload" (fn []
|
|
|
|
(local p-before (require :game))
|
|
|
|
(local p (util.reload :game))
|
2020-10-15 23:02:32 +00:00
|
|
|
(if (link.machine:hotswap p-before p)
|
2020-10-15 03:40:01 +00:00
|
|
|
(core.log "Reloaded!")
|
|
|
|
(core.log "Reload failed")))
|
2020-09-27 18:53:16 +00:00
|
|
|
})
|
2020-11-17 20:35:41 +00:00
|
|
|
|
|
|
|
(command.add #(and (link.machine:connected?) link.machine.overlay) {
|
|
|
|
"honeylisp:vm-eval" (fn []
|
|
|
|
(fn vm-eval [code]
|
|
|
|
(local vmcode (fennel.eval (.. "[:vm " code "]") {:env _G :compiler-env _G}))
|
|
|
|
(local prg (require :game))
|
|
|
|
(local overlay (prg.vm:gen-eval-prg vmcode))
|
|
|
|
(link.machine:overlay overlay)
|
|
|
|
"")
|
|
|
|
(editor.inline-eval vm-eval))
|
|
|
|
})
|
|
|
|
|
2021-09-06 03:29:16 +00:00
|
|
|
(command.add #(and (link.machine:connected?) link.machine.set-bp) {
|
|
|
|
"honeylisp:set-breakpoint" (fn []
|
|
|
|
(local word (selected-symbol))
|
|
|
|
(local p (require "game"))
|
|
|
|
(local addr (p:lookup-addr word))
|
|
|
|
(if addr (do (link.machine:set-bp addr)
|
|
|
|
(core.log (.. "Set breakpoint at " addr)))
|
|
|
|
(core.log (.. "Unknown address for " word))))
|
|
|
|
})
|
|
|
|
|
2020-09-27 18:53:16 +00:00
|
|
|
(command.add (fn [] true) {
|
2020-10-12 15:48:14 +00:00
|
|
|
"honeylisp:rebuild" #(util.reload "game")
|
2020-09-20 17:55:06 +00:00
|
|
|
})
|
2020-10-04 19:10:56 +00:00
|
|
|
|
2020-09-20 17:55:06 +00:00
|
|
|
(command.add "core.docview" {
|
2020-11-08 20:36:38 +00:00
|
|
|
"fennel:eval" #(editor.inline-eval #(fv (fennel.eval $1 {:env _G :compiler-env _G}) {}))
|
2020-09-20 17:55:06 +00:00
|
|
|
"lume:hotswap" (fn []
|
|
|
|
(local modname
|
|
|
|
(-> core.active_view.doc.filename
|
|
|
|
(: :gsub "%.%a+$" "")
|
|
|
|
(: :gsub "/" ".")
|
|
|
|
(: :gsub "^data%." "")
|
|
|
|
(: :gsub "%.init$" "")))
|
|
|
|
(core.log (.. "Hotswapping " modname))
|
2020-10-06 03:47:25 +00:00
|
|
|
(local (mod err) (util.hotswap modname))
|
2020-09-20 17:55:06 +00:00
|
|
|
(when (not= err nil) (print err) (error err)))
|
2020-09-27 18:53:16 +00:00
|
|
|
"honeylisp:address" (fn []
|
2020-10-04 19:10:56 +00:00
|
|
|
(local word (selected-symbol))
|
2020-10-12 15:48:14 +00:00
|
|
|
(local p (require "game"))
|
2020-09-27 18:53:16 +00:00
|
|
|
(core.log (string.format "%s %x" word (or (p:lookup-addr word) -1)))
|
|
|
|
)
|
2020-09-20 17:55:06 +00:00
|
|
|
})
|
|
|
|
(keymap.add {
|
|
|
|
"alt+e" "fennel:eval"
|
2020-11-17 20:35:41 +00:00
|
|
|
"alt+v" "honeylisp:vm-eval"
|
2020-09-20 17:55:06 +00:00
|
|
|
"alt+r" "lume:hotswap"
|
2020-10-04 19:10:56 +00:00
|
|
|
"alt+a" "honeylisp:address"
|
2021-09-06 03:29:16 +00:00
|
|
|
"alt+b" "honeylisp:set-breakpoint"
|
2020-10-15 03:40:01 +00:00
|
|
|
"alt+l" "honeylisp:reload"
|
2020-09-20 17:55:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
{}
|