Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map js Object to struct in V8

Tags:

javascript

v8

First shot at V8, trying to get a js object cast to a c++ struct and cannot find more info on the web.

lets say I have:

    var brush = {
        r:255,
        g:255,
        b:255,
        a:255
    }

and I want to pass it to a function accepting a struct like the following:

struct brush{
  int r;
  int g;
  int b;
  int a;
} ;

How should I go about maping this?

like image 463
Jmorvan Avatar asked Apr 29 '26 20:04

Jmorvan


1 Answers

Got a solution but i must say V8 is not well documented IMHO!

v8::Local<v8::Object> options(args[i]->ToObject());
int r = (options->Has(v8::String::NewSymbol("red")) ? (float)options->Get(v8::String::NewSymbol("red"))->IntegerValue() : 0);
like image 129
Jmorvan Avatar answered May 01 '26 11:05

Jmorvan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!