Getting a Java class from Function.execute (LispObject introspection)

Frederico Munoz fsmunoz at sdf.org
Tue Apr 25 10:57:17 UTC 2017


Hello,

Solved it help from ferada in the IRC channel, it's trivial now that I
look at it but I'll leave it here anyway, maybe it helps someone.

Frederico Munoz <fsmunoz at sdf.org> wrote:
> I have one doubt regarding LispObject (what we get from
> Function.execute): I have read some introspection in the manual but my
> use-case is slightly different since the I will use the return value of
> the Lisp call and that value is actually a Java class (from a
> non-standard library which I use) that will be the return value of the
> main method of the Main class.

Assuming somethins like this in the Lisp file:

---
(defun say-hello (&optional name)
  (let ((response (java:jnew "com.google.gson.JsonObject")))
      response))
---
... this works from the Java side:

---
LispObject result = voidFunction.execute(new JavaObject(thisObject));
JavaObject jo = ((JavaObject) result);
JsonObject json = ((JsonObject) jo.getObject());
json.addProperty("greet", "Hi!");
System.out.println(json.get("greet"));
// => "Hi!"
System.out.println("Class: "  + json.getClass().getName());
// => Class: com.google.gson.JsonObject
---

Best regards,
-- 
fsmunoz at sdf.org
SDF Public Access UNIX System - http://sdf.org



More information about the armedbear-devel mailing list