v8pp, a header only library for C++ code binding into V8 JavaScript engine

240 views
Skip to first unread message

Pavel Medvedev

unread,
Feb 6, 2015, 1:58:53 AM2/6/15
to nod...@googlegroups.com
Hi there,

I have updated a new version of v8pp, a library to make bindings from C++ code into V8 JavaScript engine:


The new library version supports V8 versions after 3.28 with v8::Isolate usage in API. Now it doesn't depend on Boost libraries. Only modern C++ compiler is required, such as Visual C++ 2013, GCC 4.8, Clang.

v8pp might  be useful to create bindings in node.js and io.js addons:

int var;
int get_var() { return var + 1; }
void set_var(int x) { var = x + 1; }

struct X
{
    X
(int v, bool u) : var(v) {}

   
int var;

   
int get() const { return var; }
   
void set(int x) { var = x; }
};

void RegisterModule(v8::Handle<v8::Object> exports)
{
    v8pp
::module addon(v8::Isolate::GetCurrent());
   
    addon
       
// set read-only attribute
       
.set_const("PI", 3.1415)
       
// set variable available in JavaScript
       
.set("var", var)
       
// set function get_var as `fun`
       
.set("fun", &get_var)
       
// set property `prop` with getter get_var() and setter set_var()
       
.set("prop", property(get_var, set_var))
       
   
//  class bindings v8pp::class_<X> X_class(isolate);
    X_class
       
// specify X constructor signature
       
.ctor<int, bool>()
       
// bind variable
       
.set("var", &X::var)
       
// bind function
       
.set("fun", &X::set)
       
// bind read-only property
       
.set("prop", property(&X::get))
 
    addon
.set("X", X_class);

   
// set bindings as exports object prototype
    exports
->SetPrototype(addon.new_instance());
}

NODE_MODULE
(addon, RegisterModule)

Kevin Ingwersen (Ingwie Phoenix)

unread,
Feb 6, 2015, 1:24:00 PM2/6/15
to nod...@googlegroups.com
This is a very nice library! I think I know where I’ll use it. It’s ability to add require() to a v8 context is very useful.
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/c22e78cc-3d3f-467e-b82b-c5e84b000f5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pavel Medvedev

unread,
Feb 10, 2015, 1:23:38 PM2/10/15
to nod...@googlegroups.com
Added Node.js addon examples with difference to v8pp: https://github.com/pmed/v8pp/commit/34c6344bdb1bdf7f0b46db6ea15c8ddd20ac3824
Reply all
Reply to author
Forward
0 new messages