Re: Unwrapping Java Character to char
Mark Evenson <[email protected]> Thu, 4 Jan 2024 12:11:17 +0100
| Newsgroups | gmane.editors.j.devel |
|---|---|
| Message-ID | <24EC384C-D5A0-41F6-B201-94E4D49764E0__20455.0305543066$1704366734$gmane$org@panix.com> |
> On Jan 3, 2024, at 23:49, Robert Dodier <[email protected]> = wrote: >=20 > Hi Blake, thanks for your reply. >=20 > I actually don't need to convert to ASCII -- what I really want to do > is to call a Java method which has a char argument. I got the > following error: >=20 > CL-USER(19): (jss:new "org.armedbear.lisp.LispCharacter" #\U2502) > #<THREAD "interpreter" native {41BFB5BC}>: Debugger invoked on > condition of type JAVA-EXCEPTION > Java exception 'java.lang.NoSuchMethodException: > LispCharacter(java.lang.Character)'. Do you need to 1) call an arbitrary Java method with a char argument, or 2) just programmatically call the org.armedbear.lisp.LispCharacter constructor to get a Lisp character? For 1) calling arbitrary Java methods, one should be able to use JSS to do the following: (#0"charValue" (#"valueOf" 'java.lang.Character #\U2502)) The #0 returns the raw value of the method invocation without attempting to convert through the Lisp/Java FFI. For 2) why can=E2=80=99t you use CODE-CHAR =20 (char-code #\U2502) =3D> 9474 (code-char 9474)=20 =3D>#\=E2=94=82 > It appears that the Lisp character #\U2502 has been converted to a > Java Character, but that's not acceptable to the > org.armedbear.lisp.LispCharacter constructor, which is declared to > take a char argument; see line 70 of > src/org/armedbear/lisp/LispCharacter.java in the current version > (commit bba779e). Indeed it does change back to a java.lang.Character instance, even when I use the method to return the raw Java type. I cant figure out a way to coerce calling arguments to a primitive char. Maybe I haven't found the right invocation yet, but otherwise we will have to fix the implementation. >=20 > Now a complicating factor is that the LispCharacter(char) constructor > is declared private -- I don't know if that's the actual problem, and > the error message about the argument type is misleading. Are Java > private methods, variables, and constructors visible from Lisp? JSS:NEW should be able to invoke private constructors. That is one of the features which distinguishes it from JAVA:JNEW. --=20 "A screaming comes across the sky. It has happened before but there is = nothing=20 to compare to it now."