Fixed compile errors.
Fixed cross-refernecing module dependencies.

Move away gl_loader to src_bak.
[from now] 2014/03/30 23:49:49

diff --git a/src/sdl.ml b/src/sdl.ml
index a489e70..c19851a 100644
--- a/src/sdl.ml
+++ b/src/sdl.ml
@@ -5,8 +5,16 @@
    @since 0.1
 *)

+module Init = Sdl_init
 module Error = Sdl_error
 module Texture = Sdl_texture
 module Renderer = Sdl_renderer
 module Window = Sdl_window
 module Log = Sdl_log
+
+module Flags = struct
+  include Sdl_flags
+end
+module Types = struct
+  include Sdl_types
+end
diff --git a/src/sdl_init.ml b/src/sdl_init.ml
new file mode 100644
index 0000000..8fada6e
--- /dev/null
+++ b/src/sdl_init.ml
@@ -0,0 +1,68 @@
+(**
+ * this module provide lowlevel SDL bindings of {b SDK.h}. this don't include
+ * high level API for user. these functions are often use only inner library.
+ *
+ * @author derui
+ * @since 0.1
+ *)
+
+exception Sdl_init_exception of string
+
+(** Initializing SDL and SDL Subsystems for SDK version of 1.2
+ *  Taking arguments to this function have to {e flags}. if {e auto_clean} isn't
+ *  send, you must call {!sdl_quit} in the end of your program.
+ *  if SDL initialization failed, raise {!SDL_init_exception} with error infomations
+ *  from {b SDL_GetError} and line number at raised it.
+ *
+ *  @param auto_clean auto_clean setting up auto cleanup with sdl_quit if give
+ *  this true. defaults, sdl_init doesn't set up it.
+ *  @param flags Targets of initializing systems and mode flags.
+ *  @raise SDL_init_exception raise it when initialization failed.
+ *  @author derui
+ *  @since 0.1
+ *)
+external init : ?auto_clean:bool ->
+  flags:Sdl_flags.Sdl_init_flags.t list -> unit -> unit = "sdlcaml_init_init"
+
+(**
+ * This function is wrapper of {b SDL_Quit}.
+ * Quit and finish all SDL systems. if you don't set auto_clean of {!sdl_init}
+ * or give false to it, you must call this function in the end of your program.
+ *
+ * @author derui
+ * @since 0.1
+ *)
+external quit : unit -> unit = "sdlcaml_init_quit"
+
+(**
+ * return result of that if each subsystems are initialized.
+ *
+ * @return result of initialized.
+ * @author derui
+ * @since 0.1
+ *)
+external was_init : Sdl_flags.Sdl_init_flags.t list -> bool = "sdlcaml_init_was_init"
+
+(**
+ * Initializing a SDL subsystem.  this function used to after {!sdl_init}
+ * without flags that any subsystem initializing.
+ * If a subsystem initializing failed, {!SDL_init_exception} raise.
+ *
+ * @param flag give flags of a target subsystem
+ * @raise SDL_init_exception when initializing failed
+ * @author derui
+ * @since 0.1
+ *)
+external init_subsystem : Sdl_flags.Sdl_init_flags.t -> unit = "sdlcaml_init_init_subsystem"
+
+(**
+ * Quit a SDL subsystem. this function have to call after {!sdl_init} or
+ * {!sdl_init_subsystem} called.
+ * If you call {!sdl_quit}, you doesn't need to call this because {!sdl_quit}
+ * shut down all SDL subsystems.
+ *
+ * @param flag give flags of a target subsystem
+ * @author derui
+ * @since 0.1
+ *)
+external quit_subsystem : Sdl_flags.Sdl_init_flags.t -> unit = "sdlcaml_init_quit_subsystem"
diff --git a/src/sdl_init_stub.c b/src/sdl_init_stub.c
new file mode 100644
index 0000000..2948223
--- /dev/null
+++ b/src/sdl_init_stub.c
@@ -0,0 +1,76 @@
+#include <SDL.h>
+#include <SDL_version.h>
+
+#include <caml/alloc.h>
+#include <caml/mlvalues.h>
+#include <caml/memory.h>
+#include <caml/fail.h>
+#include <caml/callback.h>
+
+#include "sdl_init_flags.h"
+#include "common.h"
+
+/* trick for SDLMain under MacOSX */
+#ifdef __APPLE__
+int main(int argc, char *argv[]) {
+  caml_main(argv);
+  return 0;
+}
+#endif
+
+static void sdlcaml_inner_quit(void) {
+  SDL_Quit();
+}
+
+CAMLprim value sdlcaml_init_init(value auto_clean, value flags, value unit) {
+  CAMLparam3(auto_clean, flags, unit);
+  int init_flag = ml_make_combined_flag(ml_sdl_init_flags_table, flags);
+
+  if (SDL_Init(init_flag) < 0) {
+    caml_raise_with_string(*caml_named_value("Sdl_init_exception"),
+                           SDL_GetError());
+  }
+
+  if (is_none(auto_clean) || Val_true == Field(auto_clean, 0)) {
+    atexit(sdlcaml_inner_quit);
+  }
+
+  CAMLreturn(Val_unit);
+}
+
+CAMLprim value sdlcaml_init_quit(value unit) {
+  /* only calling inner function */
+  CAMLparam0();
+  sdlcaml_inner_quit();
+  CAMLreturn(unit);
+}
+
+CAMLprim value sdlcaml_init_was_init(value subsystems) {
+  /* only calling inner function */
+  CAMLparam1(subsystems);
+  int flag = ml_make_combined_flag(ml_sdl_init_flags_table, subsystems);
+
+  int initialized = SDL_WasInit(flag);
+
+  CAMLreturn(initialized == flag ? Val_true : Val_false);
+}
+
+CAMLprim value sdlcaml_init_init_subsystem(value flag) {
+  CAMLparam1(flag);
+  int c_flag = ml_lookup_to_c(ml_sdl_init_flags_table, flag);
+
+  if (SDL_InitSubSystem(c_flag)) {
+    caml_raise_with_string(*caml_named_value("SDL_init_exception"),
+                           SDL_GetError());
+  }
+
+  CAMLreturn(Val_unit);
+}
+
+CAMLprim value sdlcaml_init_quit_subsystem(value flag) {
+  CAMLparam1(flag);
+  int c_flag = ml_lookup_to_c(ml_sdl_init_flags_table, flag);
+
+  SDL_QuitSubSystem(c_flag);
+  CAMLreturn(Val_unit);
+}
diff --git a/src/sdl_log.ml b/src/sdl_log.ml
index 93c75b4..639f9de 100644
--- a/src/sdl_log.ml
+++ b/src/sdl_log.ml
@@ -8,14 +8,14 @@
 type priority = Sdl_flags.Sdl_log_priority.t
 type category = Sdl_flags.Sdl_log_category.t

-external inner_log : category -> priority -> 'a -> unit = "sdlcaml_log_raw_log"
+external inner_log : [<category] -> [<priority] -> 'a -> unit = "sdlcaml_log_raw_log"

 let log ~category ~priority fmt =
   let s = Printf.kprintf (fun s () -> s) fmt in
   inner_log category priority s

-let log_critical category fmt = log ~priority:`CRITICAL ~category fmt
-let log_debug category fmt = log ~priority:`DEBUG ~category fmt
+let log_critical [<category] fmt = log ~priority:`CRITICAL ~category fmt
+let log_debug [<category] fmt = log ~priority:`DEBUG ~category fmt
 let log_error category fmt = log ~priority:`ERROR ~category fmt
 let log_info category fmt = log ~priority:`INFO ~category fmt
 let log_verbose category fmt = log ~priority:`VERBOSE ~category fmt
diff --git a/src/sdl_log.mli b/src/sdl_log.mli
index d787490..49c118f 100644
--- a/src/sdl_log.mli
+++ b/src/sdl_log.mli
@@ -5,46 +5,40 @@
    @since 0.2
 *)

-type priority = Sdl_flags.Sdl_log_priority.t
-(** Priorities to output log *)
-
-type category = Sdl_flags.Sdl_log_category.t
-(** Categories of the log *)
-
-val log : category:category -> priority:priority ->
+val log : category:[< Sdl_flags.Sdl_log_category.t] -> priority:[<Sdl_flags.Sdl_log_priority.t] ->
   ('a, unit, string, unit -> string) format4 -> unit
 (** [log ~category ~priority "format" ...] log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO *)

-val log_critical : category -> ('a, unit, string, unit-> string) format4 -> unit
+val log_critical : [< Sdl_flags.Sdl_log_category.t] -> ('a, unit, string, unit-> string) format4 -> unit
 (** [log_critical priority "format" ...] log a message with SDL_Critial *)

-val log_debug : category -> ('a, unit, string, unit-> string) format4 -> unit
+val log_debug : [< Sdl_flags.Sdl_log_category.t] -> ('a, unit, string, unit-> string) format4 -> unit
 (** [log_debug priority "format" ...] log a message with SDL_Critial *)

-val log_error : category -> ('a, unit, string, unit-> string) format4 -> unit
+val log_error : [< Sdl_flags.Sdl_log_category.t] -> ('a, unit, string, unit-> string) format4 -> unit
 (** [log_error priority "format" ... ] log a message with SDL_Critial *)

-val log_info : category -> ('a, unit, string, unit-> string) format4 -> unit
+val log_info : [<Sdl_flags.Sdl_log_category.t] -> ('a, unit, string, unit-> string) format4 -> unit
 (** [log_info priority "format" ... ] log a message with SDL_Critial *)

-val log_verbose : category -> ('a, unit, string, unit-> string) format4 -> unit
+val log_verbose :[< Sdl_flags.Sdl_log_category.t]-> ('a, unit, string, unit-> string) format4 -> unit
 (** [log_verbose priority "format" ... ] log a message with SDL_Critial *)

-val log_warn : category -> ('a, unit, string, unit-> string) format4 -> unit
+val log_warn : [< Sdl_flags.Sdl_log_category.t] -> ('a, unit, string, unit-> string) format4 -> unit
 (** [log_warn priority "format" ... ] log a message with SDL_Critial *)

 val reset_priorities : unit -> unit
 (** [reset_priorities ()] reset all priorities to default *)

-val set_all_priority : priority -> unit
+val set_all_priority : [< Sdl_flags.Sdl_log_priority.t] -> unit
 (** [set_all_priority priority] set all priority of all log categories *)

-val set_priority : category:category -> priority:priority -> unit -> unit
+val set_priority : category:[< Sdl_flags.Sdl_log_category.t] -> priority:[< Sdl_flags.Sdl_log_priority.t] -> unit -> unit
 (** [set_priority ~category ~priority ()] set the priority of a particular log category *)

 val reset_output_function : unit -> unit
 (** [reset_output_function ()] Reset output funciton to defaults of SDL *)

-val set_output_function : (category -> priority -> string -> unit) -> unit
+val set_output_function : ([<Sdl_flags.Sdl_log_category.t] -> [<Sdl_flags.Sdl_log_priority.t] -> string -> unit) -> unit
 (** [set_output_function (fun category priority str -> ...)] set the output
     function when call each output logs. *)
Make new rule that is named `config' to create flags
to build stubs.

Move src/config/flags to src/flags.

Move src/config/flags to src/flag