mirror of
https://github.com/webui-dev/webui
synced 2025-03-28 21:13:17 +00:00
Adding webui_interface_get_xxx_at
- Adding: webui_interface_get_string_at() - Adding: webui_interface_get_int_at() - Adding: webui_interface_get_bool_at() - Fix crash bug when script result is empty
This commit is contained in:
parent
058f082cd2
commit
c398d35dd0
@ -535,14 +535,19 @@ WEBUI_EXPORT size_t webui_interface_bind(size_t window, const char* element, voi
|
||||
// When using `webui_interface_bind()`, you may need this function to easily set your callback response.
|
||||
WEBUI_EXPORT void webui_interface_set_response(size_t window, size_t event_number, const char* response);
|
||||
|
||||
/**
|
||||
* @brief Check if the app still running.
|
||||
*
|
||||
* @example if (webui_interface_is_app_running()) ...
|
||||
*/
|
||||
// Check if the app still running.
|
||||
WEBUI_EXPORT bool webui_interface_is_app_running(void);
|
||||
|
||||
// Get a unique window ID.
|
||||
WEBUI_EXPORT size_t webui_interface_get_window_id(size_t window);
|
||||
|
||||
// Get an argument as string at a specific index
|
||||
WEBUI_EXPORT const char* webui_interface_get_string_at(size_t window, size_t event_number, size_t index);
|
||||
|
||||
// Get an argument as integer at a specific index
|
||||
WEBUI_EXPORT long long int webui_interface_get_int_at(size_t window, size_t event_number, size_t index);
|
||||
|
||||
// Get an argument as boolean at a specific index
|
||||
WEBUI_EXPORT bool webui_interface_get_bool_at(size_t window, size_t event_number, size_t index);
|
||||
|
||||
#endif /* _WEBUI_H */
|
||||
|
53
src/webui.c
53
src/webui.c
@ -1943,6 +1943,57 @@ static void _webui_interface_bind_handler(webui_event_t* e) {
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* webui_interface_get_string_at(size_t window, size_t event_number, size_t index) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_interface_get_string_at([%zu], [%zu], [%zu])...\n", window, event_number, index);
|
||||
#endif
|
||||
|
||||
// New Event
|
||||
webui_event_t e;
|
||||
e.window = window;
|
||||
e.event_type = 0;
|
||||
e.element = NULL;
|
||||
e.event_number = event_number;
|
||||
e.bind_id = 0;
|
||||
|
||||
return webui_get_string_at(&e, index);
|
||||
}
|
||||
|
||||
long long int webui_interface_get_int_at(size_t window, size_t event_number, size_t index) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_interface_get_int_at([%zu], [%zu], [%zu])...\n", window, event_number, index);
|
||||
#endif
|
||||
|
||||
// New Event
|
||||
webui_event_t e;
|
||||
e.window = window;
|
||||
e.event_type = 0;
|
||||
e.element = NULL;
|
||||
e.event_number = event_number;
|
||||
e.bind_id = 0;
|
||||
|
||||
return webui_get_int_at(&e, index);
|
||||
}
|
||||
|
||||
bool webui_interface_get_bool_at(size_t window, size_t event_number, size_t index) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_interface_get_bool_at([%zu], [%zu], [%zu])...\n", window, event_number, index);
|
||||
#endif
|
||||
|
||||
// New Event
|
||||
webui_event_t e;
|
||||
e.window = window;
|
||||
e.event_type = 0;
|
||||
e.element = NULL;
|
||||
e.event_number = event_number;
|
||||
e.bind_id = 0;
|
||||
|
||||
return webui_get_bool_at(&e, index);
|
||||
}
|
||||
|
||||
size_t webui_interface_bind(size_t window, const char* element, void (*func)(size_t, size_t, char*, size_t, size_t)) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
@ -6116,7 +6167,7 @@ static WEBUI_THREAD_RECEIVE
|
||||
else {
|
||||
|
||||
// Empty Result
|
||||
memcpy(_webui_core.run_userBuffer[packet_id], 0x00, 1);
|
||||
_webui_core.run_userBuffer[packet_id] = 0x00;
|
||||
}
|
||||
|
||||
// Send ready signal to webui_script()
|
||||
|
Loading…
x
Reference in New Issue
Block a user