java interop has been improved
This commit is contained in:
parent
f3ac693da3
commit
bf21c741ec
2
Makefile
2
Makefile
|
@ -1,2 +1,4 @@
|
|||
repl:
|
||||
gradle compileJava && rlwrap java -cp build/classes/java/main/ serene.simple.Main
|
||||
docs:
|
||||
npx docco src/**/*.java
|
||||
|
|
|
@ -89,14 +89,14 @@ public class ListNode<T extends Node> extends Node implements Iterable<T> {
|
|||
return this.evalInteropProperty(
|
||||
scope,
|
||||
target,
|
||||
mName.substring(1, firstElement.name.length()));
|
||||
mName.substring(1, mName.length()));
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(target.getClass().getName());
|
||||
Method f = target.getClass().getMethod(mName);
|
||||
return f.invoke(target, rest.toArray());
|
||||
}
|
||||
|
||||
catch(NoSuchMethodException e) {
|
||||
throw new SereneException(
|
||||
String.format(
|
||||
|
@ -119,8 +119,9 @@ public class ListNode<T extends Node> extends Node implements Iterable<T> {
|
|||
|
||||
public Object evalInteropProperty(BaseScope scope, Object target, String propertyName)
|
||||
throws SereneException {
|
||||
|
||||
try {
|
||||
Class<?> targetClass = target.getClass();
|
||||
Class<?> targetClass = this.getClassOf(target);
|
||||
return targetClass.getField(propertyName);
|
||||
}
|
||||
catch(NoSuchFieldException e) {
|
||||
|
@ -186,4 +187,12 @@ public class ListNode<T extends Node> extends Node implements Iterable<T> {
|
|||
|
||||
return output + ")";
|
||||
}
|
||||
|
||||
private Class<?> getClassOf(Object target) {
|
||||
if (target instanceof Class) {
|
||||
return (Class<?>) target;
|
||||
}
|
||||
|
||||
return target.getClass();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@ public class RootScope extends BaseScope {
|
|||
put("println", new PrintlnFn());
|
||||
put("quit", new QuitFn());
|
||||
put("+", new PlusFn());
|
||||
put("System", System.class);
|
||||
put("Boolean", Boolean.class);
|
||||
put("String", String.class);
|
||||
}};
|
||||
// "+", PlusFn,
|
||||
// "-", MinusFn,
|
||||
|
|
Loading…
Reference in New Issue