Posting an array to PNaCl module and working with it there

25 views
Skip to first unread message

Tal Glozman

unread,
Sep 9, 2016, 5:01:08 PM9/9/16
to Native-Client-Discuss
I'm trying to put all the values from an pp::VarArray variable into a local array, I have this so far:

     virtual void HandleMessage(const pp::Var& message) {
           
// is array condition
           
if (message.is_array()) {
               
PostMessage(pp::Var("I'm in is_array condition"));
   
               
// get the object
                pp
::VarArray array(message);
   
               
// get the first elemet of the Object, which is an array into a new array
                pp
::VarArray newArray = pp::VarArray(array.Get(0));
   
               
// Use the object and array
               
// the size of the object
                int32_t arrayObjectSize
= array.GetLength(); // important for the last job number 4 to loop and create the lenth variables for the 2 arrays
               
PostMessage(pp::VarArray(array));
               
PostMessage(pp::Var("the size of the object array: " + std::to_string(arrayObjectSize)));
   
                int32_t newArraySize
= newArray.GetLength();
               
PostMessage(pp::VarArray(newArray));
               
PostMessage(pp::Var("the size of the object array: " + std::to_string(newArraySize)));
               
PostMessage(newArray.Get(0));
 
   
                int32_t size
= 50;
                int32_t unsortedArray
[size];
   
               
for (int32_t i = 0; i < size; ++i){
                     unsortedArray
[i] = newArray.Get(i);
               
}
           
}
     
}

I can't get it done with the loop i'm getting a compile error:

    job2.cc:104:35: error: assigning to 'int32_t' (aka 'int') from incompatible type 'pp::Var'
                     unsortedArray
[i] = newArray.Get(i);
                                     
^ ~~~~~~~~~~~~~~~

Does any one know how I can get those 50 elements from the `pp::VarArray newArray` into this local `unsortedArray`?

Sam Clegg

unread,
Sep 12, 2016, 1:13:44 PM9/12/16
to native-cli...@googlegroups.com
Get is returning you a `Var` object. If you want to get integer
value of the `Var` you need to call `AsInt()` on it. You can also use
`is_int()` to check the type of the boxed value.

>
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.
> To post to this group, send email to native-cli...@googlegroups.com.
> Visit this group at https://groups.google.com/group/native-client-discuss.
> For more options, visit https://groups.google.com/d/optout.

Tal Glozman

unread,
Sep 12, 2016, 4:22:54 PM9/12/16
to native-cli...@googlegroups.com
Thanks for the help!.

--
You received this message because you are subscribed to a topic in the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/native-client-discuss/PYKGHQG82gg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to native-client-discuss+unsub...@googlegroups.com.
To post to this group, send email to native-client-discuss@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages