aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmin Mesbah <dev@aminmesbah.com>2019-06-24 22:30:40 -0700
committerAmin Mesbah <dev@aminmesbah.com>2019-06-24 22:30:40 -0700
commitdf85ab4a9c9c1f1f8344c8e75c0cb42d5f87670c (patch)
treec5b5df711f790edbc9092eca6e0508afac15c02b
parent15780ed658a7dc0f8f0bbc0f0d23af670d498415 (diff)
downloadtransparent-cube-df85ab4a9c9c1f1f8344c8e75c0cb42d5f87670c.zip
transparent-cube-df85ab4a9c9c1f1f8344c8e75c0cb42d5f87670c.tar.gz
Export functions via linker arguments
-rwxr-xr-xbuild_wasm.sh5
-rw-r--r--src/platform_wasm.c12
-rw-r--r--src/platform_wasm.h4
3 files changed, 10 insertions, 11 deletions
diff --git a/build_wasm.sh b/build_wasm.sh
index 112189a..48bf02a 100755
--- a/build_wasm.sh
+++ b/build_wasm.sh
@@ -33,9 +33,10 @@ wasm-ld \
--no-entry $wasm_dir/wasm.o \
-o $wasm_dir/binary.wasm \
-allow-undefined-file src/platform_wasm_js_symbols.txt \
- --export-all \
+ --export=init \
+ --export=render \
+ --export=window_resize \
--import-memory
rm $wasm_dir/*.o
rm $wasm_dir/*.bc
-rm src/*.bc
diff --git a/src/platform_wasm.c b/src/platform_wasm.c
index 6291582..5bd9ceb 100644
--- a/src/platform_wasm.c
+++ b/src/platform_wasm.c
@@ -2,11 +2,6 @@
#include "platform.h"
#include "platform_wasm.h"
-#define export __attribute__( ( visibility( "default" ) ) )
-
-char *js_read_entire_file(i32 file_path, i32 name_len, char *file_data);
-int js_print(i32 string, i32 len);
-
struct GameState g_game_state = {0};
i32 g_width = PLATFORM_SCR_WIDTH;
i32 g_height = PLATFORM_SCR_HEIGHT;
@@ -14,8 +9,7 @@ char g_mem_buffer[1000] = {0};
i32 g_mem_buffer_i = 0;
u32 time = 0;
-
-export bool init(void)
+bool init(void)
{
g_game_state.platform.platform_read_entire_file = &wasm_read_entire_file;
g_game_state.platform.platform_print = &wasm_print;
@@ -24,13 +18,13 @@ export bool init(void)
return true;
}
-export void render(void)
+void render(void)
{
time += 16;
game_update_and_render(&g_game_state, time/1000.0f, g_width, g_height);
}
-export void window_resize(int w, int h)
+void window_resize(int w, int h)
{
g_width = w;
g_height = h;
diff --git a/src/platform_wasm.h b/src/platform_wasm.h
index 4f1f6f4..7b03efb 100644
--- a/src/platform_wasm.h
+++ b/src/platform_wasm.h
@@ -4,3 +4,7 @@
PLATFORM_READ_ENTIRE_FILE(wasm_read_entire_file);
PLATFORM_PRINT(wasm_print);
PLATFORM_MEMORY_FREE(wasm_memory_free);
+
+// Functions implemented in the JS loader
+char *js_read_entire_file(i32 file_path, i32 name_len, char *file_data);
+int js_print(i32 string, i32 len);