[Commits] SDL: emscripten: Fixed compiling on C89 compilers.

libsdl.org revision control commits-owner at libsdl.org
Fri May 26 13:51:08 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/fcb1f3161d2e
changeset: 11034:fcb1f3161d2e
user:      Philipp Wiesemann <philipp.wiesemann at arcor.de>
date:      Fri May 26 22:45:40 2017 +0200
description:
emscripten: Fixed compiling on C89 compilers.

diffstat:

 src/audio/emscripten/SDL_emscriptenaudio.c  |   7 +++++--
 src/video/emscripten/SDL_emscriptenevents.c |  24 +++++++++++++++---------
 2 files changed, 20 insertions(+), 11 deletions(-)

diffs (104 lines):

diff -r 3b8bfd13c61f -r fcb1f3161d2e src/audio/emscripten/SDL_emscriptenaudio.c
--- a/src/audio/emscripten/SDL_emscriptenaudio.c	Thu May 25 23:01:59 2017 +0200
+++ b/src/audio/emscripten/SDL_emscriptenaudio.c	Fri May 26 22:45:40 2017 +0200
@@ -328,6 +328,9 @@
 static int
 EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
 {
+    int available;
+    int capture_available;
+
     /* Set the function pointers */
     impl->OpenDevice = EMSCRIPTENAUDIO_OpenDevice;
     impl->CloseDevice = EMSCRIPTENAUDIO_CloseDevice;
@@ -339,7 +342,7 @@
     impl->ProvidesOwnCallbackThread = 1;
 
     /* check availability */
-    const int available = EM_ASM_INT_V({
+    available = EM_ASM_INT_V({
         if (typeof(AudioContext) !== 'undefined') {
             return 1;
         } else if (typeof(webkitAudioContext) !== 'undefined') {
@@ -352,7 +355,7 @@
         SDL_SetError("No audio context available");
     }
 
-    const int capture_available = available && EM_ASM_INT_V({
+    capture_available = available && EM_ASM_INT_V({
         if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) {
             return 1;
         } else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') {
diff -r 3b8bfd13c61f -r fcb1f3161d2e src/video/emscripten/SDL_emscriptenevents.c
--- a/src/video/emscripten/SDL_emscriptenevents.c	Thu May 25 23:01:59 2017 +0200
+++ b/src/video/emscripten/SDL_emscriptenevents.c	Fri May 26 22:45:40 2017 +0200
@@ -490,6 +490,8 @@
 Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
 {
     Uint32 scancode;
+    SDL_bool prevent_default;
+    SDL_bool is_nav_key;
 
     /* .keyCode is deprecated, but still the most reliable way to get keys */
     if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
@@ -517,17 +519,17 @@
         }
     }
 
-    SDL_bool prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
+    prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
 
     /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
      * we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
      */
-    SDL_bool is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
-                          keyEvent->keyCode == 9 /* tab */ ||
-                          keyEvent->keyCode == 37 /* left */ ||
-                          keyEvent->keyCode == 38 /* up */ ||
-                          keyEvent->keyCode == 39 /* right */ ||
-                          keyEvent->keyCode == 40 /* down */;
+    is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
+                 keyEvent->keyCode == 9 /* tab */ ||
+                 keyEvent->keyCode == 37 /* left */ ||
+                 keyEvent->keyCode == 38 /* up */ ||
+                 keyEvent->keyCode == 39 /* right */ ||
+                 keyEvent->keyCode == 40 /* down */;
 
     if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE && !is_nav_key)
         prevent_default = SDL_FALSE;
@@ -629,6 +631,8 @@
 void
 Emscripten_RegisterEventHandlers(SDL_WindowData *data)
 {
+    const char *keyElement;
+
     /* There is only one window and that window is the canvas */
     emscripten_set_mousemove_callback("#canvas", data, 0, Emscripten_HandleMouseMove);
 
@@ -651,7 +655,7 @@
     emscripten_set_pointerlockchange_callback(NULL, data, 0, Emscripten_HandlePointerLockChange);
 
     /* Keyboard events are awkward */
-    const char *keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
+    keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
     if (!keyElement) keyElement = "#window";
 
     emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
@@ -668,6 +672,8 @@
 void
 Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
 {
+    const char *target;
+
     /* only works due to having one window */
     emscripten_set_mousemove_callback("#canvas", NULL, 0, NULL);
 
@@ -689,7 +695,7 @@
 
     emscripten_set_pointerlockchange_callback(NULL, NULL, 0, NULL);
 
-    const char *target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
+    target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
     if (!target) {
         target = "#window";
     }


More information about the commits mailing list