diff --git a/hxSerial/Serial.hx b/hxSerial/Serial.hx index 7b13da4..843a0b4 100644 --- a/hxSerial/Serial.hx +++ b/hxSerial/Serial.hx @@ -2,6 +2,7 @@ package hxSerial; #if neko import neko.Lib; +import neko.vm.Loader; #elseif cpp import cpp.Lib; #end @@ -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 } } @@ -88,6 +127,20 @@ class Serial { private var handle:Null; 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); @@ -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 } diff --git a/ndll/Windows64/hxSerial.ndll b/ndll/Windows64/hxSerial.ndll new file mode 100644 index 0000000..25b5a15 Binary files /dev/null and b/ndll/Windows64/hxSerial.ndll differ