Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added calljs example

  • Loading branch information...
commit e566173a5faec79761031e1769433639f2897b2a 1 parent 67c6ae7
@nikhilm authored
Showing with 49 additions and 0 deletions.
  1. +28 −0 calljs/main.cc
  2. +8 −0 calljs/test.js
  3. +13 −0 calljs/wscript
View
28 calljs/main.cc
@@ -0,0 +1,28 @@
+#include <v8.h>
+#include <node.h>
+using namespace v8;
+
+Handle<Value> Apply(const Arguments &args) {
+ HandleScope scope;
+
+ Handle<Function> func = Handle<Function>::Cast(args[0]);
+ Handle<Object> receiver = args[1]->ToObject();
+
+ Handle<Value> *argv = new Handle<Value>[args.Length() - 2];
+ for (int i = 2; i < args.Length(); i++)
+ argv[i-2] = args[i];
+
+ func->Call(receiver, args.Length()-2, argv);
+
+ delete argv;
+ return Undefined();
+}
+
+extern "C" {
+ static void Init(Handle<Object> target) {
+ HandleScope scope;
+
+ NODE_SET_METHOD(target, "apply", Apply);
+ }
+ NODE_MODULE(calljs, Init)
+}
View
8 calljs/test.js
@@ -0,0 +1,8 @@
+var calljs = require("./build/Release/calljs")
+
+var f = function() {
+ console.log("This", this);
+ console.log(arguments);
+}
+
+calljs.apply(f, { cool: "dude" }, "one", 2, 3.14);
View
13 calljs/wscript
@@ -0,0 +1,13 @@
+import Options
+
+def set_options(opt):
+ opt.tool_options("compiler_cxx")
+
+def configure(conf):
+ conf.check_tool("compiler_cxx")
+ conf.check_tool("node_addon")
+
+def build(bld):
+ obj = bld.new_task_gen("cxx", "shlib", "node_addon")
+ obj.target = "calljs"
+ obj.source = "main.cc"
Please sign in to comment.
Something went wrong with that request. Please try again.