Working toward Java CFFI
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
<set name="lime" />
|
||||
|
||||
<define name="native" if="cpp || neko || nodejs || cs" />
|
||||
<define name="native" if="cpp || neko || nodejs || cs || java" />
|
||||
<define name="howlerjs" if="html5" />
|
||||
|
||||
<define name="lime-html5" if="html5" />
|
||||
@@ -52,7 +52,7 @@
|
||||
<ndll name="zlib" haxelib="hxcpp" unless="emscripten || ios || tvos" />
|
||||
</section>
|
||||
|
||||
<ndll name="lime" if="cpp || neko || nodejs" unless="lime-console" />
|
||||
<ndll name="lime" if="cpp || neko || nodejs || java" unless="lime-console" />
|
||||
|
||||
<dependency name="extension-api" path="dependencies/extension-api" if="android" />
|
||||
<dependency path="dependencies/howler.min.js" if="html5 howlerjs" />
|
||||
|
||||
@@ -93,6 +93,8 @@ class CFFI {
|
||||
|
||||
#if neko
|
||||
result = neko.Lib.loadLazy (library, method, args);
|
||||
#elseif java
|
||||
result = __loadJava (library, method, args);
|
||||
#elseif cpp
|
||||
result = cpp.Lib.loadLazy (library, method, args);
|
||||
#end
|
||||
@@ -105,7 +107,6 @@ class CFFI {
|
||||
return cpp.Lib.load (library, method, args);
|
||||
#end
|
||||
|
||||
|
||||
if (__moduleNames.exists (library)) {
|
||||
|
||||
#if cpp
|
||||
@@ -114,6 +115,8 @@ class CFFI {
|
||||
return neko.Lib.load (__moduleNames.get (library), method, args);
|
||||
#elseif nodejs
|
||||
return untyped __nodeNDLLModule.load_lib (__moduleNames.get (library), method, args);
|
||||
#elseif java
|
||||
result = __loadJava (__moduleNames.get (library), method, args);
|
||||
#elseif cs
|
||||
return untyped CSFunctionLoader.load (__moduleNames.get (library), method, args);
|
||||
#else
|
||||
@@ -131,7 +134,7 @@ class CFFI {
|
||||
#elseif nodejs
|
||||
if (__nodeNDLLModule == null) {
|
||||
|
||||
__nodeNDLLModule = untyped require('ndll');
|
||||
__nodeNDLLModule = untyped require ('ndll');
|
||||
|
||||
}
|
||||
#end
|
||||
@@ -279,6 +282,29 @@ class CFFI {
|
||||
}
|
||||
|
||||
|
||||
#if java
|
||||
private static var __loadedLibraries = new Map<String, Bool> ();
|
||||
private static function __loadJava (library:String, method:String, args:Int = 0) {
|
||||
|
||||
if (!__loadedLibraries.exists (library)) {
|
||||
|
||||
var extension = #if android ".so" #else ".ndll" #end;
|
||||
var path = Sys.getCwd () + "/" + library + extension;
|
||||
|
||||
java.lang.System.load (path);
|
||||
|
||||
__loadedLibraries.set (library, true);
|
||||
|
||||
trace ("load library: " + library);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
#if neko
|
||||
private static function __loadNekoAPI (lazy:Bool):Void {
|
||||
|
||||
@@ -345,6 +371,8 @@ class CFFI {
|
||||
var result = neko.Lib.load (name, func, args);
|
||||
#elseif nodejs
|
||||
var result = untyped __nodeNDLLModule.load_lib (name, func, args);
|
||||
#elseif java
|
||||
var result = __loadJava (name, func, args);
|
||||
#elseif cs
|
||||
var result = CSFunctionLoader.load (name, func, args);
|
||||
#else
|
||||
|
||||
@@ -6,6 +6,7 @@ import haxe.Template;
|
||||
import lime.tools.helpers.CPPHelper;
|
||||
import lime.tools.helpers.DeploymentHelper;
|
||||
import lime.tools.helpers.FileHelper;
|
||||
import lime.tools.helpers.JavaHelper;
|
||||
import lime.tools.helpers.LogHelper;
|
||||
import lime.tools.helpers.NekoHelper;
|
||||
import lime.tools.helpers.NodeJSHelper;
|
||||
@@ -14,6 +15,7 @@ import lime.tools.helpers.PlatformHelper;
|
||||
import lime.tools.helpers.ProcessHelper;
|
||||
import lime.project.AssetType;
|
||||
import lime.project.Architecture;
|
||||
import lime.project.Haxelib;
|
||||
import lime.project.HXProject;
|
||||
import lime.project.Platform;
|
||||
import lime.project.PlatformTarget;
|
||||
@@ -65,6 +67,10 @@ class LinuxPlatform extends PlatformTarget {
|
||||
|
||||
targetType = "nodejs";
|
||||
|
||||
} else if (project.targetFlags.exists ("java")) {
|
||||
|
||||
targetType = "java";
|
||||
|
||||
} else {
|
||||
|
||||
targetType = "cpp";
|
||||
@@ -127,6 +133,29 @@ class LinuxPlatform extends PlatformTarget {
|
||||
//NekoHelper.createExecutable (project.templatePaths, "linux" + (is64 ? "64" : ""), targetDirectory + "/obj/ApplicationMain.n", executablePath);
|
||||
NekoHelper.copyLibraries (project.templatePaths, "linux" + (is64 ? "64" : ""), applicationDirectory);
|
||||
|
||||
} else if (targetType == "java") {
|
||||
|
||||
var libPath = PathHelper.combine (PathHelper.getHaxelib (new Haxelib ("lime")), "templates/java/lib/");
|
||||
|
||||
ProcessHelper.runCommand ("", "haxe", [ hxml, "-java-lib", libPath + "disruptor.jar", "-java-lib", libPath + "lwjgl.jar" ]);
|
||||
//ProcessHelper.runCommand ("", "haxe", [ hxml ]);
|
||||
|
||||
if (noOutput) return;
|
||||
|
||||
var haxeVersion = project.environment.get ("haxe_ver");
|
||||
var haxeVersionString = "3404";
|
||||
|
||||
if (haxeVersion.length > 4) {
|
||||
|
||||
haxeVersionString = haxeVersion.charAt (0) + haxeVersion.charAt (2) + (haxeVersion.length == 5 ? "0" + haxeVersion.charAt (4) : haxeVersion.charAt (4) + haxeVersion.charAt (5));
|
||||
|
||||
}
|
||||
|
||||
ProcessHelper.runCommand (targetDirectory + "/obj", "haxelib", [ "run", "hxjava", "hxjava_build.txt", "--haxe-version", haxeVersionString ]);
|
||||
FileHelper.recursiveCopy (targetDirectory + "/obj/lib", PathHelper.combine (applicationDirectory, "lib"));
|
||||
FileHelper.copyFile (targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".jar", PathHelper.combine (applicationDirectory, project.app.file + ".jar"));
|
||||
JavaHelper.copyLibraries (project.templatePaths, "Linux" + (is64 ? "64" : ""), applicationDirectory);
|
||||
|
||||
} else {
|
||||
|
||||
var haxeArgs = [ hxml ];
|
||||
@@ -171,7 +200,7 @@ class LinuxPlatform extends PlatformTarget {
|
||||
|
||||
}
|
||||
|
||||
if (PlatformHelper.hostPlatform != Platform.WINDOWS && targetType != "nodejs") {
|
||||
if (PlatformHelper.hostPlatform != Platform.WINDOWS && (targetType != "nodejs" && targetType != "java")) {
|
||||
|
||||
ProcessHelper.runCommand ("", "chmod", [ "755", executablePath ]);
|
||||
|
||||
@@ -278,6 +307,10 @@ class LinuxPlatform extends PlatformTarget {
|
||||
|
||||
NodeJSHelper.run (project, targetDirectory + "/bin/ApplicationMain.js", arguments);
|
||||
|
||||
} else if (targetType == "java") {
|
||||
|
||||
ProcessHelper.runCommand (applicationDirectory, "java", [ "-jar", project.app.file + ".jar" ].concat (arguments));
|
||||
|
||||
} else if (project.target == PlatformHelper.hostPlatform) {
|
||||
|
||||
arguments = arguments.concat ([ "-livereload" ]);
|
||||
|
||||
Reference in New Issue
Block a user