1+ /*
2+ WebUI Library Extras
3+ https://webui.me
4+ https://github.com/webui-dev/webui
5+ Copyright (c) 2020-2025 Hassan Draga.
6+ Licensed under MIT License.
7+ All rights reserved.
8+ Canada.
9+ */
10+
11+ #ifndef _WEBUI_EXTENSIONS_H
12+ #define _WEBUI_EXTENSIONS_H
13+
14+ #ifdef __cplusplus
15+ extern "C" {
16+ #endif
17+
18+ /**
19+ * This is to help the compiler identify whether to compile the extensions API funtions or not
20+ * - If you are including the webui.c file to your source file directly,
21+ * and wish to use the extensions API functions,
22+ * please include this header file before including webui.c,
23+ * or define this macro manually before including webui.c
24+ * - In other cases, as long as the webui.c file is not included directly,
25+ * you might need to define this macro in your compiler settings
26+ */
27+ #ifndef WEBUI_EXTENSION_API
28+ #define WEBUI_EXTENSION_API
29+ #endif
30+
31+ #ifndef WEBUI_EXPORT
32+ #define WEBUI_EXPORT
33+ #warning "WEBUI_EXPORT not defined; Please include webui.h before webui_extensions.h"
34+ #endif
35+
36+ #include <stdbool.h>
37+ #include <stddef.h>
38+
39+ /**
40+ * @brief Construct a JavaScript string from a format string,
41+ * then execute it without waiting for the response. All clients.
42+ *
43+ * @param window The window number
44+ * @param fmt The JavaScript format string to be run
45+ *
46+ * @warning This function DOES NOT handle escape characters, proceed with caution.
47+ * For example, when passing string arguments that contain quotes or backslashes,
48+ * it may lead to unexpected behavior
49+ *
50+ * @note This function internally uses vsnprintf
51+ *
52+ * @example webui_run_fmt(myWindow, "alert('Hello %s');", "World");
53+ */
54+ WEBUI_EXPORT void webui_run_fmt (size_t window , const char * fmt , ...);
55+
56+ /**
57+ * @brief Construct a JavaScript string from a format string,
58+ * then execute it and get the response back. Work only in single client mode.
59+ * Make sure your local buffer can hold the response.
60+ *
61+ * @param window The window number
62+ * @param timeout The execution timeout in seconds
63+ * @param buffer The local buffer to hold the response
64+ * @param buffer_length The local buffer size
65+ * @param fmt The JavaScript format string to be run
66+ *
67+ * @return Returns True if there is no execution error
68+ *
69+ * @warning This function DOES NOT handle escape characters, proceed with caution.
70+ * For example, when passing string arguments that contain quotes or backslashes,
71+ * it may lead to unexpected behavior
72+ *
73+ * @note This function internally uses vsnprintf
74+ *
75+ * @example bool err = webui_script_fmt(myWindow, 0, myBuffer, myBufferSize,
76+ * "return %d + %d;", 4, 6);
77+ */
78+ WEBUI_EXPORT bool webui_script_fmt (size_t window , size_t timeout ,
79+ char * buffer , size_t buffer_length ,
80+ const char * fmt , ...);
81+
82+ #ifdef __cplusplus
83+ }
84+ #endif
85+
86+ #endif /*_WEBUI_EXTENSIONS_H */
0 commit comments