mirror of
https://github.com/webui-dev/webui.git
synced 2024-09-11 22:17:13 +03:00
Adding webui_get_count
This commit is contained in:
parent
19234368ba
commit
19b2e32394
@ -624,6 +624,17 @@ WEBUI_EXPORT bool webui_script(size_t window, const char* script, size_t timeout
|
||||
*/
|
||||
WEBUI_EXPORT void webui_set_runtime(size_t window, size_t runtime);
|
||||
|
||||
/**
|
||||
* @brief Get how many arguments there are in an event.
|
||||
*
|
||||
* @param e The event struct
|
||||
*
|
||||
* @return Returns the arguments count.
|
||||
*
|
||||
* @example size_t count = webui_get_count(e);
|
||||
*/
|
||||
WEBUI_EXPORT size_t webui_get_count(webui_event_t* e);
|
||||
|
||||
/**
|
||||
* @brief Get an argument as integer at a specific index
|
||||
*
|
||||
|
27
src/webui.c
27
src/webui.c
@ -139,6 +139,7 @@ typedef struct webui_event_inf_t {
|
||||
char* event_data[WEBUI_MAX_ARG + 1]; // Event data (string | num | bool | raw)
|
||||
size_t event_size[WEBUI_MAX_ARG + 1]; // Event data size (in bytes)
|
||||
char* response; // Event response (string)
|
||||
size_t count;
|
||||
} webui_event_inf_t;
|
||||
|
||||
// WebView
|
||||
@ -1436,6 +1437,28 @@ const char* webui_get_string_at(webui_event_t* e, size_t index) {
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t webui_get_count(webui_event_t* e) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_get_count()\n");
|
||||
#endif
|
||||
|
||||
// Initialization
|
||||
_webui_init();
|
||||
|
||||
// Dereference
|
||||
if (_webui_mutex_is_exit_now(WEBUI_MUTEX_NONE) || _webui_core.wins[e->window] == NULL)
|
||||
return 0;
|
||||
_webui_window_t * win = _webui_core.wins[e->window];
|
||||
|
||||
// Get event inf
|
||||
webui_event_inf_t* event_inf = win->events[e->event_number];
|
||||
if (event_inf == NULL)
|
||||
return 0;
|
||||
|
||||
return event_inf->count;
|
||||
}
|
||||
|
||||
long long int webui_get_int_at(webui_event_t* e, size_t index) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
@ -8160,8 +8183,10 @@ static WEBUI_THREAD_RECEIVE {
|
||||
#endif
|
||||
|
||||
args_ptr = args_ptr + (arg_len + 1);
|
||||
token_num++;
|
||||
token = strtok(NULL, ";");
|
||||
|
||||
// Save total found arguments
|
||||
event_inf->count = ++token_num;
|
||||
}
|
||||
|
||||
// Check data validity
|
||||
|
Loading…
Reference in New Issue
Block a user