I'm trying to use ToCString in a NodeJS addon.
String::Utf8Value foo_utf8(args[0]->ToString());
const char *foo = ToCString(foo_utf8);
I can't find it's header, and if I manually prototype it as:
const char* ToCString(const v8::String::Utf8Value& value);
then I get a runtime error of:
node: symbol lookup error: /home/chris/Dropbox/cbackend/build/Release/cbackend.node:
undefined symbol: _Z9ToCStringRKN2v86String9Utf8ValueE
How can I convert a V8 String argument to a null-terminated 8 bit C string?
I found a workaround, as the ToCString function (wherever it lives) is trivial. Just add:
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
}
Going by the docs, v8 has operators for cstr conversion:
Local<Value> value = get_value(); // nan† thing, you can ignore this
v8::String::Utf8Value string(value);
char* str = *string; // defined as: char * operator* ()
const char* const_str = *string; // defined as: const char * operator* () const
This applies to both njs v0.10 and v0.11.