On Fri, Nov 12, 2010 at 7:21 AM, Trevor Burnham <[email protected]> wrote: > Hi, > > Suppose that I pass a string from JavaScript-land to a function > defined in a C extension. If the string is short, it's easy to convert > it: > > const char* stringArgToCStr(const v8::Local<v8::Value> arg) { > v8::String::AsciiValue str(arg); > return *str; > } > > However, this will break if the string is more than 256 characters > long (as will v8::String::Utf8Value).
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: c_func(*String::AsciiValue(arg)); Matthias > How do I work with strings of > longer length from C-world? Looking at the API docs, it sounds like I > should be using an external string for efficiency's sake, but I'm > unclear on how to use them. Concrete examples would be greatly > appreciated. > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
