Hi All,

this is enough information for me to give this a shot next week (maybe
the next as time allows).

I am going to schedule in 2 non-consecutive days, just to try it out
and report back (each day) to this very helpful group if/when i
encounter problems.

so thanks for the good info, and next time i check in on this thread
will either be in a triumphant or frustrated tone :)

- Jak

On Jan 19, 9:32 am, Stephan Beal <[email protected]> wrote:
> On Wed, Jan 19, 2011 at 3:58 PM, Jak Sprats <[email protected]> wrote:
> > Is there a similarly simple mechanism to register JS functions to call
> > defined C functions.
>
> > This is the part I am not yet fully grasping on how to code it :)
>
> That's the easy part. Here's an (untested/skeleton) example:
>
> using namespace v8;
> Handle<Value> my_func( Arguments const & argv )
> {
>     if( argv.Length() < 1 ) {
>         return ThrowException("Requires 1 argument!");
>     }
>
>     unsigned int sleepTime = static_cast<unsigned int>(argv[0]->Int32Value);
>     unsigned int rc;
>     {
>         v8::Unlocker unlock; // allows other threads to work while
> sleep()ing
>         rc = ::sleep(sleepTime);
>     }
>     return Integer::New( static_cast<int32_t>(rc) );
>
> }
>
> (remember to do more range checking on the arguments, and remember that JS
> has no unsigned integer type, so a user passing a negative number would
> sleep very, very long in the above code.)
>
> my_func() simply implements the v8::InvocationCallback interface (the
> standard callback type), and can be bound directly to v8.
>
> That glue is basically what v8-juice/vu8 provide for you, but if you just
> want to wrap a small handful of functions then such helpers are probably
> overkill.
>
> --
> ----- stephan bealhttp://wanderinghorse.net/home/stephan/

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to