From c89d66563d543d834511be2187881e39fb03bd11 Mon Sep 17 00:00:00 2001 From: ritchie Date: Thu, 24 May 2012 22:52:00 -0400 Subject: [PATCH] some tweaks to compile with NME client --- cloudshift/Core.hx | 4 ++-- cloudshift/Mixin.hx | 20 ++++++++++++++++++++ cloudshift/Sys.hx | 3 ++- cloudshift/core/LogImpl.hx | 7 ++++++- cloudshift/http/RemoteImpl.hx | 3 ++- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cloudshift/Core.hx b/cloudshift/Core.hx index 3f4b684..c73355d 100644 --- a/cloudshift/Core.hx +++ b/cloudshift/Core.hx @@ -183,12 +183,12 @@ class Core { public static function parse(str:String):Dynamic { - return untyped __js__("JSON.parse(str)"); + return haxe.Json.parse(str); } public static function stringify(obj:Dynamic):String { - return untyped __js__("JSON.stringify(obj)"); + return haxe.Json.stringify(obj); } public static diff --git a/cloudshift/Mixin.hx b/cloudshift/Mixin.hx index 0bd2a34..4282d6c 100644 --- a/cloudshift/Mixin.hx +++ b/cloudshift/Mixin.hx @@ -33,7 +33,11 @@ class DynamicX { public static function stringify(o:Dynamic):String { + #if js return untyped __js__("JSON.stringify(o)"); + #else + return Std.string(o); + #end } } @@ -186,12 +190,20 @@ class StringX { public static function parse(str:String):Dynamic { + #if js return untyped __js__("JSON.parse(str)"); + #else + return haxe.Json.parse(str); + #end } public static inline function clone(o:Dynamic):Dynamic { + #if js return untyped __js__("JSON.parse(JSON.stringify(o))"); + #else + return haxe.Json.parse(haxe.Json.stringify(o)); + #end } inline static public function @@ -225,7 +237,11 @@ class DateX { } public static function UTCString(d:Date) : String { + #if js return untyped __js__("d.toUTCString()"); + #else + return Std.string(d); + #end } } @@ -233,7 +249,11 @@ class ArrayX { public static function stringify(a:Array):String { + #if js return untyped __js__("JSON.stringify(o)"); + #else + return Std.string(a); + #end } diff --git a/cloudshift/Sys.hx b/cloudshift/Sys.hx index bc0b0c4..823cea3 100644 --- a/cloudshift/Sys.hx +++ b/cloudshift/Sys.hx @@ -32,7 +32,8 @@ enum SysWriteStreamEvents { enum SysReadStreamEvents { Data(d:String); Error(e:String); - End; + + End; Close; Fd; } diff --git a/cloudshift/core/LogImpl.hx b/cloudshift/core/LogImpl.hx index c88d6d3..95593d9 100644 --- a/cloudshift/core/LogImpl.hx +++ b/cloudshift/core/LogImpl.hx @@ -47,8 +47,11 @@ class LogImpl { var b = new NodeBuffer(msg+"\n",NodeC.UTF8); Node.fs.write(logFileFD,b,0,b.length,null); } - else + else { + #if js untyped __js__("console.log(msg)"); + #end + } } } @@ -56,6 +59,7 @@ class LogImpl { static function write(msg,type) { + #if js if (msg != null) switch(type) { case "info": @@ -69,6 +73,7 @@ class LogImpl { default: untyped __js__("console.log(msg)"); } + #end } #end diff --git a/cloudshift/http/RemoteImpl.hx b/cloudshift/http/RemoteImpl.hx index ad5f05a..8009a60 100644 --- a/cloudshift/http/RemoteImpl.hx +++ b/cloudshift/http/RemoteImpl.hx @@ -12,7 +12,8 @@ class RemoteImpl extends Context, implements RemoteProvider { public function httpHandler(re:EReg,req:NodeHttpServerReq,resp:NodeHttpServerResp) { if(Reflect.field(req.headers,"x-haxe-remoting") == null){ - resp.end("bad request"); + resp.end("bad remoting request"); + return; } HttpImpl.parseFields(req,function(flds,optFiles) {