On Fri, Jan 7, 2011 at 3:09 AM, getify <[email protected]> wrote:
> Thanks! That seems to work. However, I'm still having trouble
> converting some types of the properties on the object to something
> useable in my C++.
>
> For instance:
>
> v8::String::Utf8Value my_str = v8::String::Utf8Value(obj-
>>Get(v8::String::New("my_str")));
>
> That works for getting a string property (`my_str`) value out. But now
> that I have a v8::String::Utf8Value, is there a straightforward way to
> get that value into something I can use, like a C++ std::string for
> instance?
I think you're doing it quite right. I must admit I've never dealt
with failed conversion.
I'm not sure what reasons for failure exist other than
input->ToString() failing - which is not an issue if it's already a
string.
> This is what I came up with from the sample code:
>
> const char* ToCString(const v8::String::Utf8Value& value) {
> return *value ? *value : "<string conversion failed>";
> }
>
> ...
>
> std::string my_str =
> std::string::New(ToCString(v8::String::Utf8Value(obj-
>>Get(v8::String::New("my_str")))));
>
> That seems kinda convoluted, but works. However, is there another more
> direct way?
>
> And what about extracting a Boolean? Integer? Float? Array? Haven't
> found any documentation about how to get at those other property
> types. Any help is greatly appreciated.
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).
>
> --
> 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