Ah, I see. Thanks for the help. Obviously my inexperience with C is
showing...
This seems to work, though it makes me a bit nervous about memory
leaks:
const char* stringArgToStr(const v8::Local<v8::Value> arg) {
v8::String::AsciiValue v8Str(arg);
char *cStr = (char*) malloc(strlen(*v8Str) + 1);
strcpy(cStr, *v8Str);
return cStr;
}
Of course, I suppose it would be more elegant to just keep v8Str
around and use the pointer to it when needed.
On Nov 12, 2:50 am, Stephan Beal <[email protected]> wrote:
> On Fri, Nov 12, 2010 at 8:38 AM, Matthias Ernst <[email protected]> wrote:
> > I don't think there is a length restriction. Rather, your method may
> > fail because the char* is deleted as soon as the AsciiValue goes out
> > of scope - it owns the array. I guess v8.h could make that more clear.
> > If you expand the expression inline it should work:
>
> i agree. The lifetime of the char bytes are undefined in your example, and
> v8 "almost certainly" deletes them the first chance it gets.
> See:http://code.google.com/p/v8-juice/wiki/BindingFunctions#The_(_char_co...
>
> --
> ----- stephan bealhttp://wanderinghorse.net/home/stephan/
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users