Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated

  • Loading branch information...
commit 1ab8699028a3d49b0e7ab932b0f544c64afe0d19 1 parent eb0c3ab
@tokuhirom authored
View
2  .gitignore
@@ -3,3 +3,5 @@ node_modules/
ya.js
foo.js
hoge.*
+core
+log
View
1  README.md
@@ -19,6 +19,7 @@ TODO
----
* write a node.js library in ruby, and export classes/functions as npm library.
+ * export mRuby's function/class to the node.js world?
* better diag for syntax error in node.js level
* inject object from node.js world to ruby world
* save a instance of NodeMRuby to NodeMRubyObject
View
5 author/expose-new-mruby.js
@@ -0,0 +1,5 @@
+var mRuby = require('../index.js');
+while (1) {
+ var mruby = new mRuby();
+ // global.gc();
+}
View
2  author/load-open-close.js
@@ -0,0 +1,2 @@
+var mruby = require('../build/Release/mruby.node');
+mruby.loadTestOpenClose();
View
6 eg/httpd.rb
@@ -0,0 +1,6 @@
+http = NodeJS.require('http')
+
+http.createServer {|req, res|
+ res.end("Oh!\n")
+}.listen(8124, '127.0.0.1')
+
View
25 src/mrb.cc
@@ -31,11 +31,13 @@ static mrb_value jsobj2ruby(mrb_state* mrb, Handle<Value> val);
struct NodeMRubyValueContainer {
Persistent<Value> v_;
- NodeMRubyValueContainer(Handle<Value> v) {
+ int type_;
+ NodeMRubyValueContainer(Handle<Value> v, int t) : type_(t) {
v_ = Persistent<Value>::New(v);
}
~NodeMRubyValueContainer() {
TRACE_DESTRUCTOR("NodeMRubyValueContainer");
+ std::cerr << "container type : " << type_ <<std::endl;
v_.Dispose();
v_.Clear();
}
@@ -143,20 +145,6 @@ class NodeMRubyFunction : ObjectWrap {
struct Callback {
mrb_value callback;
};
- inline void Wrap2 (v8::Handle<v8::Object> handle) {
- this->Wrap(handle);
- }
-
- /*
- static void Init(Handle<Object> target) {
- Local<FunctionTemplate> t = FunctionTemplate::New(NodeMRubyFunction::Call);
- constructor_template = Persistent<FunctionTemplate>::New(t);
- constructor_template->SetClassName(String::NewSymbol("mRubyFunction"));
-
- Local<ObjectTemplate> instance_template = constructor_template->InstanceTemplate();
- instance_template->SetInternalFieldCount(1);
- }
- */
static Handle<Value> Call(const Arguments& args) {
HandleScope scope;
@@ -501,11 +489,11 @@ inline static mrb_value jsobj2ruby(mrb_state* mrb, Handle<Value> val) {
return retval;
} else if (val->IsFunction()) {
struct RClass *c = reinterpret_cast<NodeMRubyUDContext*>(mrb->ud)->mruby_node_function_class();
- NodeMRubyValueContainer * vc = new NodeMRubyValueContainer(val);
+ NodeMRubyValueContainer * vc = new NodeMRubyValueContainer(val, 1);
return mrb_obj_value(Data_Wrap_Struct(mrb, c, &node_mruby_function_data_type, vc));
} else if (val->IsObject()) {
struct RClass *c = reinterpret_cast<NodeMRubyUDContext*>(mrb->ud)->mruby_node_object_class();
- NodeMRubyValueContainer * vc = new NodeMRubyValueContainer(val);
+ NodeMRubyValueContainer * vc = new NodeMRubyValueContainer(val, 2);
return mrb_obj_value(Data_Wrap_Struct(mrb, c, &node_mruby_function_data_type, vc));
} else if (val->IsInt32()) {
return mrb_fixnum_value(val->Int32Value());
@@ -651,6 +639,8 @@ static mrb_value node_function_call(mrb_state *mrb, mrb_value self) {
static Handle<Value> rubyproc2jsfunc(mrb_state*mrb, const mrb_value &v) {
HandleScope scope;
+ DBG("rubyproc2jsfunc");
+
// get a instance of NodeMRubyFunctionInner
Local<Value> arg0 = External::New(new NodeMRubyFunctionInner::Callback(mrb, v));
Local<Value> args[] = {arg0};
@@ -662,6 +652,7 @@ static Handle<Value> rubyproc2jsfunc(mrb_state*mrb, const mrb_value &v) {
instance_template->SetInternalFieldCount(1);
Local<Function> func = t->GetFunction();
func->Set(0, inner);
+ func->Set(1, mrb2nmrb(mrb));
return scope.Close(func);
}
View
4 src/nodeutil.h
@@ -69,6 +69,10 @@ inline static void jsobjdump(v8::Handle<v8::Value> val, int n=0) {
for (int i=0; i<n; i++) {
std::cerr << " ";
}
+ if (n>32) {
+ std::cerr << "too deep" << std::endl;
+ return;
+ }
if (val->IsTrue()) {
std::cerr << "true" << std::endl;
} else if (val->IsFalse()) {
Please sign in to comment.
Something went wrong with that request. Please try again.