<commit_before>#include "ruby.h"
#include <GLFW/glfw3.h>


typedef struct s_rb_glfw_error
{
  VALUE error_code;   // mark
  VALUE description;  // mark
} rb_glfw_error_t;


static const char *kRB_IVAR_WINDOW_INTERNAL_NAME                   = "@__internal_window";
static const char *kRB_IVAR_WINDOW_KEY_CALLBACK_NAME               = "@__key_callback";
static const char *kRB_IVAR_WINDOW_CHAR_CALLBACK_NAME              = "@__char_callback";
static const char *kRB_IVAR_WINDOW_MOUSE_BUTTON_CALLBACK_NAME      = "@__mouse_button_callback";
static const char *kRB_IVAR_WINDOW_CURSOR_POSITION_CALLBACK_NAME   = "@__cursor_position_callback";
static const char *kRB_IVAR_WINDOW_CURSOR_ENTER_CALLBACK_NAME      = "@__cursor_enter_callback";
static const char *kRB_IVAR_WINDOW_SCROLL_CALLBACK_NAME            = "@__scroll_callback";
static const char *kRB_IVAR_WINDOW_POSITION_CALLBACK_NAME          = "@__position_callback";
static const char *kRB_IVAR_WINDOW_SIZE_CALLBACK_NAME              = "@__size_callback";
static const char *kRB_IVAR_WINDOW_CLOSE_CALLBACK_NAME             = "@__close_callback";
static const char *kRB_IVAR_WINDOW_REFRESH_CALLBACK_NAME           = "@__refresh_callback";
static const char *kRB_IVAR_WINDOW_FOCUS_CALLBACK_NAME             = "@__focus_callback";
static const char *kRB_IVAR_WINDOW_ICONIFY_CALLBACK_NAME           = "@__iconify_callback";
static const char *kRB_IVAR_WINDOW_FRAMEBUFFER_SIZE_CALLBACK_NAME  = "@__framebuffer_size_callback";
static const char *kRB_CVAR_WINDOW_WINDOWS_NAME                    = "@@__windows";
static const char *kRB_CVAR_GLFW_ERROR_CALLBACK_NAME               = "@@__error_callback";
static const char *kRB_CVAR_GLFW_MONITOR_CALLBACK_NAME             = "@@__monitor_callback";
static const char *kRB_CALL_NAME                                   = "call";
static const char *kRB_RED_NAME                                    = "red";
static const char *kRB_GREEN_NAME                                  = "green";
static const char *kRB_BLUE_NAME                                   = "blue";


static ID kRB_IVAR_WINDOW_INTERNAL;
static ID kRB_IVAR_WINDOW_KEY_CALLBACK;
static ID kRB_IVAR_WINDOW_CHAR_CALLBACK;
static ID kRB_IVAR_WINDOW_MOUSE_BUTTON_CALLBACK;
static ID kRB_IVAR_WINDOW_CURSOR_POSITION_CALLBACK;
static ID kRB_IVAR_WINDOW_CURSOR_ENTER_CALLBACK;
static ID kRB_IVAR_WINDOW_SCROLL_CALLBACK;
static ID kRB_IVAR_WINDOW_POSITION_CALLBACK;
static ID kRB_IVAR_WINDOW_SIZE_CALLBACK;
static ID kRB_IVAR_WINDOW_CLOSE_CALLBACK;
static ID kRB_IVAR_WINDOW_REFRESH_CALLBACK;
static ID kRB_IVAR_WINDOW_FOCUS_CALLBACK;
static ID kRB_IVAR_WINDOW_ICONIFY_CALLBACK;
static ID kRB_IVAR_WINDOW_FRAMEBUFFER_SIZE_CALLBACK;
static ID kRB_CVAR_WINDOW_WINDOWS;
static ID kRB_CVAR_GLFW_ERROR_CALLBACK;
static ID kRB_CVAR_GLFW_MONITOR_CALLBACK;
static ID kRB_CALL;
static ID kRB_RED;
static ID kRB_GREEN;
static ID kRB_BLUE;


static VALUE s_glfw_module = Qundef;
static VALUE s_glfw_window_klass = Qundef;
static VALUE s_glfw_window_internal_klass = Qundef;
static VALUE s_glfw_monitor_klass = Qundef;
static VALUE s_glfw_videomode_klass = Qundef;


static void rb_glfw_error_callback(int error_code, const char *description);
static void rb_glfw_monitor_callback(GLFWmonitor *monitor, int message);


#define RB_ENABLE_CALLBACK_DEF(NAME, CALLBACK, GLFW_FUNC)                     \
static VALUE NAME (VALUE self, VALUE enabled)                                 \
{                                                                             \
  if (RTEST(enabled)) {                                                       \
    GLFW_FUNC ( rb_get_window(self), CALLBACK );                              \
  } else {                                                                    \
    GLFW_FUNC ( rb_get_window(self), NULL );                                  \
  }                                                                           \
  return self;                                                                \
}


/*
 * Initializes GLFW. Returns true on success, false on failure.
 *
 * call-seq:
 *    init -> true or false
 *
 * Wraps glfwInit.
 */
static VALUE rb_glfw_init(VALUE self)
{
  (void)self;
  VALUE result = glfwInit() ? Qtrue : Qfalse;
  if (result == Qtrue) {
    glfwSetMonitorCallback(rb_glfw_monitor_callback);
  }
  return result;
}




/*
 * Terminates GLFW.
 *
 * Wraps glfwTerminate.
 */
static VALUE rb_glfw_terminate(VALUE self)
{
  glfwTerminate();
  return Qundef;
}



/*
 * Returns GLFW's version in an array.
 *
 * call-seq:
 *    version -> [major, minor, revision]
 *
 * Wraps glfwGetVersion.
 */
static VALUE rb_glfw_version(VALUE self)
{
  int major = 0;<commit_msg>Fix return value for rb_glfw_terminate<commit_after>#include "ruby.h"
#include <GLFW/glfw3.h>


typedef struct s_rb_glfw_error
{
  VALUE error_code;   // mark
  VALUE description;  // mark
} rb_glfw_error_t;


static const char *kRB_IVAR_WINDOW_INTERNAL_NAME                   = "@__internal_window";
static const char *kRB_IVAR_WINDOW_KEY_CALLBACK_NAME               = "@__key_callback";
static const char *kRB_IVAR_WINDOW_CHAR_CALLBACK_NAME              = "@__char_callback";
static const char *kRB_IVAR_WINDOW_MOUSE_BUTTON_CALLBACK_NAME      = "@__mouse_button_callback";
static const char *kRB_IVAR_WINDOW_CURSOR_POSITION_CALLBACK_NAME   = "@__cursor_position_callback";
static const char *kRB_IVAR_WINDOW_CURSOR_ENTER_CALLBACK_NAME      = "@__cursor_enter_callback";
static const char *kRB_IVAR_WINDOW_SCROLL_CALLBACK_NAME            = "@__scroll_callback";
static const char *kRB_IVAR_WINDOW_POSITION_CALLBACK_NAME          = "@__position_callback";
static const char *kRB_IVAR_WINDOW_SIZE_CALLBACK_NAME              = "@__size_callback";
static const char *kRB_IVAR_WINDOW_CLOSE_CALLBACK_NAME             = "@__close_callback";
static const char *kRB_IVAR_WINDOW_REFRESH_CALLBACK_NAME           = "@__refresh_callback";
static const char *kRB_IVAR_WINDOW_FOCUS_CALLBACK_NAME             = "@__focus_callback";
static const char *kRB_IVAR_WINDOW_ICONIFY_CALLBACK_NAME           = "@__iconify_callback";
static const char *kRB_IVAR_WINDOW_FRAMEBUFFER_SIZE_CALLBACK_NAME  = "@__framebuffer_size_callback";
static const char *kRB_CVAR_WINDOW_WINDOWS_NAME                    = "@@__windows";
static const char *kRB_CVAR_GLFW_ERROR_CALLBACK_NAME               = "@@__error_callback";
static const char *kRB_CVAR_GLFW_MONITOR_CALLBACK_NAME             = "@@__monitor_callback";
static const char *kRB_CALL_NAME                                   = "call";
static const char *kRB_RED_NAME                                    = "red";
static const char *kRB_GREEN_NAME                                  = "green";
static const char *kRB_BLUE_NAME                                   = "blue";


static ID kRB_IVAR_WINDOW_INTERNAL;
static ID kRB_IVAR_WINDOW_KEY_CALLBACK;
static ID kRB_IVAR_WINDOW_CHAR_CALLBACK;
static ID kRB_IVAR_WINDOW_MOUSE_BUTTON_CALLBACK;
static ID kRB_IVAR_WINDOW_CURSOR_POSITION_CALLBACK;
static ID kRB_IVAR_WINDOW_CURSOR_ENTER_CALLBACK;
static ID kRB_IVAR_WINDOW_SCROLL_CALLBACK;
static ID kRB_IVAR_WINDOW_POSITION_CALLBACK;
static ID kRB_IVAR_WINDOW_SIZE_CALLBACK;
static ID kRB_IVAR_WINDOW_CLOSE_CALLBACK;
static ID kRB_IVAR_WINDOW_REFRESH_CALLBACK;
static ID kRB_IVAR_WINDOW_FOCUS_CALLBACK;
static ID kRB_IVAR_WINDOW_ICONIFY_CALLBACK;
static ID kRB_IVAR_WINDOW_FRAMEBUFFER_SIZE_CALLBACK;
static ID kRB_CVAR_WINDOW_WINDOWS;
static ID kRB_CVAR_GLFW_ERROR_CALLBACK;
static ID kRB_CVAR_GLFW_MONITOR_CALLBACK;
static ID kRB_CALL;
static ID kRB_RED;
static ID kRB_GREEN;
static ID kRB_BLUE;


static VALUE s_glfw_module = Qundef;
static VALUE s_glfw_window_klass = Qundef;
static VALUE s_glfw_window_internal_klass = Qundef;
static VALUE s_glfw_monitor_klass = Qundef;
static VALUE s_glfw_videomode_klass = Qundef;


static void rb_glfw_error_callback(int error_code, const char *description);
static void rb_glfw_monitor_callback(GLFWmonitor *monitor, int message);


#define RB_ENABLE_CALLBACK_DEF(NAME, CALLBACK, GLFW_FUNC)                     \
static VALUE NAME (VALUE self, VALUE enabled)                                 \
{                                                                             \
  if (RTEST(enabled)) {                                                       \
    GLFW_FUNC ( rb_get_window(self), CALLBACK );                              \
  } else {                                                                    \
    GLFW_FUNC ( rb_get_window(self), NULL );                                  \
  }                                                                           \
  return self;                                                                \
}


/*
 * Initializes GLFW. Returns true on success, false on failure.
 *
 * call-seq:
 *    init -> true or false
 *
 * Wraps glfwInit.
 */
static VALUE rb_glfw_init(VALUE self)
{
  (void)self;
  VALUE result = glfwInit() ? Qtrue : Qfalse;
  if (result == Qtrue) {
    glfwSetMonitorCallback(rb_glfw_monitor_callback);
  }
  return result;
}




/*
 * Terminates GLFW.
 *
 * Wraps glfwTerminate.
 */
static VALUE rb_glfw_terminate(VALUE self)
{
  glfwTerminate();
  return self;
}



/*
 * Returns GLFW's version in an array.
 *
 * call-seq:
 *    version -> [major, minor, revision]
 *
 * Wraps glfwGetVersion.
 */
static VALUE rb_glfw_version(VALUE self)
{
  int major = 0;
{'fraction_non_alphanumeric': 0.06661668630181, 'fraction_numerical': 0.0004284031273428296, 'mean_word_length': 2.674931129476584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6768199', 'n_tokens_mistral': 3058, 'n_tokens_neox': 3008, 'n_words': 603}