[v8-users] call javascript function from c++

2018-06-06 Thread Robert Nick
Basically I want to:
v8::Script::Run
v8::Script::Compile

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] call javascript function from c++

2018-06-06 Thread Joe Smack
Yes, the examples are horribly written and hard to understand. 

And I don't believe any of them covered this:

// get the function
v8::Local global = context->Global();
v8::Local function_value1 = 
global->Get(v8::String::NewFromUtf8(isolate, "StartNamespace"));
v8::Local a = v8::Local::Cast(function_value1);
v8::Local function_value2 = 
a->Get(v8::String::NewFromUtf8(isolate, "cppTalkTo"));
v8::Local function1 = 
v8::Local::Cast(function_value2);

// call it
v8::Local js_result1;
js_result1 = function1->Call(context, global, 0, nullptr).ToLocalChecked();

Unless there is a better way, please consider my original post answered.


On Wednesday, June 6, 2018 at 3:07:33 AM UTC-7, Ben Noordhuis wrote:
>
> On Wed, Jun 6, 2018 at 11:42 AM, Joe Smack  > wrote: 
> > Let's say you compile and run code: 
> > 
> > var StartNamespace = 
> > { 
> >  cppTalkTo: function () { 
> >   // some code 
> > } 
> > }; 
> > StartNamespace.init(); 
> > 
> > After you compile and run the above code how could you call cppTalkTo 
> from 
> > C++? Whats the C++ functions for that? 
> > 
> > 
> > Basically I want to: 
> > v8::Script::Run 
> > v8::Script::Compile 
> > At this point how do i get the cppTalkTo v8::Handle 
> and 
> > then call the function? 
>
> Have you looked at the examples in the samples/ directory? 
> samples/shell.cc in particular is a good starting point. 
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] call javascript function from c++

2018-06-06 Thread Ben Noordhuis
On Wed, Jun 6, 2018 at 11:42 AM, Joe Smack  wrote:
> Let's say you compile and run code:
>
> var StartNamespace =
> {
>  cppTalkTo: function () {
>   // some code
> }
> };
> StartNamespace.init();
>
> After you compile and run the above code how could you call cppTalkTo from
> C++? Whats the C++ functions for that?
>
>
> Basically I want to:
> v8::Script::Run
> v8::Script::Compile
> At this point how do i get the cppTalkTo v8::Handle and
> then call the function?

Have you looked at the examples in the samples/ directory?
samples/shell.cc in particular is a good starting point.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] call javascript function from c++

2018-06-06 Thread Joe Smack
Let's say you compile and run code:

var StartNamespace =
{
 cppTalkTo: function () {
  // some code
}
};
StartNamespace.init();

After you compile and run the above code how could you call cppTalkTo from 
C++? Whats the C++ functions for that?


Basically I want to:
v8::Script::Run
v8::Script::Compile
At this point how do i get the cppTalkTo v8::Handle and 
then call the function?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.