Permalink
Browse files

Added simple function example and relevant slides

  • Loading branch information...
1 parent 316ef59 commit e114e08e43f770851d341fa32eb3bf7b881c942e @nikhilm committed Jan 14, 2012
Showing with 81 additions and 0 deletions.
  1. +25 −0 simplefunctions/main.cc
  2. +13 −0 simplefunctions/wscript
  3. +43 −0 slides.rst
View
@@ -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)
+}
View
@@ -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"
View
@@ -96,3 +96,46 @@ Injecting primitives
:include: primitives/primitives.cc
+Templates
+---------
+
+* Creation of functions and objects in C++
+
+.. note::
+
+ Explain how they differ, what each is for and
+ whats the deal with FunctionTemplate && FunctionTemplate::GetFunction
+
+Simple functions
+----------------
+
+Registering with V8:
+
+.. code-block:: cpp
+ :include: simplefunctions/main.cc
+ :start-at: Handle<Value>
+ :end-before: {
+
+.. code-block:: cpp
+ :include: simplefunctions/main.cc
+ :start-at: static void
+ :end-before: NODE_MODULE
+
+TODO TODO TODO
+
+Simple functions
+----------------
+
+Implementation:
+
+.. code-block:: cpp
+ :include: simplefunctions/main.cc
+ :start-after: {
+ :end-before: }
+
+ObjectWrap
+----------
+
+TODO diagram of how the nesting happens of native object and v8 object
+
+MakeCallback

0 comments on commit e114e08

Please sign in to comment.