When the linked pull request is merged, you will be able to call
val::typeof(), which returns another val.  You probably want to write
val::typeof().as<std::string>() most of the time.

https://github.com/kripken/emscripten/pull/2360

Cheers,
Chad



On Thu, May 15, 2014 at 11:19 AM, Chad Austin <[email protected]> wrote:

> On Thu, May 15, 2014 at 4:41 AM, Lee Morgan 
> <[email protected]>wrote:
>
>> Hi Chad,
>>
>> Thanks for your answer.
>>
>> Say I want to convert a JS value to my C++ variant type, so if string,
>> cast string if number cast float, if array iterate etc
>>
>> (I'm trying to store a JS object as c++ map)
>>
>
> I see, cool.
>
> When I get home to my Ubuntu VM where I do emscripten development, I'll
> try to expose the 'typeof' operator to emval.
>
> Just so you're aware, here are the semantics of the JS typeof operator:
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
>
>
>> Cheers
>> Lee
>>
>> On Thursday, May 15, 2014 7:04:33 AM UTC+1, Chad Austin wrote:
>>
>>> On Tue, May 13, 2014 at 3:37 AM, Lee Morgan <[email protected]>wrote:
>>>
>>>> Hi,
>>>>
>>>> Can I access the object keys given an emscripten::val.
>>>>
>>>
>>> Hi Lee,
>>>
>>> That's a good question.  Here's one way:
>>>
>>> #include <stdio.h>
>>> #include <emscripten/val.h>
>>>
>>> using emscripten::val;
>>>
>>> int main() {
>>>     val window = val::global("window");
>>>     val keys = val::global("Object").call<val>("keys", window);
>>>     int length = keys["length"].as<int>();
>>>     for (int i = 0; i < length; ++i) {
>>>         printf("%s\n", keys[i].as<std::string>().c_str());
>>>     }
>>> }
>>>
>>> The example program looks up the global 'window' object and then prints
>>> out all of the keys.
>>>
>>>
>>>> How do I get type information about a val? or an array length etc
>>>>
>>>
>>> The above example illustrates getting array length, but I don't think
>>> there's a typeof operator exposed yet.
>>>
>>> In particular, what kind of type information do you need?
>>>
>>> Thanks,
>>> Chad
>>>
>>>  --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Chad Austin
> Technical Director, IMVU
> http://engineering.imvu.com <http://www.imvu.com/members/Chad/>
> http://chadaustin.me
>
>
>


-- 
Chad Austin
Technical Director, IMVU
http://engineering.imvu.com <http://www.imvu.com/members/Chad/>
http://chadaustin.me

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to