Advertisement
whitequark

Untitled

Apr 26th, 2011
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var hello_ruby = require('./hello_ruby');
  2. var ruby = hello_ruby.ruby;
  3.  
  4. ruby.define_class('NodeJSResponse');
  5.  
  6. ruby.define_method(ruby.c.NodeJSResponse, 'writeHead', 1, function(self, status) {
  7.   status = this.check_convert_type(status, this.c.Fixnum, 'to_i');
  8.   self.internal.writeHead(status, {'Content-Type': 'text/plain'});
  9. });
  10.  
  11. ruby.define_method(ruby.c.NodeJSResponse, 'write', 1, function(self, data) {
  12.   data = this.check_convert_type(data, this.c.String, 'to_s');
  13.   self.internal.write(data);
  14. });
  15.  
  16. ruby.define_method(ruby.c.NodeJSResponse, 'end', 0, function(self) {
  17.   self.internal.end();
  18. });
  19.  
  20. var http = require('http');
  21. http.createServer(function (req, res) {
  22.   var ruby_res = {
  23.     klass: ruby.c.NodeJSResponse,
  24.     internal: res,
  25.   };
  26.  
  27.   ruby.protect(function() {
  28.     var reply = ruby.funcall(ruby.toplevel, 'process_request', ruby_res);
  29.   }, function(e) {
  30.     console.log("Exception Occured: " + ruby.funcall(e, 'to_s'));
  31.   });
  32. }).listen(1337, "127.0.0.1");
  33.  
  34. console.log('Server running at http://127.0.0.1:1337/');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement