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

How to custom APIs? #28

Closed
Cretezy opened this issue Jan 17, 2020 · 5 comments · Fixed by #68
Closed

How to custom APIs? #28

Cretezy opened this issue Jan 17, 2020 · 5 comments · Fixed by #68
Labels
enhancement New feature or request

Comments

@Cretezy
Copy link

Cretezy commented Jan 17, 2020

I'm interesting in adding custom APIs, such as adding a console API to print.

My question is how to add callbacks from JS to Go using v8go. I've used J2V8 before which allows to add APIs to the global scope, such as an object for console with the method log which calls back to Java in that case. Is that possible using this project?

The ideal API would be something like (pseudo code):

console = CreateObject()

console.AddMethod("log", (params Value[]) {
	print(params[0])
})

isolate.Add("console", console)

In addition, it would be much more useful to actually be able to use Value with more than strings.

@kostyaten
Copy link

I would also like to get such functionality!

@ghost
Copy link

ghost commented Jun 13, 2020

Being able to bind structs, functions, and values to variables in V8 would make this useful for the project I'm working on as well. Right now I'm trying to replace goja, and stumbled on this project.

@tmc
Copy link
Collaborator

tmc commented Nov 27, 2020

Currently this project does not expose a method to influence the global object in the created context.

@rogchap
Copy link
Owner

rogchap commented Dec 20, 2020

This is something I'm looking at adding as an API. Starting with #50, which will pave the way for more interop between v8 and Go.

In terms of specifically console'log that may require a slightly custom API as v8 has it's own delegate for the console object. Still needs to flesh this out, but will become clearer once I get to that part of the code.

Thanks for your patience.

@rogchap
Copy link
Owner

rogchap commented Jan 17, 2021

#64

@rogchap rogchap added the enhancement New feature or request label Jan 19, 2021
@rogchap rogchap mentioned this issue Jan 19, 2021
@rogchap rogchap linked a pull request Feb 8, 2021 that will close this issue
@rogchap rogchap closed this as completed Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants