Running a background thread REPL on Android
teyc
teyc@cognoware.com
Tue Jan 24 10:56:00 GMT 2012
> Using (future (start-repl 4444 (this))) is probably the easier way to
> start a new thread.
>
> Helmut
>
That did the trick. Here's my completed example.
(require 'android-defs)
(define (msg (fstring string) #!rest args)
(android.util.Log:v "kawa-hello" (apply format fstring args)))
(define (start-repl port uiContext)
(begin
; required! otherwise the getLanguage() call will fail
(kawa.standard.Scheme:registerEnvironment)
; required! as Android cannot compile to java
(set! gnu.expr.ModuleExp:alwaysCompile #f)
; sets the ui variable to the uiContext)
((interaction-environment):put "ui" uiContext)
(let* ((server (java.net.ServerSocket port)))
(msg "listing on ~a (~a)" port server)
(let ((socket (server:accept)))
(msg "connected ~a " socket)
(let ((in (gnu.mapping.InPort (socket:getInputStream)))
(out (gnu.mapping.OutPort (socket:getOutputStream))))
(parameterize ((current-input-port in)
(current-output-port out))
(do () (#f)
(try-catch
(begin
(format #t "\n> " )
(force-output)
(let ((form (read)))
(format #t "form: ~s\n" form)
(format #t "~s" (eval form (interaction-environment)))))
(e java.lang.Exception
(e:printStackTrace out))))))))))
(activity hello
(on-create-view
(begin
(future (start-repl 4444 (this)))
(let ((panel
(android.widget.LinearLayout (this)
orientation: android.widget.LinearLayout:VERTICAL
view:
(android.widget.TextView (this)
text: "Hello, Android REPL from Kawa Scheme!")
view:
(android.widget.Button (this)
text: "Click Me!"
on-click-listener:
(lambda (v)
((android.widget.Toast:makeText (this)
"Beep Bop! You clicked me!"
android.widget.Toast:LENGTH_LONG):show))
))))
panel
))))
ps. In the larger scheme of things, I'm interested in exploratory
live-coding on the device rather than redeploying a new app every time. I'm
new to Scheme... and I've experienced more oddities that I'll post as as a
separate problem.
--
View this message in context: http://old.nabble.com/Running-a-background-thread-REPL-on-Android-tp33193100p33194129.html
Sent from the Sourceware - kawa list mailing list archive at Nabble.com.
More information about the Kawa
mailing list