The value of args[0] in the call to the callback is an Object, and its
properties can be retrieved using the Get method, e.g. for subject:

  Handle<Value> subject = args[0]->Get(v8::String::New("Subject"))

Regards,
Søren

On Sun, Sep 14, 2008 at 10:27 PM, Hector <[EMAIL PROTECTED]> wrote:

>
> I might be going about this the wrong way, but I'm just exploring the
> different ways I can do this.
>
> Given a developer's V8 script usage of our embedded implementation
> exposing an API to it:
>
> function addMessage(toWhom, subject, text) {
>  var msg = {};
>  msg.From     = {Name: "Post Master"}
>  msg.To         = {Name: toWhom};
>  msg.Private   = true;
>  msg.Subject  = subject;
>  if (!wcAddMessage(msg,text)) {
>       alert("! Error wcaddMessage: "+wcGetLastError());
>  }
> }
>
> I want to the callback to wcAddMessage() to be able to read the msg
> json object using Arguments:
>
> static Handle<Value> wcAddMessageCallback(const Arguments& args) {
>  if (args.Length() < 1) return v8::Undefined();
>  HandleScope scope;
>
>  printf("------------------------------------------------\n");
>  printf("- args length: %d\n",args.Length());
>
>  v8::String::AsciiValue text(args[1]);
>  printf("- args[1]: [%s]\n",*text);
>
>  ???? How to I access the args[0] as a JSON object ??
> /*
>  map<string, string> *msg = wcUnwrapMap(args[0]);
>  for (map<string, string>::iterator i = msg->begin(); i != msg-
> >end(); i++) {
>    pair<string, string> entry = *i;
>    printf("AddMsg Args: %s: %s\n", entry.first.c_str(),
> entry.second.c_str());
>  }
> */
>  return v8::Undefined();
> }
>
> I basically want to extract the fields here so I can map it to the
> actual TMsgHeader c-structure which in this case only needs a few
> fields filled to satisfy the API wcAddMessage() call.
>
> Maybe this isn't the best approach, but I'm trying to think ahead in
> optimizing this, but I am not very familiar with V8 yet.   I mean,
> off hand, I appears it would be inefficient for us to create a class
> object for all our c-based structures (over 60 of them) and then
> instances of these in V8 scripts will be making all the getters and
> setters calls.
>
> Thanks for any tips
>
>
>
> >
>

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

Reply via email to