[feat] add console log module

This commit is contained in:
SouthFox 2024-05-20 22:37:08 +08:00
parent e970ed8706
commit 9c2f4c1c5f
4 changed files with 21 additions and 2 deletions

View file

@ -8,7 +8,8 @@ modules = \
modules/dom/window.scm \ modules/dom/window.scm \
modules/math.scm \ modules/math.scm \
modules/math/rect.scm \ modules/math/rect.scm \
modules/math/vector.scm modules/math/vector.scm\
modules/console.scm
game.wasm: game.scm $(modules) game.wasm: game.scm $(modules)
guild compile-wasm -L modules -o $@ $< guild compile-wasm -L modules -o $@ $<

View file

@ -66,6 +66,9 @@ window.addEventListener("load", async () => {
}, },
math: { math: {
random: () => Math.random() random: () => Math.random()
},
console: {
log: (message) => console.log(message)
} }
}); });
} catch(e) { } catch(e) {

View file

@ -1,13 +1,15 @@
(import (scheme base) (import (scheme base)
(scheme inexact) (scheme inexact)
(hoot ffi) (hoot ffi)
(hoot debug)
(dom canvas) (dom canvas)
(dom document) (dom document)
(dom element) (dom element)
(dom event) (dom event)
(dom image) (dom image)
(dom media) (dom media)
(dom window)) (dom window)
(console))
(define game-width 640.0) (define game-width 640.0)
@ -29,3 +31,6 @@
(set-element-height! canvas (exact game-height)) (set-element-height! canvas (exact game-height))
(request-animation-frame draw-callback) (request-animation-frame draw-callback)
(dprint "game-height" game-height)
(console-log canvas)

10
modules/console.scm Normal file
View file

@ -0,0 +1,10 @@
(define-module (console)
#:pure
#:use-module (scheme base)
#:use-module (hoot ffi)
#:export (console-log))
(define-foreign console-log
"console" "log"
(ref extern) -> (ref extern))