https://sjbaker.org/wiki/index.php?title=GameTools_autogen_java&feed=atom&action=historyGameTools autogen java - Revision history2024-03-29T00:07:27ZRevision history for this page on the wikiMediaWiki 1.24.4https://sjbaker.org/wiki/index.php?title=GameTools_autogen_java&diff=68&oldid=prevSteveBaker: New page: The '''autogen''' tool converts the file 'lol/src/JavaInterface.jxx' into '''lol/src/JavaInterface.cxx''' and '''lol/src/GameInterface.java''' in order to automate the generation of Java b...2007-10-24T03:39:11Z<p>New page: The '''autogen''' tool converts the file 'lol/src/JavaInterface.jxx' into '''lol/src/JavaInterface.cxx''' and '''lol/src/GameInterface.java''' in order to automate the generation of Java b...</p>
<p><b>New page</b></p><div>The '''autogen''' tool converts the file 'lol/src/JavaInterface.jxx' into '''lol/src/JavaInterface.cxx''' and '''lol/src/GameInterface.java''' in order to automate the generation of Java bindings into the C game code. It's a bit of a hack - but it makes maintaining Java interfaces much easier than messing around with javah and/or swig.<br />
<br />
/u/games/tools/src/autogen_java JavaInterface.jxx<br />
<br />
...the tool is currently only ever run from within the '''lol/src/Makefile.am'''.<br />
<br />
The '''JavaInterface.jxx''' file uses a special syntax for function headers and accepts javadoc-formatted comments.<br />
<br />
Javadoc comments must start with '''/**''' (by itself on a line) and end with '''*/''' (by itself on a line). <br />
<br />
Function headers must be preceded by '''JAVAFUNC''' and must be all on one line (although they may have code on that same line). The type of the return result must be either '''void, int, char, uchar, bool, float''' or '''string'''. '''uchar''' gets turned into '''byte''' in Java, '''bool''' becomes '''boolean''' in Java, '''string''' causes code to be generated to convert from a Java '''String''' into a C '''const char *'''.<br />
<br />
eg:<br />
<br />
/**<br />
* Does the specified object/flag/camers exist in this game level?<br />
*<br />
* @param name the name you are looking for<br />
* @return 'true' if it exists, 'false' if it doesn't.<br />
*/<br />
JAVAFUNC bool objectExists ( string name )<br />
{<br />
return findObject ( name ) != NULL ;<br />
}<br />
<br />
...becomes (in C ):<br />
<br />
/*******************JAVA INTERFACE JUNK ************************/<br />
bool objectExists ( string name ) ; extern "C" JNIEXPORT jboolean JNICALL Java_<br />
javaLoL_GameInterface_objectExists ( JNIEnv *env, jobject _jobj, jstring name<br />
){ string C0 = env -> GetStringUTFChars ( name, false ) ; jboolean ret = (jbo<br />
olean) objectExists ( C0 ) ; env -> ReleaseStringUTFChars ( name, C0 ) ; retu<br />
rn ret ;}<br />
/***************************************************************/<br />
<br />
bool objectExists ( string name ) {<br />
return findObject ( name ) != NULL ;<br />
}<br />
<br />
...and in Java:<br />
<br />
/**<br />
* Does the specified object/flag/camers exist in this game level?<br />
*<br />
* @param name the name you are looking for<br />
* @return 'true' if it exists, 'false' if it doesn't.<br />
*/<br />
public native boolean objectExists ( String name ) ;<br />
<br />
...running javadoc on the result produces the Java API function documentation: [http://www.sjbaker.org/games/lol/plugins/javaLoL/GameInterface.html GameInterface API ] and [http://www.sjbaker.org/games/lol/plugins/index-all.html Alphabetical Index ]<br />
<br />
{{gameTools}}<br />
{{LoL}}</div>SteveBaker