I have this:
if (!args[2]->IsString() || (*args[2]->ToString() != "true" && *args[2]->ToString() != "false")) {
Nan::ThrowTypeError("Third argument to 'replace-line' must be a string representing whether to find or replace.");
return;
}
but I get a compilation errors andwarnings:
../hello.cpp:49:58: error: comparison between distinct pointer types ‘v8::String*’ and ‘const char*’ lacks a cast [-fpermissive]
../hello.cpp:49:92: warning: comparison with string literal results in unspecified behaviour [-Waddress]
if (!args[2]->IsString() || (*args[2]->ToString() != "true" && *args[2]->ToString() != "false")) {
how can I properly compare v8 strings with plain C strings?
You can convert using
v8::String::NewFromOneByte
detailed in the documentation there are also other sources if you want.If you want to go the other way it looks like you would have to create your own buffer and use
WriteOneByte
.