You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Alternative to creating references to non-objects #149
nodejs/node#15289 removed the possibility to create references to values that are not objects.
My use-case is the following. I want to store arguments given to my function persistently. Then some time later I want to call a callback function with those parameters. In the past I just used a vector<Reference<Value>>. Now I don't quite understand how I'm supposed to do it...
How about storing the arguments in a JS array and then creating a reference
to the array. Below is the pseudocode skeleton:
```c
napi_create_array();
for (index = 0; index < argc; index++) {
napi_set_element(array, index, argv[index]);
}
napi_create_reference(array, &array_ref);
```
On Fri, Sep 29, 2017 at 11:49 AM, Mika Fischer ***@***.***> wrote:
nodejs/node#15289 <nodejs/node#15289> removed the
possibility to create references to values that are not objects.
My use-case is the following. I want to store arguments given to my
function persistently. Then some time later I want to call a callback
function with those parameters. In the past I just used a
vector<Reference<Value>>. Now I don't quite understand how I'm supposed
to do it...
As an example, see this test: https://github.com/mika-
fischer/napi-thread-safe-callback/blob/e03dda83fb1d2a63fb8332406e2436
fc18a63fba/test/tests.cpp#L36-L51
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#149>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA7k0R_0u2jIKmgFqS4_joy9vjAFLR7vks5snK8cgaJpZM4PoYFz>
.
There is. You can convert it to a `char *` and then pass the `char *` to
`napi_wrap()`. In general, you need to convert to a native type, store the
data in a heap-allocated buffer, and use `napi_wrap()`.
On Fri, Sep 29, 2017 at 1:17 PM, Mika Fischer ***@***.***> wrote:
OK, fair enough, that's slightly inconcenient, but not too bad...
But just so I understand: There's now no way at all to just hold onto say
a string literal across calls into C++?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#149 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA7k0X7gRpG7-BD63rsy-k1FGKdGbZkcks5snMPPgaJpZM4PoYFz>
.
Sure, I meant keeping the JS string without converting to C++. That seems impossible now, right?
And while converting a string to C++ by itself is not that bad, in cases like this where you get passed a Value and you don't care what it is, you just want to hold on to it for later use, things are a lot more complicated than before if you don't want to use this boxing trick...
On Fri, Sep 29, 2017 at 1:51 PM, Mika Fischer ***@***.***> wrote:
Sure, I meant keeping the JS string without converting to C++. That seems
impossible now, right?
And while converting a string to C++ by itself is not that bad, in cases
like this where you get passed a Value and you don't care what it is, you
just want to hold on to it for later use, things are a lot more complicated
than before if you don't want to use this boxing trick...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#149 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA7k0Yh1YomF_IR2IaoYrIa4Kv9JZAUWks5snMupgaJpZM4PoYFz>
.
Activity
gabrielschulhof commentedon Sep 29, 2017
mika-fischer commentedon Sep 29, 2017
OK, fair enough, that's slightly inconcenient, but not too bad...
But just so I understand: There's now no way at all to just hold onto say a string literal across calls into C++?
gabrielschulhof commentedon Sep 29, 2017
mika-fischer commentedon Sep 29, 2017
Sure, I meant keeping the JS string without converting to C++. That seems impossible now, right?
And while converting a string to C++ by itself is not that bad, in cases like this where you get passed a
Valueand you don't care what it is, you just want to hold on to it for later use, things are a lot more complicated than before if you don't want to use this boxing trick...gabrielschulhof commentedon Sep 29, 2017
mika-fischer commentedon Sep 29, 2017
Ah I see, that makes sense then. Thanks for the explanations!