From d3c5885b7463f3019efdf2ee1fd9cdf7d85396fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 5 Jan 2018 21:58:55 +0100 Subject: Implement SDL_GetPlatform to get one more header done --- README.asciidoc | 2 +- c_src/esdl2.h | 2 ++ c_src/sdl_platform.c | 31 +++++++++++++++++++++++++++++++ ebin/esdl2.app | 2 +- src/esdl2.erl | 8 ++++++++ src/sdl_platform.erl | 21 +++++++++++++++++++++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 c_src/sdl_platform.c create mode 100644 src/sdl_platform.erl 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 +// +// 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 +%% +%% 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(). -- cgit v1.2.3