本文整理汇总了C++中nan::FunctionCallbackInfo类的典型用法代码示例。如果您正苦于以下问题:C++ FunctionCallbackInfo类的具体用法?C++ FunctionCallbackInfo怎么用?C++ FunctionCallbackInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FunctionCallbackInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nodeExtractFiles
/* Extract files into directory.
*
* Extract an array of files (args[0]) into a directory of choice (args[1]).
* @param (string) Source directory of CASC archive
* @param (string) Destination directory to extract files
* @param (array) Array of files within the CASC archive
* @return (int) Number of files successfully extracted.
*/
void nodeExtractFiles(const Nan::FunctionCallbackInfo<v8::Value> &args) {
// Allocate a new scope when we create v8 JavaScript objects.
v8::Isolate *isolate = args.GetIsolate();
Nan::HandleScope scope;
// strSource
strSource = *v8::String::Utf8Value(args[0]->ToString());
if ((strSource[strSource.size() - 1] == '/') || (strSource[strSource.size() - 1] == '\\'))
strSource = strSource.substr(0, strSource.size() - 1);
// strDestination
strDestination = *v8::String::Utf8Value(args[1]->ToString());
if (strDestination.at(strDestination.size() - 1) != '/')
strDestination += "/";
// Open CASC archive
if (!CascOpenStorage(strSource.c_str(), 0, &hStorage)) {
cerr << "Failed to open the storage '" << strSource << "'" << endl;
args.GetReturnValue().Set(-1);
return;
}
int filesDone = 0;
if (args[2]->IsArray()) {
v8::Handle<v8::Array> files = v8::Handle<v8::Array>::Cast(args[2]);
for (uint32_t i = 0; i < files->Length(); i++) {
v8::String::Utf8Value item(files->Get(i)->ToString());
std::basic_string<char> file = std::string(*item);
size_t bytesWritten = extractFile(file);
if (bytesWritten > 0) {
filesDone++;
}
}
}
// Clean it up...
CascCloseStorage(hStorage);
hStorage = NULL;
// Ship it out...
args.GetReturnValue().Set(filesDone);
return;
}
示例2: Stop
void Client::Stop(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 1, "1")
CHECK_N_ARGS_IS_A_FUNCTION(info, 0, "0")
Callback* callback = new Callback(info[0].As<v8::Function>());
memClient->progressWorker->setCallback(callback);
memClient->isRunning = false;
}
示例3: nodeListFiles
/* List all files in a CASC archive.
*
* @param (string) Source directory of CASC files
* @return (array) Full paths of files in the archive
*/
void nodeListFiles(const Nan::FunctionCallbackInfo<v8::Value> &args) {
// Set API variables
bQuiet = true;
bVerbose = false;
// Allocate a new scope when we create v8 JavaScript objects.
v8::Isolate *isolate = args.GetIsolate();
Nan::HandleScope scope;
strSource = *v8::String::Utf8Value(args[0]->ToString());
if ((strSource[strSource.size() - 1] == '/') || (strSource[strSource.size() - 1] == '\\'))
strSource = strSource.substr(0, strSource.size() - 1);
if (!CascOpenStorage(strSource.c_str(), 0, &hStorage)) {
cerr << "Failed to open the storage '" << strSource << "'" << endl;
return;
}
// Define variables
CASC_FIND_DATA findData;
HANDLE handle = CascFindFirstFile(hStorage, "*", &findData, NULL);
// Let's get this party started..
vector<string> results = searchArchive();
// Convert returned vector of *chars to a v8::Array of v8::Strings
v8::Handle<v8::Array> files = v8::Array::New(isolate);
for (unsigned int i = 0; i < results.size(); i++ ) {
v8::Handle<v8::String> result = v8::String::NewFromUtf8(isolate, results[i].c_str());
files->Set(i, result);
}
// Clean it up...
CascFindClose(handle);
CascCloseStorage(hStorage);
handle = NULL;
hStorage = NULL;
// Ship it out...
args.GetReturnValue().Set(files);
return;
}
示例4: CheckPass
void CheckPass(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Nan::Utf8String recipfile(info[0]->ToString());
Nan::Utf8String pass(info[1]->ToString());
//wchar_t* w_recipfile = CharToWchar_New(*recipfile);
int ret = parse_cert_file(*recipfile, *pass,NULL);
//delete[] w_recipfile;
v8::Local<v8::Number> res = Nan::New(ret);
info.GetReturnValue().Set(res);
}
示例5: decrypt
void SecureCellContextImprint::decrypt(const Nan::FunctionCallbackInfo<v8::Value>& args) {
SecureCellContextImprint* obj = Nan::ObjectWrap::Unwrap<SecureCellContextImprint>(args.This());
size_t length=0;
const uint8_t* context=(const uint8_t*)(node::Buffer::Data(args[1]));
size_t context_length=node::Buffer::Length(args[1]);
if(themis_secure_cell_decrypt_context_imprint(&(obj->key_)[0], obj->key_.size(), (const uint8_t*)(node::Buffer::Data(args[0])), node::Buffer::Length(args[0]), context, context_length, NULL, &length)!=THEMIS_BUFFER_TOO_SMALL){
Nan::ThrowError("Secure Cell (Context Imprint) failed decrypting");
args.GetReturnValue().SetUndefined();
return;
}
uint8_t* data=(uint8_t*)(malloc(length));
if(themis_secure_cell_decrypt_context_imprint(&(obj->key_)[0], obj->key_.size(), (const uint8_t*)(node::Buffer::Data(args[0])), node::Buffer::Length(args[0]), context, context_length, data, &length)!=THEMIS_SUCCESS){
Nan::ThrowError("Secure Cell (Context Imprint) failed decrypting");
free(data);
args.GetReturnValue().SetUndefined();
return;
}
args.GetReturnValue().Set(Nan::NewBuffer((char*)(data), length).ToLocalChecked());
}
示例6: Inverse
/**
* Inverse:
* Compute the (multiplicative) inverse of a matrix.
* Given a square matrix a, return the matrix ainv satisfying dot(a, ainv) = dot(ainv, a)
*
* arguments:
* info[0]: Buffer(object created by smalloc) represent the numjs.Matrix object to be inverted.
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Buffer(object created by smalloc) for return value, inverse of the given matrix.
*/
void Inverse(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 4) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
Local<Object> matrixBuffer = info[0].As<Object>();
if (matrixBuffer->HasIndexedPropertiesInExternalArrayData()) {
double *refMatrixData = static_cast<double*>(matrixBuffer->GetIndexedPropertiesExternalArrayData());
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
Local<Object> resBuffer = info[4].As<Object>();
if (resBuffer->HasIndexedPropertiesInExternalArrayData()) {
double *refResData = static_cast<double*>(resBuffer->GetIndexedPropertiesExternalArrayData());
Md res(refResData, rowsMatrix, colsMatrix);
res = inputMat.inverse();
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments2");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
else{
Nan::ThrowTypeError("Wrong arguments3");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例7: sayHello
//#include <string>
void sayHello(const Nan::FunctionCallbackInfo<v8::Value>& info){
// v8::Local<v8::String> str=info.Data().Cast<v8::String>(info.Data());
Nan::Utf8String str(info[0]);
// std::cout<<*str<<std::endl;
// char* helloStr="hello ";
std::string hello=std::string("hello ")+std::string(*str);
// v8::Local<v8::String> helloStr=
// v8::String::NewFromUtf8(Nan::GetCurrentContext()->GetIsolate(),hello.c_str());
v8::Local<v8::String> helloStr=Nan::New<v8::String>("hello ").ToLocalChecked();
info.GetReturnValue().Set(helloStr);
}
示例8: Replace
void Client::Replace(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 4, "4")
CHECK_N_ARGS_IS_A_STRING(info, 0, "0")
CHECK_N_ARGS_IS_A_STRING(info, 1, "1")
CHECK_N_ARGS_IS_A_NUMBER(info, 2, "2")
CHECK_N_ARGS_IS_A_FUNCTION(info, 3, "3")
const string memcached_key = GET_STRING_FROM_PARAM(info[0]);
const string memcached_value = GET_STRING_FROM_PARAM(info[1]);
time_t ttl = (time_t) GET_NUMBER_FROM_PARAM(info[2]);
Callback* callback = GET_CALLBACK_FROM_PARAM(info[3]);
JobBase* job = new ReplaceJob(callback, memcached_key, memcached_value, ttl);
job->setDebug(memClient->debug);
memClient->jobs.insert(job);
info.GetReturnValue().Set(Nan::Undefined());
}
示例9: RegisterRemoved
void RegisterRemoved(const Nan::FunctionCallbackInfo<v8::Value>& args) {
Nan::HandleScope scope;
v8::Local<v8::Function> callback;
if (args.Length() == 0) {
return Nan::ThrowTypeError("First argument must be a function");
}
if (args.Length() == 1) {
// callback
if(!args[0]->IsFunction()) {
return Nan::ThrowTypeError("First argument must be a function");
}
callback = args[0].As<v8::Function>();
}
removedCallback = new Nan::Callback(callback);
isRemovedRegistered = true;
}
示例10: GetClipDatabase
void GetClipDatabase(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if ((info.Length() < 1) || (info.Length() > 1)) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[0]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
int sizeOfData = 0;
char* clipDatabase = GetClipDatabase(sizeOfData);
v8::Local<v8::String> v8ClipDatabase = v8::String::New(clipDatabase, sizeOfData);
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
obj->Set(Nan::New("msg").ToLocalChecked(), v8ClipDatabase);
info.GetReturnValue().Set(obj);
FreeClipDatabase(clipDatabase);
}
示例11: Inverse
/**
* Inverse:
* Compute the (multiplicative) inverse of a matrix.
* Given a square matrix a, return the matrix ainv satisfying dot(a, ainv) = dot(ainv, a)
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be inverted.
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Buffer(object created by Float64Array) for return value, inverse of the given matrix.
*/
void Inverse(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 4) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
if (info[3]->IsFloat64Array()) {
double *refResData = *(Nan::TypedArrayContents<double>(info[3]));
Md res(refResData, rowsMatrix, colsMatrix);
res = inputMat.inverse();
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments (4th arg)");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
else{
Nan::ThrowTypeError("Wrong arguments (1st arg)");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例12: Parse
void MeCab_Tagger::Parse(const Nan::FunctionCallbackInfo<v8::Value>& info) {
MeCab_Tagger* mecabTagger = ObjectWrap::Unwrap<MeCab_Tagger>(info.Holder());
v8::String::Utf8Value input(info[0]);
v8::Local<v8::Function> callback = info[1].As<v8::Function>();
const char *result = mecabTagger->tagger->parse(*input);
const unsigned argc = 2;
v8::Local<v8::Value> argv[] = {
Nan::Null(),
Nan::New(result).ToLocalChecked()
};
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, argc, argv);
}
示例13: Tri
/**
* Tri:
* Creates a new nXm matrix with ones at and below the matrix diagonal
* and zeros elsewhere.
*
* arguments:
* info[0]: Number n which represents the number of rows in the newly built matrix
* info[1]: Number m which represents the number of cols in the newly built matrix
* info[2]: Buffer(object created by Float64Array) for return value(eye matrix nXm).
*/
void Tri(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[0]->IsNumber() || !info[1]->IsNumber()) {
Nan::ThrowTypeError("Wrong argument given, should be a number");
return;
}
if (info[2]->IsFloat64Array()) {
size_t rowsMatrix(info[0]->Uint32Value());
size_t colsMatrix(info[1]->Uint32Value());
double *refResData = *(Nan::TypedArrayContents<double>(info[2]));
Md res(refResData, rowsMatrix, colsMatrix);
res = Md::Ones(rowsMatrix, colsMatrix);
for (int i = 0; i < rowsMatrix; i++) {
for (int j = i + 1; j < colsMatrix; j++) {
res(i, j) = 0;
}
}
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments2");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例14: getTelemetryDescription
void getTelemetryDescription(const Nan::FunctionCallbackInfo<v8::Value>& args)
{
Local<Object> obj = Nan::New<Object>();
std::vector<irsdk_varHeader*> headers = irsdk.getVarHeaders();
for (const auto item : headers)
{
IRSDKWrapper::TelemetryVar var(item);
irsdk.getVarVal(var);
Handle<Object> varObj = Nan::New<Object>();
convertVarHeaderToObject(var, varObj);
Nan::Set(obj, Nan::New(var.header->name).ToLocalChecked(), varObj);
}
args.GetReturnValue().Set(obj);
}
示例15: MGetAndFetchAll
void Client::MGetAndFetchAll(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Client* memClient = ObjectWrap::Unwrap<Client>(info.Holder());
CHECK_ARGUMENT_LENGTH(info, 2, "2")
CHECK_N_ARGS_IS_AN_ARRAY(info, 0, "0")
CHECK_N_ARGS_IS_A_FUNCTION(info, 1, "1")
v8::Local<v8::Object> arr = info[0]->ToObject();
size_t number_of_keys = arr->GetOwnPropertyNames()->Length();
memClient->debug && printf("%s %lu %s\n", "Array with", number_of_keys, "keys");
std::vector<string> keys;
for(size_t i = 0; i < number_of_keys; i++) {
keys.push_back(GET_STRING_FROM_PARAM(arr->Get(i)));
}
Callback* callback = GET_CALLBACK_FROM_PARAM(info[1]);
JobBase* job = new MGetAndFetchAllJob(callback, keys);
job->setDebug(memClient->debug);
memClient->jobs.insert(job);
info.GetReturnValue().Set(Nan::Undefined());
}