-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative to creating references to non-objects #149
Comments
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>
.
|
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++? |
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 |
It is indeed more complicated. Nevertheless, it is necessary, because not
all engines support making references to non-object types.
…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>
.
|
Ah I see, that makes sense then. Thanks for the explanations! |
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/e03dda83fb1d2a63fb8332406e2436fc18a63fba/test/tests.cpp#L36-L51
The text was updated successfully, but these errors were encountered: