Skip to content
Browse files

add Console

update examples
  • Loading branch information...
1 parent 5f7a80c commit 0b3b97eddcf39a9838e236c246597ca91ee946b4 @cloudshift committed May 6, 2011
Showing with 52 additions and 41 deletions.
  1. +1 −2 Ex1.hx
  2. +9 −10 Ex2.hx
  3. +42 −29 js/Node.hx
View
3 Ex1.hx
@@ -6,8 +6,7 @@ class Ex1 {
trace(Node.process.memoryUsage());
trace(Node.process.memoryUsage().heapTotal);
- var dns = Node.dns();
- dns.resolve("ipowerhouse.com","A",function(err,ips:Array<Dynamic>) {
+ Node.dns.resolve("ipowerhouse.com","A",function(err,ips:Array<Dynamic>) {
trace(ips);
});
}
View
19 Ex2.hx
@@ -16,9 +16,9 @@ class Ex2 {
public static function
tcpTest() {
- var tcp:Net = Node.net;
+ var tcp = Node.net;
- var s = tcp.createServer(function(c:Stream) {
+ var s = tcp.createServer(function(c) {
c.addListener('connect',function(d) {
trace("got connection");
c.write("hello\r\n");
@@ -41,9 +41,9 @@ class Ex2 {
public static function
flashCrossDomain() {
- var tcp:Net = Node.require("net");
+ var tcp = Node.net;
- var s = tcp.createServer(function(c:Stream) {
+ var s = tcp.createServer(function(c) {
c.addListener('connect',function(d) {
c.write('<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
@@ -69,18 +69,17 @@ class Ex2 {
static function
clientTest() {
var
- sys:NodeSys = Node.require("sys"),
- http:Http = Node.require("http"),
+ console = Node.console,
+ http = Node.http,
google = http.createClient(80, "www.google.cl"),
request = google.request("GET","/", {host: "www.google.cl"});
request.addListener('response',function (response) {
- sys.puts("STATUS: " + response.statusCode);
- sys.puts("HEADERS: " + Node.stringify(response.headers));
- response.setBodyEncoding("utf8");
+ console.log("STATUS: " + response.statusCode);
+ console.log("HEADERS: " + Node.stringify(response.headers));
response.addListener("data", function (chunk) {
- sys.puts("BODY: " + chunk);
+ console.log("BODY: " + chunk);
});
});
View
71 js/Node.hx
@@ -26,10 +26,10 @@ typedef NodeEventEmitter = {
typedef NodeWatchOpt = {persistant:Bool,interval:Int};
typedef NodeExecOpt = {
- var encoding:String;
- var timeout:Int;
- var maxBuffer:Int;
- var killSignal:String;
+ var encoding:String;
+ var timeout:Int;
+ var maxBuffer:Int;
+ var killSignal:String;
var env:Dynamic;
var cwd:String;
}
@@ -41,6 +41,18 @@ typedef NodeSpawnOpt = {
var setsid:Bool;
}
+typedef NodeConsole = {
+ function log(s:String,?args:Dynamic):Void;
+ function info(s:String,?args:Dynamic):Void;
+ function warn(s:String,?args:Dynamic):Void;
+ function error(s:String,?args:Dynamic):Void;
+ function time(label:String):Void;
+ function timeEnd(label:String):Void;
+ function dir(obj:Dynamic):Void;
+ function trace():Void;
+ function assert():Void;
+}
+
/* 0.4.1
*/
typedef NodePath = {
@@ -301,7 +313,7 @@ typedef NodeChildProcess = { > NodeEventEmitter,
var stderr:NodeReadStream;
function kill(signal:String):Void;
function spawn(command: String,args: Array<String>,?options: Dynamic ): Void;
- function exec(command: String,?options:Dynamic,cb: {code:Int}->String->String->Void ): Void;
+ function exec(command: String,?options:Dynamic,cb: {code:Int}->String->String->Void ): Void;
}
@@ -645,25 +657,26 @@ class Node {
public static inline var FILE_READWRITE_APPEND = "a+";
public static var require(default,null) : String->Dynamic;
- public static var querystring(default,null) : NodeQueryString;
- public static var util(default,null) : NodeUtil;
- public static var fs(default,null) : NodeFS;
- public static var dgram(default,null) :NodeUDP ;
- public static var net(default,null) : NodeNet;
- public static var os(default,null) : NodeOs;
- public static var http(default,null) : NodeHttp;
- public static var https(default,null) : NodeHttps;
- public static var path(default,null) : NodePath;
- public static var url(default,null) : NodeUrl;
- public static var dns(default,null) : NodeDns;
- public static var vm(default,null) : NodeVM;
- public static var process(default,null) : NodeProcess;
- public static var tty(default,null) : NodeTTY;
- public static var assert(default,null) : NodeAssert;
- public static var crypto(default,null) : NodeCrypto;
- public static var tls(default,null) : NodeTLS;
- public static var repl(default,null) : NodeREPL;
+ public static var querystring(default,null) : NodeQueryString;
+ public static var util(default,null) : NodeUtil;
+ public static var fs(default,null) : NodeFS;
+ public static var dgram(default,null) :NodeUDP ;
+ public static var net(default,null) : NodeNet;
+ public static var os(default,null) : NodeOs;
+ public static var http(default,null) : NodeHttp;
+ public static var https(default,null) : NodeHttps;
+ public static var path(default,null) : NodePath;
+ public static var url(default,null) : NodeUrl;
+ public static var dns(default,null) : NodeDns;
+ public static var vm(default,null) : NodeVM;
+ public static var process(default,null) : NodeProcess;
+ public static var tty(default,null) : NodeTTY;
+ public static var assert(default,null) : NodeAssert;
+ public static var crypto(default,null) : NodeCrypto;
+ public static var tls(default,null) : NodeTLS;
+ public static var repl(default,null) : NodeREPL;
public static var childProcess(default,null) : NodeChildProcess;
+ public static var console(default,null) : NodeConsole;
public static var paths:String;
@@ -702,7 +715,11 @@ class Node {
global = untyped __js__('global');
process = untyped __js__('process');
require = untyped __js__('require');
-
+ console = untyped __js__('console');
+ module = untyped __js__('module'); // ref to the current module
+ stringify = untyped __js__('JSON.stringify');
+ parse = untyped __js__('JSON.parse');
+
// just load everything, maybe not to everyone's taste
util = require("util");
fs = require("fs");
@@ -722,14 +739,10 @@ class Node {
dgram = require('dgram');
assert = require('assert');
repl = require('repl');
-
+
var b:Dynamic = require("buffer");
untyped js.Buffer = b.Buffer;
- module = untyped __js__('module'); // ref to the current module
- stringify = untyped __js__('JSON.stringify');
- parse = untyped __js__('JSON.parse');
-
}
}

0 comments on commit 0b3b97e

Please sign in to comment.
Something went wrong with that request. Please try again.