Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32bit / 64bit fix #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 65 additions & 10 deletions hxSerial/Serial.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hxSerial;

#if neko
import neko.Lib;
import neko.vm.Loader;
#elseif cpp
import cpp.Lib;
#end
Expand All @@ -18,15 +19,53 @@ class Serial {
if (!isInit)
{
isInit = true;
var initNeko = Lib.loadLazy("hxSerial","neko_init",5);
if (initNeko != null)
initNeko(
function(s) return new String(s),
function(len:Int) { var r = []; if (len > 0) r[len - 1] = null; return r; },
null, true, false
);
else
trace("Could not init neko api for hxSerial");

#if neko

function tryLoadNeko() {
var initNeko = Lib.loadLazy("hxSerial", "neko_init", 5);
if (initNeko != null)
initNeko(
function(s) return new String(s),
function(len:Int) { var r = []; if (len > 0) r[len - 1] = null; return r; },
null, true, false
);
else
trace("Could not init neko api for hxSerial");
}

try {
tryLoadNeko();
} catch (e:Dynamic) {
// we've tried to load neko ndll, it didnt work, less assume its because
// it was 32bit and we want 64bit, lets add the 64bit path to loader (based
// on current loader path) and try again, if it works, we'll load all the
// functions, if it doesnt, something else went wrong and the initial failure
// was probably valid
for (p in Loader.local().getPath()) {
p = haxe.io.Path.normalize(p);
if (p.indexOf("/" + Sys.systemName()) != -1) {
var parts = p.split("/");
parts.pop();
parts.push(Sys.systemName() + "64");
Loader.local().addPath(parts.join("/") + "/");
}
}
tryLoadNeko();
}

// now we should have the correct .ndll
_enumerateDevices = Lib.load("hxSerial","enumerateDevices",0);
_setup = Lib.load("hxSerial","setup",2);
_writeBytes = Lib.load("hxSerial","writeBytes",3);
_readBytes = Lib.load("hxSerial","readBytes",2);
_writeByte = Lib.load("hxSerial","writeByte",2);
_readByte = Lib.load("hxSerial","readByte",1);
_flush = Lib.load("hxSerial","flush",3);
_available = Lib.load("hxSerial","available",1);
_breakdown = Lib.load("hxSerial","breakdown",1);

#end
}
}

Expand Down Expand Up @@ -88,6 +127,20 @@ class Serial {
private var handle:Null<Int>;
private static var isInit = #if neko false #else true #end ;

#if neko // load neko differently now!

private static var _enumerateDevices = null;
private static var _setup = null;
private static var _writeBytes = null;
private static var _readBytes = null;
private static var _writeByte = null;
private static var _readByte = null;
private static var _flush = null;
private static var _available = null;
private static var _breakdown = null;

#else

private static var _enumerateDevices = Lib.load("hxSerial","enumerateDevices",0);
private static var _setup = Lib.load("hxSerial","setup",2);
private static var _writeBytes = Lib.load("hxSerial","writeBytes",3);
Expand All @@ -96,5 +149,7 @@ class Serial {
private static var _readByte = Lib.load("hxSerial","readByte",1);
private static var _flush = Lib.load("hxSerial","flush",3);
private static var _available = Lib.load("hxSerial","available",1);
private static var _breakdown = Lib.load("hxSerial","breakdown",1);
private static var _breakdown = Lib.load("hxSerial", "breakdown", 1);

#end
}
Binary file added ndll/Windows64/hxSerial.ndll
Binary file not shown.