Great idea Oleg, I'm not familiar with JCP, how should we begin this project? I'll try to schedule the first steps for next week.
On Mon, Apr 7, 2008 at 2:19 PM, Oleg Kobchenko <[EMAIL PROTECTED]> wrote: > > It seems difficult that there isn't a Java API available, considering > > there is a Java front-end to J. Do we really need to write this kind > > of code, or am I missing something? > > There should be Java API which everyone will use thereafter, > but it does not exist yet. There is the pair DLL/jar for J/JNI > but it only has a few basic functions just sufficient to > implement wd interface; when full API is available it makes > sence to merge it into this JNI library. > > It's a good opportunity that you are in position to need it > and can contribute to this effort. So you are on the right track. > I suggest this be done as a community process (as JCP) and we can > use Wiki to organize the space. We will need things like requirements, > specs, implementation approach and the code itself can be placed there. > > Although it may sound like a big deal and lengthy process, > it could be phased into parts and first usable prototype > can be done very fast. > > Literate can be used to produce a full build-able zip. > For some ideas (needs updating for j602), see > http://www.jsoftware.com/jwiki/System/Beta/Java_Hardware_OpenGL > esp. JayOpenGL2_win/JayJNI > > The mapping of J API (as in COM interface) into JNI is trivial. > What is more challenging is Get/Set functions which map > native-J and J-native data structures: Variant for COM, and > will need Java for JNI. > > This could a basis for high-level J-Java integration: > http://www.jsoftware.com/pipermail/chat/2008-March/001008.html > > > > > --- Jorge Arredondo <[EMAIL PROTECTED]> wrote: > > > I've started writing a J to Java interface and realized the following > > steps needed to be implemented: > > - Create C wrapper functions to expose J methods through JNI. > > - Create a Java wrapper class to call those JNI methods. > > > > Then, the methods of the wrapper class should be called in the following > order: > > - JInit - creates the J instance > > - J method(s) > > - JFree - destroys the J instance (no more methods are going to be called). > > > > > > So, in order to call "JDo", I had to write the following code: > > === C code ============================================================= > > #include "j_jwrapper.h" > > #include <windows.h> > > BOOL APIENTRY DllMain(HANDLE hInst, DWORD reason, LPVOID reserved){ > > return TRUE; } > > > > #define JCALL(Method) long (CALLBACK* j_##Method) > > > > JCALL(Init)(void); > > JCALL(Free)(long jh); > > JCALL(Do)(long jh, const char *cmd); > > > > HMODULE jdll= NULL; > > > > JNIEXPORT jint JNICALL Java_j_JWrapper_JInit(JNIEnv *env, jobject this) > > { > > jdll = LoadLibrary("j.dll"); > > if (!jdll) > > return 0; > > *(FARPROC*)&j_Init = GetProcAddress(jdll, "JInit"); > > *(FARPROC*)&j_Free = GetProcAddress(jdll, "JFree"); > > *(FARPROC*)&j_Do = GetProcAddress(jdll, "JDo"); > > return j_Init(); > > } > > > > JNIEXPORT jint JNICALL Java_j_JWrapper_JDo(JNIEnv *env, jobject this, > > jint j, jstring cmd) > > { > > const char *pcmd = (*env)->GetStringUTFChars(env, cmd, JNI_FALSE); > > jint ec = jdll_Do(j, pcmd); > > (*env)->ReleaseStringUTFChars(env, cmd, pcmd); > > return ec; > > } > > > > JNIEXPORT jint JNICALL Java_j_JWrapper_JFree(JNIEnv *env, jobject this, > jint jh) > > { > > jint ec = j_Free(jh); > > FreeLibrary(jdll); > > return ec; > > } > > > > === Java wrapper ======================================================= > > package j; > > > > public class JWrapper { > > private int jh = 0; > > static {System.loadLibrary("JayJNI");} > > > > native int JInit(); > > native int JFree(int jh); > > native int JDo(int jh, String cmd); > > > > public JWrapper() {} > > > > public Init() throws Exception { > > jh = JInit(); > > if (jh == 0) { throw new Exception("J DLL could not be > loaded."); } > > } > > > > public int Free() { > > return JFree(jh); > > } > > > > public void Do(String cmd) throws Exception { > > int ec = JDo(jh, cmd); > > if (ec != 0) { throw new Exception("JDo failed with code: > "+ec); } > > } > > } > > > > === Usage ============================================================== > > JWrapper J = new JWrapper(); > > J.Init(); > > J.Do("'hello'(1!:2)<'out.txt'"); > > J.Free(); > > ======================================================================== > > > > It seems difficult that there isn't a Java API available, considering > > there is a Java front-end to J. Do we really need to write this kind > > of code, or am I missing something? > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > > > > > ____________________________________________________________________________________ > You rock. That's why Blockbuster's offering you one month of Blockbuster > Total Access, No Cost. > http://tc.deals.yahoo.com/tc/blockbuster/text5.com > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
