{ "Napi struct reference in": { "prefix": "napistructrefin", "body": [ "napi_value args[1];", "size_t argc = 1;", "napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);", "// Get struct reference from args[0]. data is a reference which passed to JS through napi_create_external.", "void* data;", "napi_get_value_external(env, args[0], &data);" ] }, "Napi struct reference out": { "prefix": "napistructrefout", "body": [ "/** struct MyStruct {", " * public:", " * MyStruct();", " * ~MyStruct();", " * void SetValue(int value);", " * int GetValue() const;", " * private:", " * int value_;", " * };", " */", "MyStruct* data = new MyStruct();", "napi_value result;", "// Create a JS external value that wraps a pointer to native data.", "napi_create_external(env, data, nullptr, nullptr, &result);" ] }, "Napi class reference in": { "prefix": "napiclassrefin", "body": [ "size_t argc = 1;", "napi_value args[1];", "napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);", "void* data;", "// Get class reference from args[0]. data is a reference which passed to JS through napi_create_external.", "napi_get_value_external(env, args[0], &data);" ] }, "Napi class reference out": { "prefix": "napiclassrefout", "body": [ "/** class MyClass {", " * public:", " * MyClass();", " * ~MyClass();", " * void SetValue(int value);", " * int GetValue() const;", " * private:", " * int value_;", " * };", " */", "MyClass* data = new MyClass();", "napi_value result;", "// Create a JS external value that wraps a pointer to native data.", "napi_create_external(env, data, nullptr, nullptr, &result);" ] }, "Napi array reference in": { "prefix": "napiarrayrefin", "body": [ "size_t argc = 1;", "napi_value args[1];", "int32_t* cppArray;", "napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);", "// Get int32_t array from args[0].", "napi_get_value_external(env, args[0], (void**)&cppArray);" ] }, "Napi array reference out": { "prefix": "napiarrayrefout", "body": [ "int32_t* cppArray = new int32_t[5]{1, 2, 3, 4, 5};", "napi_value jsArray;", "// FinalizeCallback is a optional callback that used to release data. (e.g.:delete[] cppArray;).", "napi_create_external(env, cppArray, FinalizeCallback, nullptr, &jsArray);" ] } }