├── README.md
├── cl-webui.asd
├── examples
├── README.md
├── call-js-from-lisp.lisp
├── call-lisp-from-js.lisp
└── minimal.lisp
├── screenshots
└── demo-1.png
└── webui.lisp
/README.md:
--------------------------------------------------------------------------------
1 | # Overview
2 |
3 | Bindings for [webui](https://github.com/webui-dev/webui).
4 |
5 | ```lisp
6 | (let ((w (webui-new-window)))
7 | (webui-bind w "my-button"
8 | (lambda (event)
9 | (declare (ignore event))
10 | (webui-run w "alert(\"hi\");")))
11 | (webui-show w "
12 |
13 | Hello,
14 |
15 | ")
16 | (webui-wait))
17 | ```
18 |
19 | 
20 |
21 | # Setup
22 |
23 | I installed webui like this on Linux:
24 |
25 | ```bash
26 | git clone https://github.com/webui-dev/webui
27 | cd webui/
28 | make
29 | cp dist/webui-2.so /usr/lib/webui-2.so
30 | ```
31 |
32 | # Setup for mac
33 |
34 | ```bash
35 | git clone https://github.com/webui-dev/webui
36 | cd webui/
37 | make
38 | sudo cp dist/libwebui-2.dylib /usr/local/lib/libwebui-2.dylib
39 | ```
40 |
41 | Feel free to contribute ways to load webui for Windows.
42 |
--------------------------------------------------------------------------------
/cl-webui.asd:
--------------------------------------------------------------------------------
1 | (asdf:defsystem "cl-webui"
2 | :author "garlic0x1"
3 | :license "MIT"
4 | :depends-on (:cffi)
5 | :components ((:file "webui")))
6 |
7 | (asdf:defsystem "cl-webui/examples"
8 | :depends-on (:cffi :cl-webui :str :hiccl)
9 | :components ((:file "examples/minimal")
10 | (:file "examples/call-js-from-lisp")
11 | (:file "examples/call-lisp-from-js")))
12 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 | These programs are analogues to the ones in [webui/examples/c/](https://github.com/webui-dev/webui/tree/main/examples/C/)
4 |
5 | Run them like this:
6 |
7 | ```lisp
8 | (ql:quickload :cl-webui/examples)
9 | (webui/examples/call-js-from-lisp:run)
10 | ```
11 |
--------------------------------------------------------------------------------
/examples/call-js-from-lisp.lisp:
--------------------------------------------------------------------------------
1 | (defpackage :webui/examples/call-js-from-lisp
2 | (:use :cl :webui)
3 | (:export :run))
4 | (in-package :webui/examples/call-js-from-lisp)
5 |
6 | (defparameter *script* "
7 | let count = 0;
8 | function GetCount() { return count; }
9 | function SetCount(number) {
10 | document.getElementById('count').innerHTML = number;
11 | count = number;
12 | }
13 | function AutoTest(number) {
14 | setInterval(function(){ webui.call('MyButton1'); }, 10);
15 | }")
16 |
17 | (defparameter *html*
18 | (hiccl:render nil
19 | `(:html
20 | (:head
21 | (:script :src "webui.js")
22 | (:title "Call JavaScript from Lisp example"))
23 | (:body
24 | (:h1 "WebUI - Call JS from Lisp") (:br)
25 | (:h1 :id "count" "0") (:br)
26 | (:button :id "MyButton1" "Manual Count") (:br)
27 | (:button :id "MyTest" :onclick "AutoTest();" "Auto Count") (:br)
28 | (:button :id "MyButton2" "Exit")
29 | ;; boost engagement on x dot com
30 | (:img
31 | :src "https://i.redd.it/a6dxsn8dpsu61.png"
32 | :style "width: 200px; position: fixed; bottom: 10px; right: 10px;")
33 | (:script (:raw ,*script*))))))
34 |
35 | (defun run ()
36 | (let ((w (webui-new-window)))
37 | (webui-bind w "MyButton1"
38 | (lambda (ev)
39 | (let* ((w (webui-event-window ev))
40 | (c (webui-script w "return GetCount();"))
41 | (n (1+ (parse-integer c))))
42 | (webui-run w (format nil "SetCount(~a);" n)))))
43 | (webui-bind w "MyButton2"
44 | (lambda (ev)
45 | (declare (ignore ev))
46 | (webui-close w)))
47 | (webui-show w *html*)
48 | (webui-wait)
49 | (webui-destroy w)))
50 |
--------------------------------------------------------------------------------
/examples/call-lisp-from-js.lisp:
--------------------------------------------------------------------------------
1 | (defpackage :webui/examples/call-lisp-from-js
2 | (:use :cl :webui)
3 | (:export :run))
4 | (in-package :webui/examples/call-lisp-from-js)
5 |
6 | (defparameter *html*
7 | (hiccl:render nil
8 | `(:html
9 | (:head (:script :src "webui.js"))
10 | (:body
11 | (:h1 "WebUI - Call Lisp from JavaScript")
12 | (:p "C functions with arguments" (:em "See the logs in your terminal"))
13 | (:button :onclick "webui.call('MyID_One', 'hello', 'world');"
14 | "Strings")
15 | (:br)
16 | (:button :onclick "webui.call('MyID_Two', 123, 456, 789, 12345.6789);"
17 | "Numbers")
18 | (:br))
19 | (:script "const arr_size = 512 * 1000;
20 | const big_arr = new Uint8Array(arr_size);
21 | big_arr[0] = 0xA1;
22 | big_arr[arr_size - 1] = 0xA2;
23 | function MyJS() {
24 | const MyInput = document.getElementById('MyInputID');
25 | const number = MyInput.value;
26 | webui.call('MyID_Four', number, 2).then((response) => {
27 | MyInput.value = response;
28 | });
29 | }"))))
30 |
31 | (defun alert (w obj)
32 | (webui-run w "console.log('alerting');")
33 | (webui-run w (format nil "console.log(btoa('~a'));"
34 | (webui-encode (format nil "~a" obj))))
35 | (webui-run w (format nil "alert(btoa('~a'));"
36 | (webui-encode (format nil "~a" obj)))))
37 |
38 | (defun run ()
39 | (let ((w (webui-new-window)))
40 | (webui-bind w "MyID_One"
41 | (lambda (ev)
42 | (alert w (format nil "One: ~a, ~a~%"
43 | (webui-get-string ev) ;; first
44 | (webui-get-string-at ev 1)))))
45 | (webui-bind w "MyID_Two"
46 | (lambda (ev)
47 | (alert w (format nil
48 | "Two: c: ~a, a: ~a, b: ~a, c: ~a, f: ~a~%"
49 | nil ;; (webui-get-count ev)
50 | (webui-get-int ev) ;; first
51 | (webui-get-int-at ev 1)
52 | (webui-get-int-at ev 2)
53 | (webui-get-float-at ev 3)))))
54 | (webui-show w *html*)
55 | (webui-wait)
56 | (webui-destroy w)))
57 |
--------------------------------------------------------------------------------
/examples/minimal.lisp:
--------------------------------------------------------------------------------
1 | (defpackage :webui/examples/minimal
2 | (:use :cl :webui)
3 | (:export :run))
4 | (in-package :webui/examples/minimal)
5 |
6 | (defun run ()
7 | (let ((w (webui-new-window)))
8 | (webui-show w "Hello, world!")
9 | (webui-wait)))
10 |
--------------------------------------------------------------------------------
/screenshots/demo-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/garlic0x1/cl-webui/f5e4b4d098c1bd7c30759de2429ee5b809a890fd/screenshots/demo-1.png
--------------------------------------------------------------------------------
/webui.lisp:
--------------------------------------------------------------------------------
1 | (defpackage :webui
2 | (:use :cl :cffi)
3 | (:export :+webui-no-browser+
4 | :+webui-any-browser+
5 | :+webui-chrome+
6 | :+webui-firefox+
7 | :+webui-edge+
8 | :+webui-safari+
9 | :+webui-chromium+
10 | :+webui-opera+
11 | :+webui-brave+
12 | :+webui-vivaldi+
13 | :+webui-epic+
14 | :+webui-yandex+
15 | :+webui-chromium-based+
16 | :webui-event-t
17 | :webui-event-window
18 | :webui-event-event-type
19 | :webui-event-element-id
20 | :webui-event-event-number
21 | :webui-event-bind-id
22 | :webui-new-window
23 | :webui-new-window-id
24 | :webui-get-new-window-id
25 | :webui-bind
26 | :webui-show
27 | :webui-show-browser
28 | :webui-show-wv
29 | :webui-show-kiosk
30 | :webui-wait
31 | :webui-close
32 | :webui-destroy
33 | :webui-exit
34 | :webui-set-root-folder
35 | :webui-set-default-root-folder
36 | :webui-set-file-handler
37 | :webui-is-shown
38 | :webui-set-timeout
39 | :webui-set-icon
40 | :webui-encode
41 | :webui-decode
42 | :webui-free
43 | :webui-malloc
44 | :webui-send-raw
45 | :webui-set-hide
46 | :webui-set-size
47 | :webui-set-position
48 | :webui-set-profile
49 | :webui-set-proxy
50 | :webui-get-url
51 | :webui-set-public
52 | :webui-navigate
53 | :webui-clean
54 | :webui-delete-all-profiles
55 | :webui-delete-profile
56 | :webui-get-parent-process-id
57 | :webui-get-child-process-id
58 | :webui-set-port
59 | :webui-config
60 | :webui-set-tls-certificate
61 | :webui-run
62 | :webui-script
63 | :webui-set-runtime
64 | :webui-get-count
65 | :webui-get-int-at
66 | :webui-get-int
67 | :webui-get-float-at
68 | :webui-get-float
69 | :webui-get-string-at
70 | :webui-get-string
71 | :webui-get-bool-at
72 | :webui-get-bool
73 | :webui-get-size-at
74 | :webui-get-size
75 | :webui-return-int
76 | :webui-return-float
77 | :webui-return-string
78 | :webui-return-bool
79 | :webui-interface-bind
80 | :webui-interface-set-response
81 | :webui-interface-is-app-running
82 | :webui-interface-get-window-id
83 | :webui-interface-get-string-at
84 | :webui-interface-get-int-at
85 | :webui-interface-get-bool-at
86 | :webui-interface-get-size-at))
87 | (in-package :webui)
88 |
89 | (define-foreign-library libwebui
90 | (:darwin (:or "webui-2.dylib" "libwebui-2.dylib"))
91 | (:unix (:or "webui-2.so" "libwebui.so")))
92 |
93 | (use-foreign-library libwebui)
94 |
95 | (defctype size-t :unsigned-int)
96 |
97 | (defcenum webui-browsers
98 | +webui-no-browser+
99 | +webui-any-browser+
100 | +webui-chrome+
101 | +webui-firefox+
102 | +webui-edge+
103 | +webui-safari+
104 | +webui-chromium+
105 | +webui-opera+
106 | +webui-brave+
107 | +webui-vivaldi+
108 | +webui-epic+
109 | +webui-yandex+
110 | +webui-chromium-based+)
111 |
112 | (defcstruct webui-event-t
113 | (window size-t)
114 | (event-type :unsigned-int)
115 | (element-id :pointer)
116 | (event-number :unsigned-int)
117 | (bind-id :unsigned-int))
118 |
119 | (defun webui-event-window (self)
120 | (foreign-slot-value self '(:struct webui-event-t) 'window))
121 |
122 | (defun webui-event-event-type (self)
123 | (foreign-slot-value self '(:struct webui-event-t) 'event-type))
124 |
125 | (defun webui-event-element-id (self)
126 | (foreign-slot-value self '(:struct webui-event-t) 'element-id))
127 |
128 | (defun webui-event-event-number (self)
129 | (foreign-slot-value self '(:struct webui-event-t) 'event-number))
130 |
131 | (defun webui-event-bind-id (self)
132 | (foreign-slot-value self '(:struct webui-event-t) 'bind-id))
133 |
134 | (defcfun "webui_new_window" size-t
135 | "@brief Create a new WebUI window object.
136 |
137 | @return Returns the window number.
138 |
139 | @example size_t myWindow = webui_new_window();")
140 |
141 | (defcfun "webui_new_window_id" size-t
142 | "@brief Create a new webui window object using a specified window number.
143 |
144 | @param window_number The window number (should be > 0, and < WEBUI_MAX_IDS)
145 |
146 | @return Returns the window number.
147 |
148 | @example size_t myWindow = webui_new_window_id(123);"
149 | (window-number size-t))
150 |
151 | (defcfun "webui_get_new_window_id" size-t
152 | "@brief Get a free window number that can be used with
153 | `webui_new_window_id()`.
154 |
155 | @return Returns the first available free window number. Starting from 1.
156 |
157 | @example size_t myWindowNumber = webui_get_new_window_id();")
158 |
159 | (defmacro webui-bind (window element-id func)
160 | "@brief Bind a specific html element click event with a function. Empty
161 | element means all events.
162 |
163 | @param window The window number
164 | @param element The HTML ID
165 | @param func The callback function
166 |
167 | @return Returns a unique bind ID.
168 |
169 | @example webui_bind(myWindow, \"myID\", myFunction);"
170 | (let ((cb (gensym)))
171 | `(progn
172 | (defcallback ,cb :void ((event :pointer))
173 | (funcall ,func event))
174 | (foreign-funcall "webui_bind"
175 | size-t ,window
176 | :string ,element-id
177 | :pointer (callback ,cb)
178 | size-t))))
179 |
180 | (defcfun "webui_show" :bool
181 | "@brief Show a window using embedded HTML, or a file. If the window is already
182 | open, it will be refreshed.
183 |
184 | @param window The window number
185 | @param content The HTML, URL, Or a local file
186 |
187 | @return Returns True if showing the window is successed.
188 |
189 | @example webui_show(myWindow, \"...\"); | webui_show(myWindow,
190 | \"index.html\"); | webui_show(myWindow, \"http://...\");"
191 | (window size-t)
192 | (content :string))
193 |
194 | (defcfun "webui_show_browser" :bool
195 | "@brief Same as `webui_show()`. But using a specific web browser.
196 |
197 | @param window The window number
198 | @param content The HTML, Or a local file
199 | @param browser The web browser to be used
200 |
201 | @return Returns True if showing the window is successed.
202 |
203 | @example webui_show_browser(myWindow, \"...\", Chrome); |
204 | webui_show(myWindow, \"index.html\", Firefox);"
205 | (window size-t)
206 | (content :string)
207 | (browser size-t))
208 |
209 | (defcfun "webui_show_wv" :bool
210 | "@brief Show a WebView window using embedded HTML, or a file. If the window is already
211 | open, it will be refreshed. Note: Win32 need `WebView2Loader.dll`.
212 |
213 | @param window The window number
214 | @param content The HTML, URL, Or a local file
215 |
216 | @return Returns True if showing the WebView window is successed.
217 |
218 | @example webui_show_wv(myWindow, \"...\"); | webui_show_wv(myWindow,
219 | \"index.html\"); | webui_show_wv(myWindow, \"http://...\");"
220 | (window size-t)
221 | (content :string))
222 |
223 | (defcfun "webui_set_kiosk" :void
224 | "@brief Set the window in Kiosk mode (Full screen)
225 |
226 | @param window The window number
227 | @param status True or False
228 |
229 | @example webui_set_kiosk(myWindow, true);"
230 | (window size-t)
231 | (status :bool))
232 |
233 | (defcfun "webui_wait" :void
234 | "@brief Wait until all opened windows get closed.
235 |
236 | @example webui_wait(); ")
237 |
238 | (defcfun "webui_close" :void
239 | "@brief Close a specific window only. The window object will still exist.
240 |
241 | @param window The window number
242 |
243 | @example webui_close(myWindow);"
244 | (window size-t))
245 |
246 | (defcfun "webui_destroy" :void
247 | "@brief Close a specific window and free all memory resources.
248 |
249 | @param window The window number
250 |
251 | @example webui_destroy(myWindow);"
252 | (window size-t))
253 |
254 | (defcfun "webui_exit" :void
255 | "@brief Close all open windows. `webui_wait()` will return (Break).
256 |
257 | @example webui_exit();")
258 |
259 | (defcfun "webui_set_root_folder" :bool
260 | "@brief Set the web-server root folder path for a specific window.
261 |
262 | @param window The window number
263 | @param path The local folder full path
264 |
265 | @example webui_set_root_folder(myWindow, \"/home/Foo/Bar/\");"
266 | (window size-t)
267 | (path :string))
268 |
269 | (defcfun "webui_set_default_root_folder" :bool
270 | "@brief Set the web-server root folder path for all windows. Should be used
271 | before `webui_show()`.
272 |
273 | @param path The local folder full path
274 |
275 | @example webui_set_default_root_folder(\"/home/Foo/Bar/\");"
276 | (path :string))
277 |
278 | (defcfun "webui_set_file_handler" :void
279 | "@param window The window number
280 | @param handler The handler function: `void myHandler(const char* filename,
281 | int* length)`
282 |
283 | @return Returns a unique bind ID.
284 |
285 | @example webui_set_file_handler(myWindow, myHandlerFunction);"
286 | (window size-t)
287 | (handler :pointer))
288 |
289 | (defcfun "webui_is_shown" :bool
290 | "@brief Check if the specified window is still running.
291 |
292 | @param window The window number
293 |
294 | @example webui_is_shown(myWindow);"
295 | (window size-t))
296 |
297 | (defcfun "webui_set_timeout" :void
298 | "@brief Set the maximum time in seconds to wait for the browser to start.
299 |
300 | @param second The timeout in seconds
301 |
302 | @example webui_set_timeout(30);"
303 | (second size-t))
304 |
305 | (defcfun "webui_set_icon" :void
306 | "@brief Set the default embedded HTML favicon.
307 |
308 | @param window The window number
309 | @param icon The icon as string: ``
310 | @param icon_type The icon type: `image/svg+xml`
311 |
312 | @example webui_set_icon(myWindow, \"\", \"image/svg+xml\");"
313 | (window size-t)
314 | (icon :string)
315 | (icon-type :string))
316 |
317 | (defcfun "webui_encode" :string
318 | "@brief Base64 encoding. Use this to safely send text based data to the UI. If
319 | it fails it will return NULL.
320 |
321 | @param str The string to encode (Should be null terminated)
322 |
323 | @example webui_encode(\"Hello\");"
324 | (str :string))
325 |
326 | (defcfun "webui_decode" :string
327 | "@brief Base64 decoding. Use this to safely decode received Base64 text from
328 | the UI. If it fails it will return NULL.
329 |
330 | @param str The string to decode (Should be null terminated)
331 |
332 | @example webui_decode(\"SGVsbG8=\");"
333 | (str :string))
334 |
335 | (defcfun "webui_free" :void
336 | "@brief Safely free a buffer allocated by WebUI using `webui_malloc()`.
337 |
338 | @param ptr The buffer to be freed
339 |
340 | @example webui_free(myBuffer);"
341 | (ptr :pointer))
342 |
343 | (defcfun "webui_malloc" :pointer
344 | "@brief Safely allocate memory using the WebUI memory management system. It
345 | can be safely freed using `webui_free()` at any time.
346 |
347 | @param size The size of memory in bytes
348 |
349 | @example char* myBuffer = (char*)webui_malloc(1024);"
350 | (size size-t))
351 |
352 | (defcfun "webui_send_raw" :void
353 | "@brief Safely send raw data to the UI.
354 |
355 | @param window The window number
356 | @param function The JavaScript function to receive raw data: `function
357 | myFunc(myData){}`
358 | @param raw The raw data buffer
359 | @param size The raw data size in bytes
360 |
361 | @example webui_send_raw(myWindow, \"myJavascriptFunction\", myBuffer, 64);"
362 | (window size-t)
363 | (func :string)
364 | (raw :pointer)
365 | (size size-t))
366 |
367 | (defcfun "webui_set_hide" :void
368 | "@brief Set a window in hidden mode. Should be called before `webui_show()`.
369 |
370 | @param window The window number
371 | @param status The status: True or False
372 |
373 | @example webui_set_hide(myWindow, True);"
374 | (window size-t)
375 | (status :bool))
376 |
377 | (defcfun "webui_set_size" :void
378 | "@brief Set the window size.
379 |
380 | @param window The window number
381 | @param width The window width
382 | @param height The window height
383 |
384 | @example webui_set_size(myWindow, 800, 600);"
385 | (window size-t)
386 | (width :unsigned-int)
387 | (height :unsigned-int))
388 |
389 | (defcfun "webui_set_position" :void
390 | "@brief Set the window position.
391 |
392 | @param window The window number
393 | @param x The window X
394 | @param y The window Y
395 |
396 | @example webui_set_position(myWindow, 100, 100);"
397 | (window size-t)
398 | (x :unsigned-int)
399 | (y :unsigned-int))
400 |
401 | (defcfun "webui_set_profile" :void
402 | "@brief Set the web browser profile to use. An empty `name` and `path` means
403 | the default user profile. Need to be called before `webui_show()`.
404 |
405 | @param window The window number
406 | @param name The web browser profile name
407 | @param path The web browser profile full path
408 |
409 | @example webui_set_profile(myWindow, \"Bar\", \"/Home/Foo/Bar\"); |
410 | webui_set_profile(myWindow, \"\", \"\");"
411 | (window size-t)
412 | (name :string)
413 | (path :string))
414 |
415 | (defcfun "webui_set_proxy" :void
416 | "@brief Set the web browser proxy_server to use. Need to be called before `webui_show()`.
417 |
418 | @param window The window number
419 | @param proxy_server The web browser proxy_server
420 |
421 | @example webui_set_proxy(myWindow, \"http://127.0.0.1:8888\");"
422 | (window size-t)
423 | (proxy-server :string))
424 |
425 | (defcfun "webui_get_url" :string
426 | "@brief Get the full current URL.
427 |
428 | @param window The window number
429 |
430 | @return Returns the full URL string
431 |
432 | @example const char* url = webui_get_url(myWindow);"
433 | (window size-t))
434 |
435 | (defcfun "webui_set_public" :void
436 | "@brief Allow a specific window address to be accessible from a public network
437 |
438 | @param window The window number
439 | @param status True or False
440 |
441 | @example webui_set_public(myWindow, true);"
442 | (window size-t)
443 | (status :bool))
444 |
445 | (defcfun "webui_navigate" :void
446 | "@brief Navigate to a specific URL
447 |
448 | @param window The window number
449 | @param url Full HTTP URL
450 |
451 | @example webui_navigate(myWindow, \"http://domain.com\");"
452 | (window size-t)
453 | (url :string))
454 |
455 | (defcfun "webui_clean" :void
456 | "@brief Free all memory resources. Should be called only at the end.
457 |
458 | @example
459 | webui_wait();
460 | webui_clean();")
461 |
462 | (defcfun "webui_delete_all_profiles" :void
463 | "@brief Delete all local web-browser profiles folder. It should called at the
464 | end.
465 |
466 | @example
467 | webui_wait();
468 | webui_delete_all_profiles();
469 | webui_clean();")
470 |
471 | (defcfun "webui_delete_profile" :void
472 | "@brief Delete a specific window web-browser local folder profile.
473 |
474 | @param window The window number
475 |
476 | @example
477 | webui_wait();
478 | webui_delete_profile(myWindow);
479 | webui_clean();
480 |
481 | @note This can break functionality of other windows if using the same
482 | web-browser."
483 | (window size-t))
484 |
485 | (defcfun "webui_get_parent_process_id" size-t
486 | "@brief Get the ID of the parent process (The web browser may re-create
487 | another new process).
488 |
489 | @param window The window number
490 |
491 | @return Returns the the parent process id as integer
492 |
493 | @example size_t id = webui_get_parent_process_id(myWindow);"
494 | (window size-t))
495 |
496 | (defcfun "webui_get_child_process_id" size-t
497 | "@brief Get the ID of the last child process.
498 |
499 | @param window The window number
500 |
501 | @return Returns the the child process id as integer
502 |
503 | @example size_t id = webui_get_child_process_id(myWindow);"
504 | (window size-t))
505 |
506 | (defcfun "webui_set_port" :bool
507 | "@brief Set a custom web-server network port to be used by WebUI.
508 | This can be useful to determine the HTTP link of `webui.js` in case
509 | you are trying to use WebUI with an external web-server like NGNIX
510 |
511 | @param window The window number
512 | @param port The web-server network port WebUI should use
513 |
514 | @return Returns True if the port is free and usable by WebUI
515 |
516 | @example bool ret = webui_set_port(myWindow, 8080);"
517 | (window size-t)
518 | (port size-t))
519 |
520 | (defcfun "webui_config" :void
521 | "@brief Control the WebUI behaviour. It's better to call at the beginning.
522 |
523 | @param option The desired option from `webui_configs` enum
524 | @param status The status of the option, `true` or `false`
525 |
526 | @example webui_config(show_wait_connection, false);"
527 | (option :int)
528 | (status :bool))
529 |
530 | (defcfun "webui_set_tls_certificate" :bool
531 | "@brief Set the SSL/TLS certificate and the private key content, both in PEM
532 | format. This works only with `webui-2-secure` library. If set empty WebUI
533 | will generate a self-signed certificate.
534 |
535 | @param certificate_pem The SSL/TLS certificate content in PEM format
536 | @param private_key_pem The private key content in PEM format
537 |
538 | @return Returns True if the certificate and the key are valid.
539 |
540 | @example bool ret = webui_set_tls_certificate(\"-----BEGIN
541 | CERTIFICATE-----\n...\", \"-----BEGIN PRIVATE KEY-----\n...\");"
542 | (cert-pem :string)
543 | (private-key-pem :string))
544 |
545 | (defcfun "webui_run" :void
546 | "@brief Run JavaScript without waiting for the response.
547 |
548 | @param window The window number
549 | @param script The JavaScript to be run
550 |
551 | @example webui_run(myWindow, \"alert('Hello');\");"
552 | (window size-t)
553 | (script :string))
554 |
555 | (defun webui-script (window script &key (timeout 60000) (max-len 1024))
556 | "@brief Run JavaScript and get the response back.
557 | Make sure your local buffer can hold the response.
558 |
559 | @param window The window number
560 | @param script The JavaScript to be run
561 | @param timeout The execution timeout
562 | @param buffer The local buffer to hold the response
563 | @param buffer_length The local buffer size
564 |
565 | @return Returns True if there is no execution error
566 |
567 | @example bool err = webui_script(myWindow, \"return 4 + 6;\", 0, myBuffer, myBufferSize);"
568 | (with-foreign-pointer-as-string (result max-len)
569 | (unless (foreign-funcall "webui_script"
570 | size-t window
571 | :string script
572 | size-t timeout
573 | :pointer result
574 | size-t max-len
575 | :bool)
576 | (error (format nil "Failed to run script: ~a" script)))))
577 |
578 | (defcfun "webui_set_runtime" :void
579 | "@brief Chose between Deno and Nodejs as runtime for .js and .ts files.
580 |
581 | @param window The window number
582 | @param runtime Deno | Nodejs
583 |
584 | @example webui_set_runtime(myWindow, Deno);"
585 | (window size-t)
586 | (runtime size-t))
587 |
588 | (defcfun "webui_get_count" size-t
589 | "@brief Get how many arguments there are in an event.
590 |
591 | @param e The event struct
592 |
593 | @return Returns the arguments count.
594 |
595 | @example size_t count = webui_get_count(e);"
596 | (event :pointer))
597 |
598 | (defcfun "webui_get_int_at" :uint64
599 | "@brief Get an argument as integer at a specific index
600 |
601 | @param e The event struct
602 | @param index The argument position starting from 0
603 |
604 | @return Returns argument as integer
605 |
606 | @example long long int myNum = webui_get_int_at(e, 0);"
607 | (event :pointer)
608 | (index size-t))
609 |
610 | (defcfun "webui_get_int" :uint64
611 | "@brief Get the first argument as integer
612 |
613 | @param e The event struct
614 |
615 | @return Returns argument as integer
616 |
617 | @example long long int myNum = webui_get_int(e);"
618 | (event :pointer))
619 |
620 | (defcfun "webui_get_float_at" :double
621 | "@brief Get an argument as float at a specific index
622 |
623 | @param e The event struct
624 | @param index The argument position starting from 0
625 |
626 | @return Returns argument as float
627 |
628 | @example double myNum = webui_get_float_at(e, 0);"
629 | (event :pointer)
630 | (index size-t))
631 |
632 | (defcfun "webui_get_float" :double
633 | "@brief Get the first argument as float
634 |
635 | @param e The event struct
636 |
637 | @return Returns argument as float
638 |
639 | @example double myNum = webui_get_float(e);"
640 | (event :pointer))
641 |
642 | (defcfun "webui_get_string_at" :string
643 | "@brief Get an argument as string at a specific index
644 |
645 | @param e The event struct
646 | @param index The argument position starting from 0
647 |
648 | @return Returns argument as string
649 |
650 | @example const char* myStr = webui_get_string_at(e, 0);"
651 | (event :pointer)
652 | (index size-t))
653 |
654 | (defcfun "webui_get_string" :string
655 | "@brief Get the first argument as string
656 |
657 | @param e The event struct
658 |
659 | @return Returns argument as string
660 |
661 | @example const char* myStr = webui_get_string(e);"
662 | (event :pointer))
663 |
664 | (defcfun "webui_get_bool_at" :bool
665 | "@brief Get an argument as boolean at a specific index
666 |
667 | @param e The event struct
668 | @param index The argument position starting from 0
669 |
670 | @return Returns argument as boolean
671 |
672 | @example bool myBool = webui_get_bool_at(e, 0);"
673 | (event :pointer)
674 | (index size-t))
675 |
676 | (defcfun "webui_get_bool" :bool
677 | "@brief Get the first argument as boolean
678 |
679 | @param e The event struct
680 |
681 | @return Returns argument as boolean
682 |
683 | @example bool myBool = webui_get_bool(e);"
684 | (event :pointer))
685 |
686 | (defcfun "webui_get_size_at" size-t
687 | "@brief Get the size in bytes of an argument at a specific index
688 |
689 | @param e The event struct
690 | @param index The argument position starting from 0
691 |
692 | @return Returns size in bytes
693 |
694 | @example size_t argLen = webui_get_size_at(e, 0);"
695 | (event :pointer)
696 | (index size-t))
697 |
698 | (defcfun "webui_get_size" size-t
699 | "@brief Get size in bytes of the first argument
700 |
701 | @param e The event struct
702 |
703 | @return Returns size in bytes
704 |
705 | @example size_t argLen = webui_get_size(e);"
706 | (event :pointer))
707 |
708 | (defcfun "webui_return_int" :void
709 | "@brief Return the response to JavaScript as integer.
710 |
711 | @param e The event struct
712 | @param n The integer to be send to JavaScript
713 |
714 | @example webui_return_int(e, 123);"
715 | (event :pointer)
716 | (n :uint64))
717 |
718 | (defcfun "webui_return_float" :void
719 | "@brief Return the response to JavaScript as float.
720 |
721 | @param e The event struct
722 | @param n The float to be send to JavaScript
723 |
724 | @example webui_return_float(e, 123.321);"
725 | (event :pointer)
726 | (f :double))
727 |
728 | (defcfun "webui_return_string" :void
729 | "@brief Return the response to JavaScript as string.
730 |
731 | @param e The event struct
732 | @param n The string to be send to JavaScript
733 |
734 | @example webui_return_string(e, \"Response...\");"
735 | (event :pointer)
736 | (str :string))
737 |
738 | (defcfun "webui_return_bool" :void
739 | "@brief Return the response to JavaScript as boolean.
740 |
741 | @param e The event struct
742 | @param n The boolean to be send to JavaScript
743 |
744 | @example webui_return_bool(e, true);"
745 | (event :pointer)
746 | (bool :bool))
747 |
748 | (defun webui-interface-bind (window element func)
749 | "@brief Bind a specific HTML element click event with a function. Empty element means all events.
750 |
751 | @param window The window number
752 | @param element The element ID
753 | @param func The callback as myFunc(Window, EventType, Element, EventNumber, BindID)
754 |
755 | @return Returns unique bind ID
756 |
757 | @example size_t id = webui_interface_bind(myWindow, \"myID\", myCallback);"
758 | (defcallback cb :void ((window size-t)
759 | (event-type :unsigned-int)
760 | (element :pointer)
761 | (event-number :unsigned-int)
762 | (bind-id :unsigned-int))
763 | (funcall func window event-type element event-number bind-id))
764 | (foreign-funcall "webui_interface_bind"
765 | size-t window
766 | :string element
767 | :pointer (callback cb)
768 | size-t))
769 |
770 | (defcfun "webui_interface_set_response" :void
771 | "@brief When using `webui_interface_bind()`, you may need this function to easily set a response.
772 |
773 | @param window The window number
774 | @param event_number The event number
775 | @param response The response as string to be send to JavaScript
776 |
777 | @example webui_interface_set_response(myWindow, e->event_number, \"Response...\");"
778 | (window size-t)
779 | (event-number size-t)
780 | (response :string))
781 |
782 | (defcfun "webui_interface_is_app_running" :bool
783 | "@brief Check if the app still running.
784 |
785 | @return Returns True if app is running
786 |
787 | @example bool status = webui_interface_is_app_running();")
788 |
789 | (defcfun "webui_interface_get_window_id" size-t
790 | "@brief Get a unique window ID.
791 |
792 | @param window The window number
793 |
794 | @return Returns the unique window ID as integer
795 |
796 | @example size_t id = webui_interface_get_window_id(myWindow);"
797 | (window size-t))
798 |
799 | (defcfun "webui_interface_get_string_at" :string
800 | "@brief Get an argument as string at a specific index
801 |
802 | @param window The window number
803 | @param event_number The event number
804 | @param index The argument position
805 |
806 | @return Returns argument as string
807 |
808 | @example const char* myStr = webui_interface_get_string_at(myWindow, e->event_number, 0);"
809 | (window size-t)
810 | (event-number size-t)
811 | (index size-t))
812 |
813 | (defcfun "webui_interface_get_int_at" :uint64
814 | "@brief Get an argument as integer at a specific index
815 |
816 | @param window The window number
817 | @param event_number The event number
818 | @param index The argument position
819 |
820 | @return Returns argument as integer
821 |
822 | @example long long int myNum = webui_interface_get_int_at(myWindow, e->event_number, 0);"
823 | (window size-t)
824 | (event-number size-t)
825 | (index size-t))
826 |
827 | (defcfun "webui_interface_get_bool_at" :bool
828 | "@brief Get an argument as boolean at a specific index
829 |
830 | @param window The window number
831 | @param event_number The event number
832 | @param index The argument position
833 |
834 | @return Returns argument as boolean
835 |
836 | @example bool myBool = webui_interface_get_bool_at(myWindow, e->event_number, 0);"
837 | (window size-t)
838 | (event-number size-t)
839 | (index size-t))
840 |
841 | (defcfun "webui_interface_get_size_at" size-t
842 | "@brief Get the size in bytes of an argument at a specific index
843 |
844 | @param window The window number
845 | @param event_number The event number
846 | @param index The argument position
847 |
848 | @return Returns size in bytes
849 |
850 | @example size_t argLen = webui_interface_get_size_at(myWindow, e->event_number, 0);"
851 | (window size-t)
852 | (event-number size-t)
853 | (index size-t))
854 |
--------------------------------------------------------------------------------