This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Running a background thread REPL on Android
- From: Remco van 't Veer <remco at remworks dot net>
- To: teyc <teyc at cognoware dot com>
- Cc: kawa at sourceware dot org
- Date: Tue, 24 Jan 2012 09:10:52 +0100
- Subject: Re: Running a background thread REPL on Android
- References: <33193100.post@talk.nabble.com>
You should start a thread, not run it;
- ((java.lang.Thread (runnable (start-repl 4444 (this)))):run)
+ ((java.lang.Thread (runnable (start-repl 4444 (this)))):start)
Otherwise it will just run the runnable associated with the thread;
http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html#run()
HTH,
Remco
2012/01/24 08:05, teyc:
> Hi all,
>
> I tried modifying Helmut Eller's eval() on Android so that it runs on a
> background thread. However, the View is no longer showing up on the main
> page. Are there any known restrictions on threading running Kawa on Android?
>
>
> (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
> ((java.lang.Thread (runnable (start-repl 4444 (this)))):run)
> (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))
> ))
> )))