Skip to content

Commit 116d28a

Browse files
committed
ANDROID jSCHEME: update following changes to setContentView
1 parent 735d810 commit 116d28a

File tree

6 files changed

+173
-134
lines changed

6 files changed

+173
-134
lines changed

modules/ln_jscheme/ANDROID_c_additions

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* -*-C-*- */
1+
/* ln_jscheme -*-C-*- */
22

33
const char* android_app_class() { return "@SYS_PACKAGE_DOT@.@SYS_APPNAME@"; } // for jscheme
44

@@ -80,3 +80,5 @@ const char* lnjscheme_eval_receive_result()
8080
}
8181
return str;
8282
}
83+
84+
/* EOF ln_jscheme */

modules/ln_jscheme/ANDROID_java_activityadditions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void ln_log(String msg) {
1212
Log.d(TAG, m);
1313
}
1414

15-
private Object onBackPressedHandler = null;
15+
private static Object onBackPressedHandler = null;
1616

1717
@Override
1818
public void onBackPressed() {
Lines changed: 108 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,131 @@
11
/* LNjScheme -*- mode: java; c-basic-offset: 2; -*- */
22

3-
LNjSchemeSession = new LNjScheme.Scheme
4-
(new String[0])
5-
{
3+
if(LNjSchemeSession==null) {
64

7-
public void ln_log(String msg) {
8-
String m = ln_log_date_formatter.format(new java.util.Date()) + msg;
9-
System.err.println(TAG + ": " + m);
10-
Log.d(TAG, m);
11-
}
12-
};
5+
LNjSchemeSession = new LNjScheme.Scheme
6+
(new String[0])
7+
{
138

14-
LNjSchemeEvaluateNoSync
15-
(LNjScheme.Scheme.cons
16-
(LNjScheme.Scheme.sym("define"),
17-
LNjScheme.Scheme.list
18-
(LNjScheme.Scheme.sym("ln-this"),
19-
this
20-
)));
9+
public void ln_log(String msg) {
10+
String m = ln_log_date_formatter.format(new java.util.Date()) + msg;
11+
System.err.println(TAG + ": " + m);
12+
Log.d(TAG, m);
13+
}
14+
};
2115

22-
LNjSchemeEvaluateNoSync
23-
(LNjScheme.Scheme.cons
24-
(LNjScheme.Scheme.sym("define"),
25-
LNjScheme.Scheme.list
26-
(LNjScheme.Scheme.sym("ln-mglview"),
27-
mGLView
28-
)));
16+
LNjSchemeEvaluateNoSync
17+
(LNjScheme.Scheme.cons
18+
(LNjScheme.Scheme.sym("define"),
19+
LNjScheme.Scheme.list
20+
(LNjScheme.Scheme.sym("log-message"),
21+
new LNMethod("log-message") {
22+
public Object apply(LNjScheme.Scheme interpreter, Object args) {
23+
String str = null;
24+
if(args instanceof LNjScheme.Pair) {
25+
Object a1 = null;
26+
a1 = LNjScheme.Scheme.first(args);
27+
if(a1 instanceof String) { str = (String)a1; }
28+
else if(a1 instanceof char[]) { str = new String((char[])a1); }
29+
else { str = "log-message: message not convertible"; }
30+
} else {
31+
str = "log-message: args not a list";
32+
}
33+
ln_log(str);
34+
return null;
35+
}}
36+
)));
2937

30-
LNjSchemeEvaluateNoSync
31-
(LNjScheme.Scheme.cons
32-
(LNjScheme.Scheme.sym("define"),
33-
LNjScheme.Scheme.list
34-
(LNjScheme.Scheme.sym("log-message"),
35-
new LNMethod("log-message") {
36-
public Object apply(LNjScheme.Scheme interpreter, Object args) {
37-
String str = null;
38-
if(args instanceof LNjScheme.Pair) {
39-
Object a1 = null;
40-
a1 = LNjScheme.Scheme.first(args);
41-
if(a1 instanceof String) { str = (String)a1; }
42-
else if(a1 instanceof char[]) { str = new String((char[])a1); }
43-
else { str = "log-message: message not convertible"; }
44-
} else {
45-
str = "log-message: args not a list";
46-
}
47-
ln_log(str);
48-
return null;
49-
}}
50-
)));
38+
LNjSchemeEvaluateNoSync
39+
(LNjScheme.Scheme.cons
40+
(LNjScheme.Scheme.sym("define"),
41+
LNjScheme.Scheme.list
42+
(LNjScheme.Scheme.sym("bound?"),
43+
new LNMethod("bound?") {
44+
public Object apply(LNjScheme.Scheme interpreter, Object args) {
45+
if(args instanceof LNjScheme.Pair) {
46+
Object a1 = null;
47+
a1 = LNjScheme.Scheme.first(args);
48+
if(a1 instanceof String) {
49+
String sym = (String)a1;
50+
try {
51+
Object val = interpreter.eval(sym);
52+
return true;
53+
} catch (RuntimeException e) { return false; }
54+
} else {
55+
return LNjScheme.Scheme.error("bound? : not a symbol " + a1);
56+
}
57+
} else {
58+
return LNjScheme.Scheme.error("bound? : missing argument");
59+
}
60+
}}
61+
)));
5162

52-
LNjSchemeEvaluateNoSync
53-
(LNjScheme.Scheme.cons
54-
(LNjScheme.Scheme.sym("define"),
55-
LNjScheme.Scheme.list
56-
(LNjScheme.Scheme.sym("bound?"),
57-
new LNMethod("bound?") {
58-
public Object apply(LNjScheme.Scheme interpreter, Object args) {
59-
if(args instanceof LNjScheme.Pair) {
60-
Object a1 = null;
61-
a1 = LNjScheme.Scheme.first(args);
62-
if(a1 instanceof String) {
63-
String sym = (String)a1;
64-
try {
65-
Object val = interpreter.eval(sym);
66-
return true;
67-
} catch (RuntimeException e) { return false; }
63+
LNjSchemeEvaluateNoSync
64+
(LNjScheme.Scheme.cons
65+
(LNjScheme.Scheme.sym("define"),
66+
LNjScheme.Scheme.list
67+
(LNjScheme.Scheme.sym("send-event!"),
68+
new LNMethod("send-event!") {
69+
public Object apply(LNjScheme.Scheme interpreter, Object args) {
70+
String str = null;
71+
if(args instanceof LNjScheme.Pair) {
72+
Object a1 = null, a2 = null, a3 = null;;
73+
a1 = LNjScheme.Scheme.first(args);
74+
a2 = LNjScheme.Scheme.rest(args);
75+
a3 = LNjScheme.Scheme.rest(a2);
76+
a2 = LNjScheme.Scheme.first(a2);
77+
a3 = LNjScheme.Scheme.first(a3);
78+
// Maybe we should accept symbolic event names too?
79+
int ia1 = (a1 instanceof Number) ? (int)LNjScheme.Scheme.num(a1) : 21;
80+
int ia2 = (a2 instanceof Number) ? (int)LNjScheme.Scheme.num(a2) : 0;
81+
int ia3 = (a3 instanceof Number) ? (int)LNjScheme.Scheme.num(a3) : 0;
82+
nativeEvent(ia1, ia2, ia3);
83+
return LNjScheme.Scheme.TRUE;
6884
} else {
69-
return LNjScheme.Scheme.error("bound? : not a symbol " + a1);
85+
nativeEvent(64, 0, 0); // debug
86+
return LNjScheme.Scheme.TRUE;
7087
}
71-
} else {
72-
return LNjScheme.Scheme.error("bound? : missing argument");
73-
}
74-
}}
75-
)));
88+
}}
89+
)));
90+
91+
LNjSchemeEvaluateNoSync
92+
(LNjScheme.Scheme.cons
93+
(LNjScheme.Scheme.sym("define"),
94+
LNjScheme.Scheme.list
95+
(LNjScheme.Scheme.sym("on-back-pressed"),
96+
new LNMethod("on-back-pressed") {
97+
public Object apply(LNjScheme.Scheme interpreter, Object args) {
98+
String str = null;
99+
if(args instanceof LNjScheme.Pair) {
100+
Object a1 = null;
101+
a1 = LNjScheme.Scheme.first(args);
102+
if(a1 instanceof LNjScheme.Procedure) { onBackPressedHandler = (LNjScheme.Procedure)a1; }
103+
else if(!LNjScheme.Scheme.truth(a1)) { onBackPressedHandler = null; }
104+
else { LNjScheme.Scheme.error("on-back-pressed: argument not a procedure or #f"); }
105+
return LNjScheme.Scheme.TRUE;
106+
} else {
107+
if(onBackPressedHandler==null) { return LNjScheme.Scheme.FALSE; }
108+
else { return onBackPressedHandler; }
109+
}
110+
}}
111+
)));
112+
113+
}
76114

77115
LNjSchemeEvaluateNoSync
78116
(LNjScheme.Scheme.cons
79117
(LNjScheme.Scheme.sym("define"),
80118
LNjScheme.Scheme.list
81-
(LNjScheme.Scheme.sym("send-event!"),
82-
new LNMethod("send-event!") {
83-
public Object apply(LNjScheme.Scheme interpreter, Object args) {
84-
String str = null;
85-
if(args instanceof LNjScheme.Pair) {
86-
Object a1 = null, a2 = null, a3 = null;;
87-
a1 = LNjScheme.Scheme.first(args);
88-
a2 = LNjScheme.Scheme.rest(args);
89-
a3 = LNjScheme.Scheme.rest(a2);
90-
a2 = LNjScheme.Scheme.first(a2);
91-
a3 = LNjScheme.Scheme.first(a3);
92-
// Maybe we should accept symbolic event names too?
93-
int ia1 = (a1 instanceof Number) ? (int)LNjScheme.Scheme.num(a1) : 21;
94-
int ia2 = (a2 instanceof Number) ? (int)LNjScheme.Scheme.num(a2) : 0;
95-
int ia3 = (a3 instanceof Number) ? (int)LNjScheme.Scheme.num(a3) : 0;
96-
nativeEvent(ia1, ia2, ia3);
97-
return LNjScheme.Scheme.TRUE;
98-
} else {
99-
nativeEvent(64, 0, 0); // debug
100-
return LNjScheme.Scheme.TRUE;
101-
}
102-
}}
119+
(LNjScheme.Scheme.sym("ln-this"),
120+
this
103121
)));
104122

105123
LNjSchemeEvaluateNoSync
106124
(LNjScheme.Scheme.cons
107125
(LNjScheme.Scheme.sym("define"),
108126
LNjScheme.Scheme.list
109-
(LNjScheme.Scheme.sym("on-back-pressed"),
110-
new LNMethod("on-back-pressed") {
111-
public Object apply(LNjScheme.Scheme interpreter, Object args) {
112-
String str = null;
113-
if(args instanceof LNjScheme.Pair) {
114-
Object a1 = null;
115-
a1 = LNjScheme.Scheme.first(args);
116-
if(a1 instanceof LNjScheme.Procedure) { onBackPressedHandler = (LNjScheme.Procedure)a1; }
117-
else if(!LNjScheme.Scheme.truth(a1)) { onBackPressedHandler = null; }
118-
else { LNjScheme.Scheme.error("on-back-pressed: argument not a procedure or #f"); }
119-
return LNjScheme.Scheme.TRUE;
120-
} else {
121-
if(onBackPressedHandler==null) { return LNjScheme.Scheme.FALSE; }
122-
else { return onBackPressedHandler; }
123-
}
124-
}}
127+
(LNjScheme.Scheme.sym("ln-mglview"),
128+
mGLView
125129
)));
126130

127131
// eof: LNjScheme

modules/ln_jscheme/README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# LNjScheme
22

3-
This directory contains an app to demo how to use LNjScheme from LN.
4-
53
LNjScheme allows to call any Java/Android method from
64
lambdanative/gambit without additional JNI code. Either directly or
75
within the UI thread (dispatched asynchronously via `runOnUiThread`).
@@ -10,6 +8,34 @@ within the UI thread (dispatched asynchronously via `runOnUiThread`).
108

119
call `make -f Makefile` in this directory to create `android_jars/LNjScheme.jar`.
1210

11+
## Usage
12+
13+
### Procedures
14+
15+
#### (`android-app-class`)
16+
17+
Returns a *string* naming the Android application class.
18+
19+
#### (`lnjscheme-future` *OBJ*)
20+
21+
Returns a `promise` for an (asynchronous evaluated) result of *OBJ* -
22+
which must be a *S-expression* valid within jScheme.
23+
24+
This is the general way to call jScheme. The *S-expression* is
25+
evaluated via `runOnUiThread` in Android. The caller is expected to
26+
wait for the result in a Scheme thread. The calling procedure (i.e.,
27+
event handler) **MUST** return to allow Android to dispatch the
28+
request **before** the returned *promise* is `force`d.
29+
30+
#### (`call-with-lnjscheme-result` *OBJ* **[** *RECEIVER* **]**)
31+
32+
Send *OBJ* to jScheme for evaluation. *RECEIVER* is a 1ari procedure,
33+
`force`by default, expecting a *promise*, which is invoked (from
34+
another callback into lambdanative in the event loop) when the result
35+
is available.
36+
37+
NOTE: This is a low level procedure, which *MAY* change.
38+
1339
# History
1440

1541
LNjScheme is derived from the 1.4 version of
@@ -21,13 +47,16 @@ Jscheme version 1.4, the last version that I released (in April
2147
(NB: There is another thing going by the name Jscheme, which was
2248
extented by a community until 2006. This version grew beyond the
2349
features, complexity and size which make the Peter Norvigs version
24-
interesting as a strating point.)
50+
interesting as a starting point.)
2551

2652
Jscheme 1.4 however lacks a few features, notably the ability supply
2753
arguments to constructors. Therefore a derivative was required for
2854
LN. In accordance with the stated license for Jscheme it got a new
2955
name.
3056

57+
Jörg F. Wittenberger (a.k.a. 08/15 -- known als 0-8-15 on githug)
58+
initially added those features (C) 2019.
59+
3160
## Changes
3261

3362
1. Baseline: unpacked the sources from `jscheme-source.jar` into

modules/ln_jscheme/ln_jscheme.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ NULL;
7373
(promise (delay (jscheme-refine-result (jscheme-read-reply reply)))))
7474
;; The optional receiver MAY either dispatch to
7575
;; asynchroneous forcing the promise catching exceptions
76-
;; etc. by default force it expection the application to
76+
;; etc. by default force it expecting the application to
7777
;; abort on any exception.
7878
(receiver promise))))
7979
(jscheme-send (object->string obj))
Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1+
/* webview onCreate -*- mode: java; c-basic-offset: 2; -*- */
2+
13
LNjSchemeEvaluate
2-
(LNjScheme.Scheme.cons
3-
(LNjScheme.Scheme.sym("define"),
4-
LNjScheme.Scheme.list
5-
(LNjScheme.Scheme.sym("webview!"), SchemeWebView.proc())));
4+
(LNjScheme.Scheme.cons
5+
(LNjScheme.Scheme.sym("define"),
6+
LNjScheme.Scheme.list
7+
(LNjScheme.Scheme.sym("webview!"), SchemeWebView.proc())));
68

79
LNjSchemeEvaluate
8-
(LNjScheme.Scheme.cons
9-
(LNjScheme.Scheme.sym("define"),
10-
LNjScheme.Scheme.list
11-
(LNjScheme.Scheme.sym("make-webview"),
12-
new LNMethod("make-webview") {
13-
public Object apply(LNjScheme.Scheme interpreter, Object args) {
14-
if(args instanceof LNjScheme.Pair) {
15-
Object a1 = null;
16-
a1 = LNjScheme.Scheme.first(args);
17-
if(a1 instanceof android.content.Context) {
18-
return new SchemeWebView((android.content.Context)a1, LNjSchemeSession);
19-
}
20-
}
21-
return LNjScheme.Scheme.error("make-webview" + args);
22-
}}
23-
)));
10+
(LNjScheme.Scheme.cons
11+
(LNjScheme.Scheme.sym("define"),
12+
LNjScheme.Scheme.list
13+
(LNjScheme.Scheme.sym("make-webview"),
14+
new LNMethod("make-webview") {
15+
public Object apply(LNjScheme.Scheme interpreter, Object args) {
16+
if(args instanceof LNjScheme.Pair) {
17+
Object a1 = null;
18+
a1 = LNjScheme.Scheme.first(args);
19+
if(a1 instanceof android.content.Context) {
20+
return new SchemeWebView((android.content.Context)a1, LNjSchemeSession);
21+
}
22+
}
23+
return LNjScheme.Scheme.error("make-webview: " + args);
24+
}}
25+
)));
2426

2527
LNjSchemeEvaluate
2628
// Dummy
27-
(LNjScheme.Scheme.cons
28-
(LNjScheme.Scheme.sym("define"),
29-
LNjScheme.Scheme.list
30-
(LNjScheme.Scheme.sym("webview-set-proxy!"), LNjScheme.Scheme.sym("list"))));
29+
(LNjScheme.Scheme.cons
30+
(LNjScheme.Scheme.sym("define"),
31+
LNjScheme.Scheme.list
32+
(LNjScheme.Scheme.sym("webview-set-proxy!"), LNjScheme.Scheme.sym("list"))));
3133

3234
/*
3335
(lnjscheme-eval
@@ -40,3 +42,5 @@ LNjSchemeEvaluate
4042
(setProperty (String "https.ProxyHost") host)
4143
(setProperty (String "https.ProxyPort") port))))
4244
*/
45+
46+
/* EOF webview onCreate */

0 commit comments

Comments
 (0)