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

Frederico Munoz <[email protected]>
Newsgroups gmane.editors.j.devel
Message-ID <[email protected]>
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 <[email protected]> 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,
-- 
[email protected]
SDF Public Access UNIX System - http://sdf.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.