Skip to content
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

Convert Go *string pointer or type alias to a regular JS string? #377

Closed
klvnptr opened this issue Apr 1, 2022 · 4 comments
Closed

Convert Go *string pointer or type alias to a regular JS string? #377

klvnptr opened this issue Apr 1, 2022 · 4 comments
Labels

Comments

@klvnptr
Copy link

klvnptr commented Apr 1, 2022

Hello. Thank you for goja, I love it :)

Question, that I hadn't been able to figure out so far:

input := "hello"
var str *string = &input
val := vm.ToValue(str)

In this case val will be a JS object. But I want it to be a JS string that contains "hello". Is there any way to do this?
Same question applies to type aliases:

type Hello string
var hello Hello = "world"
helloVal := suite.vm.ToValue(hello)

helloVal will be a JS object instead of a string.

Thanks so much. Peter

@dop251
Copy link
Owner

dop251 commented Apr 5, 2022

Hi. Sorry, not sure what you mean. Do you want ToValue() to return plain string in this case?

@klvnptr
Copy link
Author

klvnptr commented Apr 5, 2022

Hello @dop251 Thanks for you reply.
Yes, in the first case I want ToValue to return a string instead of an object. Would be awesome to somehow override how ToValue behaves.

@dop251
Copy link
Owner

dop251 commented Apr 5, 2022

Sorry, but I don't feel like introducing the sort of customisation you are suggesting would be beneficial, it would make it more complicated and slower for everybody. Instead of using ToValue() or Export(), you can implement your own mechanism if necessary.

@dop251 dop251 closed this as completed Apr 5, 2022
@dop251 dop251 added the question label Apr 5, 2022
@klvnptr
Copy link
Author

klvnptr commented Apr 5, 2022

I would be happy to implement it, but it is impossible to do so without forking the project. Can you give me any suggestions how to do it without forking? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants