On Fri, Jan 7, 2011 at 5:58 PM, getify <[email protected]> wrote:
>> See the API docs for
>
> I've tried many times to find "the API docs". All I found is this:
> http://code.google.com/apis/v8/intro.html
>
> I've read through all the pages there, and I don't see any
> documentation about these different API functions. What documentation
> am I missing?
>
>
>>Same pattern. Either you can use the ECMA conversions via "ToNumber", 
>>"ToBoolean", ... or Cast the handle after checking "IsXXX". Number has 
>>"double Value()", Boolean has "bool Value()". Array has Length() and 
>>Get(uint32).
>
> I tried:
>
>    bool logging = obj->Get(v8::String::New("my_bool"))->ToBoolean();

I fully agree with you that the documentation is lacking. Really, v8.h
is your friend. There are lots of third-party articles about specific
things, but in the end, you'll need to look at the header and try your
way through. You seem to have grokked the Handle<X> ~ smart pointer
idea, so given a Handle<X> you want to look at X's interface.

Let's see:

  V8EXPORT Local<Boolean> ToBoolean() const;

(What I think I've learnt is that the To* methods perform conversions
as described in ECMA 262.
http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf.
E.g. String::New("3")->ToNumber() won't fail but convert to a Number
value. Other than the Casts mentioned above).

So now we have a Local<Boolean>.

...
class Boolean : public Primitive {
 public:
  V8EXPORT bool Value() const;
  static inline Handle<Boolean> New(bool value);
};

i.e.

bool boolValue = v8Value->ToBoolean()->Value();

or there seems to be a shortcut:
V8EXPORT bool BooleanValue() const;


Matthias


>
> And the compiler complains:
>
>    error: cannot convert v8::Local<v8::Boolean> to bool in
> initialization
>
> Then I tried:
>
>    bool logging = (bool)obj->Get(v8::String::New("my_bool"))-
>>ToBoolean();
>
> And the compiler complains:
>
>    error: invalid cast from type v8::Local<v8::Boolean>to type bool
>
> Sorry, I'm sure the documentation that I'm failing to find makes this
> all perfectly clear, but I'm having an extrodinary amount of
> difficulty getting a type from the V8 version of that type
> (v8::Boolean) to the actual c/c++ type (bool) so that I can do
> something with it. Again, any help or direction to specific
> documentation is greatly appreciated.
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users

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

Reply via email to