aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-01-05 21:58:55 +0100
committerLoïc Hoguin <[email protected]>2018-01-05 21:58:55 +0100
commitd3c5885b7463f3019efdf2ee1fd9cdf7d85396fe (patch)
tree2854279a88ce8c2be99739216edd10b0e36b6b5b
parent30cd5551c4cdc7a2d9bbc92dfbc0313764d2bdad (diff)
downloadesdl2-d3c5885b7463f3019efdf2ee1fd9cdf7d85396fe.tar.gz
esdl2-d3c5885b7463f3019efdf2ee1fd9cdf7d85396fe.tar.bz2
esdl2-d3c5885b7463f3019efdf2ee1fd9cdf7d85396fe.zip
Implement SDL_GetPlatform to get one more header done
-rw-r--r--README.asciidoc2
-rw-r--r--c_src/esdl2.h2
-rw-r--r--c_src/sdl_platform.c31
-rw-r--r--ebin/esdl2.app2
-rw-r--r--src/esdl2.erl8
-rw-r--r--src/sdl_platform.erl21
6 files changed, 64 insertions, 2 deletions
diff --git a/README.asciidoc b/README.asciidoc
index a52dc35..dbd6943 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -15,6 +15,7 @@ corresponding to the public headers.
* 'SDL_keyboard.h'
* 'SDL_keycode.h'
* 'SDL_mouse.h'
+* 'SDL_platform.h'
* 'SDL_power.h'
* 'SDL_scancode.h'
@@ -154,7 +155,6 @@ corresponding to the public headers.
* 'SDL_joystick.h'
* 'SDL_messagebox.h'
* 'SDL_pixels.h'
-* 'SDL_platform.h'
* 'SDL_rwops.h' (unclear if we need it)
* 'SDL_shape.h'
* 'SDL_system.h'
diff --git a/c_src/esdl2.h b/c_src/esdl2.h
index 31a1fcc..a9cf3f4 100644
--- a/c_src/esdl2.h
+++ b/c_src/esdl2.h
@@ -295,6 +295,8 @@
F(set_relative_mouse_mode, 1) \
F(warp_mouse_global, 2) \
F(warp_mouse_in_window, 3) \
+ /* sdl_platform */ \
+ F(get_platform, 0) \
/* sdl_power */ \
F(get_power_info, 0) \
/* sdl_renderer */ \
diff --git a/c_src/sdl_platform.c b/c_src/sdl_platform.c
new file mode 100644
index 0000000..d51be0c
--- /dev/null
+++ b/c_src/sdl_platform.c
@@ -0,0 +1,31 @@
+// Copyright (c) 2018, Loïc Hoguin <[email protected]>
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+#include "esdl2.h"
+
+// get_platform
+
+NIF_FUNCTION(get_platform)
+{
+ const char* platform;
+ ErlNifBinary bin;
+
+ platform = SDL_GetPlatform();
+
+ enif_alloc_binary(strlen(platform), &bin);
+
+ memcpy(bin.data, platform, bin.size);
+
+ return enif_make_binary(env, &bin);
+}
diff --git a/ebin/esdl2.app b/ebin/esdl2.app
index e4b849b..093aeae 100644
--- a/ebin/esdl2.app
+++ b/ebin/esdl2.app
@@ -1,7 +1,7 @@
{application, 'esdl2', [
{description, "SDL2 Erlang NIF."},
{vsn, "0.1.0"},
- {modules, ['esdl2','esdl2_app','esdl2_callbacks','esdl2_sup','sdl','sdl_blend_mode','sdl_clipboard','sdl_cpu_info','sdl_cursor','sdl_events','sdl_filesystem','sdl_gl','sdl_hints','sdl_keyboard','sdl_keycode','sdl_mouse','sdl_power','sdl_rect','sdl_renderer','sdl_surface','sdl_texture','sdl_version','sdl_window']},
+ {modules, ['esdl2','esdl2_app','esdl2_callbacks','esdl2_sup','sdl','sdl_blend_mode','sdl_clipboard','sdl_cpu_info','sdl_cursor','sdl_events','sdl_filesystem','sdl_gl','sdl_hints','sdl_keyboard','sdl_keycode','sdl_mouse','sdl_platform','sdl_power','sdl_rect','sdl_renderer','sdl_surface','sdl_texture','sdl_version','sdl_window']},
{registered, [esdl2_sup]},
{applications, [kernel,stdlib]},
{mod, {esdl2_app, []}},
diff --git a/src/esdl2.erl b/src/esdl2.erl
index 0a76f25..f46ef23 100644
--- a/src/esdl2.erl
+++ b/src/esdl2.erl
@@ -108,6 +108,9 @@
-export([warp_mouse_global/2]).
-export([warp_mouse_in_window/3]).
+%% sdl_platform
+-export([get_platform/0]).
+
%% sdl_power
-export([get_power_info/0]).
@@ -433,6 +436,11 @@ warp_mouse_global(_, _) ->
warp_mouse_in_window(_, _, _) ->
erlang:nif_error({not_loaded, ?MODULE}).
+%% sdl_platform
+
+get_platform() ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
%% sdl_power
get_power_info() ->
diff --git a/src/sdl_platform.erl b/src/sdl_platform.erl
new file mode 100644
index 0000000..6a958bf
--- /dev/null
+++ b/src/sdl_platform.erl
@@ -0,0 +1,21 @@
+%% Copyright (c) 2018, Loïc Hoguin <[email protected]>
+%%
+%% Permission to use, copy, modify, and/or distribute this software for any
+%% purpose with or without fee is hereby granted, provided that the above
+%% copyright notice and this permission notice appear in all copies.
+%%
+%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+-module(sdl_platform).
+
+-export([get/0]).
+
+-spec get() -> binary().
+get() ->
+ esdl2:get_platform().