-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-intf.scm
128 lines (94 loc) · 3.4 KB
/
init-intf.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
;;
;; SDL App
;;
(c-define-type SDL_Window "SDL_Window")
(c-define-type SDL_GLContext "SDL_GLContext")
(define app:init (c-lambda () void "app_init"))
(define app:shutdown (c-lambda () void "app_shutdown"))
(define get-window-width (c-lambda () int "___return(_window_width);"))
(define get-window-height (c-lambda () int "___return(_window_height);"))
(define get-window-width (c-lambda () int "___return(_window_width);"))
(define get-window-height (c-lambda () int "___return(_window_height);"))
(define get-window-resolution-x (c-lambda () int "___return(_window_resolution_x);"))
(define get-window-resolution-y (c-lambda () int "___return(_window_resolution_y);"))
(define swap-window
(c-lambda () void "SDL_GL_SwapWindow(_window);"))
;;
;; Emscripten
;;
(cond-expand
(emscripten
(c-declare #<<c-declare-end
#include "emscripten.h"
c-declare-end
)
(define emscripten_set_main_loop_arg
(c-lambda ((nonnull-function ((pointer void #f)) void) (pointer void) int int)
void
"emscripten_set_main_loop_arg"))
;;;----------------------------------------------------------------------------
(define ##jseval
(c-lambda (char-string) char-string "emscripten_run_script_string"))
(define jseval ##jseval)
(define (##local-storage-get item)
(##jseval
(##string-append "localStorageGet(" (##object->string item) ");")))
(define (##local-storage-set item val)
(##jseval
(##string-append "localStorageSet(" (##object->string item) ","
(##object->string val) ");")))
;;;----------------------------------------------------------------------------
(define (##show-definition-of subject)
(let ((s
(cond ((##procedure? subject)
(##object->string (##procedure-name subject)))
(else
(##object->string subject)))))
(##jseval
(##string-append "open(\"http://www-labs.iro.umontreal.ca/~gambit/doc/gambit-c.html#"
(##escape-link (##string-append "Definition of " s))
"\")")))
(##void))
(set! ##help-hook ##show-definition-of)
(##c-declare #<<end-of-c-declare
void wget_file_onload(const char *file) {
// printf("wget_file_onload file=%s\n", file);
}
void wget_file_onerror(const char *file) {
// printf("wget_file_onerror file=%s\n", file);
}
void wget_file(const char *url, const char *file) {
emscripten_async_wget(url, file, wget_file_onload, wget_file_onerror);
}
end-of-c-declare
)
(define ##wget-file
(c-lambda (char-string char-string) void "wget_file")))
(else #!void))
;;
;; Nuklear GUI
;;
(c-define-type nk_context (struct "nk_context"))
(c-define-type nk_context* (pointer nk_context))
(c-define-type SDL_Event* (pointer (union "SDL_Event") #f))
(define gui:init
(c-lambda () nk_context* "gui_init"))
(define gui:render
(c-lambda () void "gui_render"))
(define gui:shutdown
(c-lambda () void "nk_sdl_shutdown"))
;;
;; App Events
;;
(c-define-type app_event (struct "app_event_t"))
(c-define-type app_event* (pointer app_event))
(define process-app-events
(c-lambda () void "process_app_events"))
(define clear-app-events
(c-lambda () void "clear_app_events"))
(define get-next-app-event
(c-lambda () app_event* "next_read_event"))
(define app-event-type
(c-lambda (app_event*) int "___return(___arg1->type);"))
(define app-event-data
(c-lambda (app_event*) char-string "___return(___arg1->data);"))