Skip to content

Commit

Permalink
Runtime: Update the webview C API return types
Browse files Browse the repository at this point in the history
Doesn't seem to make much of a difference in practice, but it might in the future enable better error handling?
  • Loading branch information
rdw-software committed Jan 10, 2025
1 parent 7545b3c commit 44b2663
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 37 deletions.
44 changes: 32 additions & 12 deletions Runtime/Bindings/FFI/webview/webview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,47 @@ typedef struct {
char pre_release[48];
char build_metadata[48];
} webview_version_info_t;
typedef enum {
/// Missing dependency.
WEBVIEW_ERROR_MISSING_DEPENDENCY = -5,
/// Operation canceled.
WEBVIEW_ERROR_CANCELED = -4,
/// Invalid state detected.
WEBVIEW_ERROR_INVALID_STATE = -3,
/// One or more invalid arguments have been specified e.g. in a function call.
WEBVIEW_ERROR_INVALID_ARGUMENT = -2,
/// An unspecified error occurred. A more specific error code may be needed.
WEBVIEW_ERROR_UNSPECIFIED = -1,
/// OK/Success. Functions that return error codes will typically return this
/// to signify successful operations.
WEBVIEW_ERROR_OK = 0,
/// Signifies that something already exists.
WEBVIEW_ERROR_DUPLICATE = 1,
/// Signifies that something does not exist.
WEBVIEW_ERROR_NOT_FOUND = 2
} webview_error_t;
typedef void (*promise_function_t)(const char* seq, const char* req, void* arg);
typedef void (*webview_dispatch_function_t)(webview_t w, void* arg);
struct static_webview_exports_table {
webview_t (*webview_create)(int debug, void* window);
void (*webview_destroy)(webview_t w);
webview_error_t (*webview_destroy)(webview_t w);
void (*webview_toggle_fullscreen)(webview_t w);
void (*webview_run)(webview_t w);
webview_error_t (*webview_run)(webview_t w);
int (*webview_run_once)(webview_t w, int blocking);
void (*webview_terminate)(webview_t w);
void (*webview_dispatch)(webview_t w, webview_dispatch_function_t fn, void* arg);
webview_error_t (*webview_terminate)(webview_t w);
webview_error_t (*webview_dispatch)(webview_t w, webview_dispatch_function_t fn, void* arg);
void* (*webview_get_window)(webview_t w);
void (*webview_set_title)(webview_t w, const char* title);
void (*webview_set_size)(webview_t w, int width, int height, webview_hint_t hints);
webview_error_t (*webview_set_title)(webview_t w, const char* title);
webview_error_t (*webview_set_size)(webview_t w, int width, int height, webview_hint_t hints);
void (*webview_navigate)(webview_t w, const char* url);
void (*webview_set_html)(webview_t w, const char* html);
void (*webview_init)(webview_t w, const char* js);
void (*webview_eval)(webview_t w, const char* js);
void (*webview_bind)(webview_t w, const char* name, promise_function_t fn, void* arg);
void (*webview_unbind)(webview_t w, const char* name);
void (*webview_return)(webview_t w, const char* seq, int status, const char* result);
webview_error_t (*webview_set_html)(webview_t w, const char* html);
webview_error_t (*webview_init)(webview_t w, const char* js);
webview_error_t (*webview_eval)(webview_t w, const char* js);
webview_error_t (*webview_bind)(webview_t w, const char* name, promise_function_t fn, void* arg);
webview_error_t (*webview_unbind)(webview_t w, const char* name);
webview_error_t (*webview_return)(webview_t w, const char* seq, int status, const char* result);
const webview_version_info_t* (*webview_version)(void);
bool (*webview_set_icon)(webview_t w, const char* file_path);
void* (*webview_get_native_handle)(webview_t w, webview_native_handle_kind_t kind);
Expand Down
22 changes: 21 additions & 1 deletion Runtime/Bindings/FFI/webview/webview_aliases.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,24 @@ typedef struct {
char version_number[32];
char pre_release[48];
char build_metadata[48];
} webview_version_info_t;
} webview_version_info_t;

typedef enum {
/// Missing dependency.
WEBVIEW_ERROR_MISSING_DEPENDENCY = -5,
/// Operation canceled.
WEBVIEW_ERROR_CANCELED = -4,
/// Invalid state detected.
WEBVIEW_ERROR_INVALID_STATE = -3,
/// One or more invalid arguments have been specified e.g. in a function call.
WEBVIEW_ERROR_INVALID_ARGUMENT = -2,
/// An unspecified error occurred. A more specific error code may be needed.
WEBVIEW_ERROR_UNSPECIFIED = -1,
/// OK/Success. Functions that return error codes will typically return this
/// to signify successful operations.
WEBVIEW_ERROR_OK = 0,
/// Signifies that something already exists.
WEBVIEW_ERROR_DUPLICATE = 1,
/// Signifies that something does not exist.
WEBVIEW_ERROR_NOT_FOUND = 2
} webview_error_t;
24 changes: 12 additions & 12 deletions Runtime/Bindings/FFI/webview/webview_exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ typedef void (*webview_dispatch_function_t)(webview_t w, void* arg);

struct static_webview_exports_table {
webview_t (*webview_create)(int debug, void* window);
void (*webview_destroy)(webview_t w);
webview_error_t (*webview_destroy)(webview_t w);
void (*webview_toggle_fullscreen)(webview_t w);
void (*webview_run)(webview_t w);
webview_error_t (*webview_run)(webview_t w);
int (*webview_run_once)(webview_t w, int blocking);
void (*webview_terminate)(webview_t w);
void (*webview_dispatch)(webview_t w, webview_dispatch_function_t fn, void* arg);
webview_error_t (*webview_terminate)(webview_t w);
webview_error_t (*webview_dispatch)(webview_t w, webview_dispatch_function_t fn, void* arg);
void* (*webview_get_window)(webview_t w);
void (*webview_set_title)(webview_t w, const char* title);
void (*webview_set_size)(webview_t w, int width, int height, webview_hint_t hints);
webview_error_t (*webview_set_title)(webview_t w, const char* title);
webview_error_t (*webview_set_size)(webview_t w, int width, int height, webview_hint_t hints);
void (*webview_navigate)(webview_t w, const char* url);
void (*webview_set_html)(webview_t w, const char* html);
void (*webview_init)(webview_t w, const char* js);
void (*webview_eval)(webview_t w, const char* js);
void (*webview_bind)(webview_t w, const char* name, promise_function_t fn, void* arg);
void (*webview_unbind)(webview_t w, const char* name);
void (*webview_return)(webview_t w, const char* seq, int status, const char* result);
webview_error_t (*webview_set_html)(webview_t w, const char* html);
webview_error_t (*webview_init)(webview_t w, const char* js);
webview_error_t (*webview_eval)(webview_t w, const char* js);
webview_error_t (*webview_bind)(webview_t w, const char* name, promise_function_t fn, void* arg);
webview_error_t (*webview_unbind)(webview_t w, const char* name);
webview_error_t (*webview_return)(webview_t w, const char* seq, int status, const char* result);
const webview_version_info_t* (*webview_version)(void);
bool (*webview_set_icon)(webview_t w, const char* file_path);
void* (*webview_get_native_handle)(webview_t w, webview_native_handle_kind_t kind);
Expand Down
24 changes: 12 additions & 12 deletions Runtime/Bindings/FFI/webview/webview_ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ namespace webview_ffi {
return w;
}

void webview_destroy(webview_t w) {
webview_error_t webview_destroy(webview_t w) {
delete static_cast<WebviewBrowserEngine*>(w);
}

void webview_toggle_fullscreen(webview_t w) {
static_cast<WebviewBrowserEngine*>(w)->toggleFullScreen();
}

void webview_run(webview_t w) {
webview_error_t webview_run(webview_t w) {
static_cast<WebviewBrowserEngine*>(w)->run();
}

void webview_terminate(webview_t w) {
webview_error_t webview_terminate(webview_t w) {
static_cast<WebviewBrowserEngine*>(w)->terminate();
}

Expand All @@ -68,32 +68,32 @@ namespace webview_ffi {
return unwrapResult(static_cast<WebviewBrowserEngine*>(w)->window());
}

void webview_set_title(webview_t w, const char* title) {
webview_error_t webview_set_title(webview_t w, const char* title) {
static_cast<WebviewBrowserEngine*>(w)->set_title(title);
}

void webview_set_size(webview_t w, int width, int height,
webview_error_t webview_set_size(webview_t w, int width, int height,
webview_hint_t hints) {
static_cast<WebviewBrowserEngine*>(w)->set_size(width, height, hints);
}

void webview_navigate(webview_t w, const char* url) {
webview_error_t webview_navigate(webview_t w, const char* url) {
static_cast<WebviewBrowserEngine*>(w)->navigate(url);
}

void webview_set_html(webview_t w, const char* html) {
webview_error_t webview_set_html(webview_t w, const char* html) {
static_cast<WebviewBrowserEngine*>(w)->set_html(html);
}

void webview_init(webview_t w, const char* js) {
webview_error_t webview_init(webview_t w, const char* js) {
static_cast<WebviewBrowserEngine*>(w)->init(js);
}

void webview_eval(webview_t w, const char* js) {
webview_error_t webview_eval(webview_t w, const char* js) {
static_cast<WebviewBrowserEngine*>(w)->eval(js);
}

void webview_bind(webview_t w, const char* name,
webview_error_t webview_bind(webview_t w, const char* name,
void (*fn)(const char* seq, const char* req,
void* arg),
void* arg) {
Expand All @@ -105,11 +105,11 @@ namespace webview_ffi {
arg);
}

void webview_unbind(webview_t w, const char* name) {
webview_error_t webview_unbind(webview_t w, const char* name) {
static_cast<WebviewBrowserEngine*>(w)->unbind(name);
}

void webview_return(webview_t w, const char* seq, int status,
webview_error_t webview_return(webview_t w, const char* seq, int status,
const char* result) {
static_cast<WebviewBrowserEngine*>(w)->resolve(seq, status, result);
}
Expand Down

0 comments on commit 44b2663

Please sign in to comment.