Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple function example and relevant slides
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
#include <v8.h> | |||
#include <node.h> | |||
using namespace v8; | |||
|
|||
Handle<Value> Square(const Arguments &args) { | |||
HandleScope scope; | |||
|
|||
int a = args[0]->Int32Value(); | |||
int sq = a * a; | |||
|
|||
return scope.Close(Integer::New(sq)); | |||
} | |||
|
|||
extern "C" { | |||
static void Init(Handle<Object> target) { | |||
HandleScope scope; | |||
|
|||
Handle<FunctionTemplate> squareTpl = | |||
FunctionTemplate::New(Square); | |||
|
|||
target->Set(String::New("square"), | |||
squareTpl->GetFunction()); | |||
} | |||
NODE_MODULE(simplefunctions, Init) | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 = "simplefunctions" | |||
obj.source = "main.cc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters