diff options
author | Loïc Hoguin <[email protected]> | 2015-10-21 03:41:03 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2015-10-21 03:41:03 +0200 |
commit | 276a44441d8795cd29a215dff35ab6aefcdc6557 (patch) | |
tree | b9d949f8ac4669637db97474974f27111c6a6849 /src/sdl.erl | |
parent | cdaf2699bcb6aa0db3440b1d5906f3031e50b2ac (diff) | |
download | esdl2-276a44441d8795cd29a215dff35ab6aefcdc6557.tar.gz esdl2-276a44441d8795cd29a215dff35ab6aefcdc6557.tar.bz2 esdl2-276a44441d8795cd29a215dff35ab6aefcdc6557.zip |
Add sdl_hints:add_callback/3 function
This also sets up esdl2 to start accepting callbacks.
The module/process esdl2_callbacks must always be running
for that purpose, so esdl2 was made an OTP application
instead of a simple library.
Implementation of the rest of SDL_hints will follow in
subsequent commits.
Diffstat (limited to 'src/sdl.erl')
-rw-r--r-- | src/sdl.erl | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/sdl.erl b/src/sdl.erl index 5391d32..8706eff 100644 --- a/src/sdl.erl +++ b/src/sdl.erl @@ -33,10 +33,25 @@ start() -> start([]). --spec start([subsystem()]) -> ok | error(). +-spec start([subsystem()]) -> ok | {application_start_error, term()} | error(). start(Subsystems) -> - esdl2:init(Subsystems), - receive {'_nif_thread_ret_', Ret} -> Ret end. + case ensure_started() of + ok -> + esdl2:init(Subsystems), + receive {'_nif_thread_ret_', Ret} -> Ret end; + Error -> + Error + end. + +ensure_started() -> + case application:start(esdl2) of + ok -> + ok; + {error, {already_started, esdl2}} -> + ok; + {error, Reason} -> + {application_start_error, Reason} + end. -spec stop() -> ok. stop() -> |