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

allow embedder to control the execution and error handling of callbacks #345

Closed
wants to merge 1 commit into from

Conversation

bfredl
Copy link

@bfredl bfredl commented Jun 24, 2019

For effecient use in neovim we would need a bit of control how luv executes callbacks.

Primarily we need to take control of handling of errors. Currently luv prints errors in callbacks directly to stderr which messes up the internal screen of nvim. But we would also like to set a flag around the execution of the callback, as some lua API functions in nvim need to behave differently inside a luv callback (to avoid nested event loop for instance).

My suggestion is to add a "hook" function that a C embedder can set in a similar way to setting the event loop. Then the embedder is responsible for executing the callback and dealing with errors, including potential formatting of tracebacks etc. neovim/neovim@aa78c74 is an example of usage.

Does this seem reasonable? if so I can clean up the patch, and add docs etc.

@bfredl
Copy link
Author

bfredl commented Jun 24, 2019

I guess a concern could be too many small userdata like both luv_loop_key and luv_cb_hook_key. A refactor could be to instead have a single userdata with a struct of the "global" luv state of a lua state.

@zhaozg
Copy link
Member

zhaozg commented Jun 26, 2019

Primarily we need to take control of handling of errors. Currently luv prints errors in callbacks directly to stderr which messes up the internal screen of nvim.

How a about generate a error with lua_error

My suggestion is to add a "hook" function that a C embedder can set in a similar way to setting the event loop.

I have no good idea, want to hear the voices of others.

@bfredl
Copy link
Author

bfredl commented Jun 26, 2019

How a about generate a error with lua_error

How would this work? lua_error only works inside a cfunction called from lua, and here we are outside any lua stack.

@zhaozg
Copy link
Member

zhaozg commented Jun 27, 2019

Do you mind if I re-implement this feature? That will break the API you defined. @bfredl

@bfredl
Copy link
Author

bfredl commented Jun 27, 2019

The API was only a suggestion, Yours also handles return values, so it is better.

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

Successfully merging this pull request may close these issues.

2 participants