mirror of
https://github.com/webui-dev/webui.git
synced 2024-09-11 22:17:13 +03:00
Adding webui_get_float
This commit is contained in:
parent
8d94cdcae8
commit
9c9b3dc00a
@ -647,6 +647,29 @@ WEBUI_EXPORT long long int webui_get_int_at(webui_event_t* e, size_t index);
|
||||
*/
|
||||
WEBUI_EXPORT long long int webui_get_int(webui_event_t* e);
|
||||
|
||||
/**
|
||||
* @brief Get an argument as float at a specific index
|
||||
*
|
||||
* @param e The event struct
|
||||
* @param index The argument position starting from 0
|
||||
*
|
||||
* @return Returns argument as float
|
||||
*
|
||||
* @example double myNum = webui_get_float_at(e, 0);
|
||||
*/
|
||||
WEBUI_EXPORT double webui_get_float_at(webui_event_t* e, size_t index);
|
||||
|
||||
/**
|
||||
* @brief Get the first argument as float
|
||||
*
|
||||
* @param e The event struct
|
||||
*
|
||||
* @return Returns argument as float
|
||||
*
|
||||
* @example double myNum = webui_get_float(e);
|
||||
*/
|
||||
WEBUI_EXPORT double webui_get_float(webui_event_t* e);
|
||||
|
||||
/**
|
||||
* @brief Get an argument as string at a specific index
|
||||
*
|
||||
|
35
src/webui.c
35
src/webui.c
@ -1462,6 +1462,32 @@ long long int webui_get_int_at(webui_event_t* e, size_t index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double webui_get_float_at(webui_event_t* e, size_t index) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_get_float_at([%zu])\n", index);
|
||||
#endif
|
||||
|
||||
// Initialization & Dereference
|
||||
// are done by webui_get_string()
|
||||
|
||||
if (index > WEBUI_MAX_ARG)
|
||||
return 0.0;
|
||||
|
||||
const char* str = webui_get_string_at(e, index);
|
||||
if (str == NULL)
|
||||
return 0.0;
|
||||
|
||||
size_t len = _webui_strlen(str);
|
||||
if (len > 0 && len <= 20) {
|
||||
// 64-bit max is -9,223,372,036,854,775,808 (20 character)
|
||||
char* endptr;
|
||||
return strtod(str, &endptr);
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
bool webui_get_bool_at(webui_event_t* e, size_t index) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
@ -1527,6 +1553,15 @@ long long int webui_get_int(webui_event_t* e) {
|
||||
return webui_get_int_at(e, 0);
|
||||
}
|
||||
|
||||
double webui_get_float(webui_event_t* e) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_get_float()\n");
|
||||
#endif
|
||||
|
||||
return webui_get_float_at(e, 0);
|
||||
}
|
||||
|
||||
bool webui_get_bool(webui_event_t* e) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
|
Loading…
Reference in New Issue
Block a user