[Fluxus] convenient(?) debugging test

Kassen signal.automatique at gmail.com
Sat Aug 21 12:37:37 PDT 2010


Dear list,

I just wrote the code below. The issue is that I don't really like switching
to the repl every time to read my debugging (display) prints, so I created
this stuff to be able to print to the scene itself. This works quite well,
so far, I'll add it to me .fluxus.scm On the positive side; it's faster than
switching and more fun too. It also scales, depending on the size of the
message. On the downside; the scaling and translating it does probably only
works for my own set screen-size (1024 x 768) and camera settings (the
default). Also; it seems that I can't parent this to the camera. New
messages will be in the right spot but moving the camera will ruin that and
I didn't want to add a task. Worse; I added to-string conversion for most
stuff I'm likely to encounter but there must be a lot more, like procedures.
There might be a better way for that. It's also quite limited, with no
new-line and only a single message at a time, though this message may be a
list if messages.

I looked into catching the errors that end up in the repl as well, to print
those in a different colour, but it seems that you need to register some
sort of "port" construct and it was all a bit beyond me. That does sound
like a fun thing to think about, though.

Still, this works well enough for me right now to add it to my .fluxus.scm
and test it for a while, might be useful for others too.

(print stuff); prints stuff, or at least gives it a go
(clear-print); gets the printed stuff out of the way
debug-colour; sets the colour and transparency for this printing

That's it.

Yours,
Kas.



(define debug-print #f)
(define debug-colour (vector 1 1 1 .7))


(define (to-string msg)
    (let ((output "unknown type"))
        (when (string? msg) (set! output msg))
        (when (symbol? msg) (set! output (symbol->string msg)))
        (when (number? msg) (set! output (number->string msg)))
        (when (boolean? msg) (set! output (if msg "#t" "#f")))

        (when (list? msg)
            (set! output "( ")
                (for ((x (in-range 0 (length msg))))
                    (set! output (string-append output (to-string (list-ref
msg x)) " ")))
                (set! output (string-append output ")")))
        (when (vector? msg)
            (set! output "#( ")
                (for ((x (in-range 0 (vector-length msg))))
                    (set! output (string-append output (to-string
(vector-ref msg x)) " ")))
                (set! output (string-append output ")")))

        output))


(define (clear-print)
    (when (number? debug-print) (destroy debug-print))
    (set! debug-print #f))

(define (print msg)
    (let*(
            ( output (to-string msg))
            (s (min 1 (/ 6 (string-length output)))))
    (with-state

        (concat (minverse (get-camera-transform)))
        (hint-ignore-depth)
        (hint-depth-sort)
        (hint-unlit)
        (colour debug-colour)

        (texture (load-texture "font.png"))

        (translate (vector -1.05 (* .7 s) -1.1))

        (scale s)
        (when (number? debug-print) (destroy debug-print))
        (set! debug-print (build-text output)))))


;let's test!
(clear)
(build-cube)

(print (list 1 (list 2 3) #f "fluxus" 'test (time) time (vector 4 5)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pawfal.org/pipermail/fluxus-pawfal.org/attachments/20100821/9e1c8b0f/attachment-0002.htm>


More information about the Fluxus mailing list