Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added calljs example
  • Loading branch information
nikhilm committed Jan 20, 2012
1 parent 67c6ae7 commit e566173
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 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)
}
8 changes: 8 additions & 0 deletions 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);
13 changes: 13 additions & 0 deletions 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"

0 comments on commit e566173

Please sign in to comment.