Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following V8 code:

Local<String> getSumString(int32_t a,  int32_t b){
    int32_t sum = a + b;
    return String::Concat(String::New("The sum is: ") , String::New(sum));
}

In the above function I want to add a and b, then want to return a string "The sum is: CALCULATED_SUM " .

I'm having problems in converting the calculated sum to a String so that it can be concatenated with other String.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
158 views
Welcome To Ask or Share your Answers For Others

1 Answer

You don't say the nature of the error, but I'm guessing that the end of your output string is mangled, because you're instantiating a String from an int. V8 is interpreting that data as const char * data. You should instantiate an Integer from your int. Your last line will look like this instead:

return String::Concat(String::New("The sum is: ") , Integer::New(sum));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...