webview icon indicating copy to clipboard operation
webview copied to clipboard

Return arg when unbinding

Open dandeto opened this issue 3 years ago • 1 comments

This will resolve #730. Please see the discussion there.

To test, modify the bind.c example to malloc an argument, bind, unbind, and free.

webview_t w = webview_create(0, NULL); context_t context = malloc (sizeof(context_t)); context->w = w; context->count = 0; webview_set_title(w, "Bind Example"); webview_set_size(w, 480, 320, WEBVIEW_HINT_NONE); webview_bind(w, "increment", increment, context); void arg = webview_unbind(w, "increment"); free(arg);

dandeto avatar Jul 18 '22 22:07 dandeto

I have updated #766 for the work you did in PR #797. It returns an error when attempting to bind again with the same name as well as when attempting to unbind a non-existing binding. This way C/C++ API users cannot easily use the API incorrectly.

If we were to go with my suggested approach then webview_get_bound_arg would return the arg in an output parameter and then return WEBVIEW_ERROR_OK itself; WEBVIEW_ERROR_NOT_FOUND would be returned for a non-existing binding.

Calling webview_get_bound_arg to get the arg associated with a synchronous binding should not be allowed so it could return e.g. WEBVIEW_ERROR_INVALID_ARGUMENT.

The C++ function that implements the logic could be named get_bound_arg and could simply return the arg (void *) and throw exceptions as needed.

SteffenL avatar Jul 21 '22 15:07 SteffenL

I have submitted PR #866 which is in conflict with some of the changes in this PR. Would you like to take a look?

SteffenL avatar Nov 30 '22 21:11 SteffenL

Thanks for the feedback, everyone. I made a new PR for this feature here: #867.

dandeto avatar Dec 02 '22 17:12 dandeto