Best way to do Extern functions...
Monkey Forums/Monkey Programming/Best way to do Extern functions...
| ||
Diddy's external functions are getting pretty big now and its a bit of a pain to add empty stubs to targets which does not support a function. Currently we have got the following: functions.monkey #if HOST="macos" And TARGET="glfw" Import "native/diddy.${TARGET}.mac.${LANG}" #else Import "native/diddy.${TARGET}.${LANG}" #end Extern #If LANG="cpp" Then Function RealMillisecs:Int() = "diddy::systemMillisecs" #Else Function RealMillisecs:Int() = "diddy.systemMillisecs" #End Public diddy.android.java class diddy { static int systemMillisecs() { int ms = (int)System.currentTimeMillis(); return ms; } } diddy.glfw.cpp #include <time.h> #include <Shellapi.h> class diddy { public: // only accurate to 1 second static int systemMillisecs() { time_t seconds; seconds = time (NULL); return seconds * 1000; } } etc Is there a better way? I've looked in the mojo app file and tried to do it in a similar way with a class for the extern, but it would mean I would have to instantiate the functions class and call the methods within that class, which I dont want to do - I just want to call this function: RealMillisecs() |
| ||
In Monkey itself...Import "native/myfile.${TARGET}.${LANG}" Extern Class MonkeyClass="nativeClass" Method Method1() Method Method2() End Function CallMethod1() MonkeyClass.Method1() End Then in the native code (java for example): class nativeClass{ float var1; void Method1(){ DoSomething(); } //etc... } EDIT: Sorry, finally read the bottom part... but I don't see a way around it personally, unless you bock out each language as it's own separate file and use the preprocessor commands in them, then having a main file that imports each language as needed. |