summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-06-18 18:34:35 -0500
committersanine <sanine.not@pm.me>2022-06-18 18:34:35 -0500
commitf977596e6b8f37b471042607b795c662abd61cdb (patch)
tree9bdf211a0c69b3e55eb4f7bb9b3650e3d3e47c52 /src
parenta73494d8858d67fd6b69ad4440b2b6657c0c9a5d (diff)
add tointeger
Diffstat (limited to 'src')
-rw-r--r--src/gl/window.c51
-rw-r--r--src/gl/window.test.c142
2 files changed, 190 insertions, 3 deletions
diff --git a/src/gl/window.c b/src/gl/window.c
index 03afd24..e16b330 100644
--- a/src/gl/window.c
+++ b/src/gl/window.c
@@ -3,9 +3,10 @@
#include <lua.h>
#include <honeysuckle.h>
-
+/* build a table of all possible window hints */
void create_glfw_window_hints_table(lua_State *L)
{
+ /* hint keys */
hs_create_table(L,
/* window hints */
hs_str_int("resizable", GLFW_RESIZABLE),
@@ -44,8 +45,39 @@ void create_glfw_window_hints_table(lua_State *L)
hs_str_int("contextReleaseBehavior", GLFW_CONTEXT_RELEASE_BEHAVIOR),
hs_str_int("noError", GLFW_CONTEXT_NO_ERROR)
);
+
+ /* special hint values */
+ hs_create_table(L,
+ hs_str_int("dontCare", GLFW_DONT_CARE),
+
+ /* client api */
+ hs_str_int("glApi", GLFW_OPENGL_API),
+ hs_str_int("glesApi", GLFW_OPENGL_ES_API),
+ hs_str_int("noApi", GLFW_NO_API),
+
+ /* context api */
+ hs_str_int("nativeApi", GLFW_NATIVE_CONTEXT_API),
+ hs_str_int("eglApi", GLFW_EGL_CONTEXT_API),
+ hs_str_int("osMesaApi", GLFW_OSMESA_CONTEXT_API),
+
+ /* robustness */
+ hs_str_int("noRobustness", GLFW_NO_ROBUSTNESS),
+ hs_str_int("noResetNotification", GLFW_NO_RESET_NOTIFICATION),
+ hs_str_int("loseContextOnReset", GLFW_LOSE_CONTEXT_ON_RESET),
+
+ /* context release */
+ hs_str_int("anyBehavior", GLFW_ANY_RELEASE_BEHAVIOR),
+ hs_str_int("flush", GLFW_RELEASE_BEHAVIOR_FLUSH),
+ hs_str_int("none", GLFW_RELEASE_BEHAVIOR_NONE),
+
+ /* profile */
+ hs_str_int("anyProfile", GLFW_OPENGL_ANY_PROFILE),
+ hs_str_int("compatabilityProfile", GLFW_OPENGL_COMPAT_PROFILE),
+ hs_str_int("coreProfile", GLFW_OPENGL_CORE_PROFILE)
+ );
}
+
int gl_init(lua_State *L)
{
if (glfwInit() != GLFW_TRUE) {
@@ -53,3 +85,20 @@ int gl_init(lua_State *L)
}
return 0;
}
+
+
+lua_Integer tointeger(lua_State *L, int index)
+{
+ if (lua_isboolean(L, index)) {
+ return lua_toboolean(L, index);
+ }
+ else if (lua_isnumber(L, index)) {
+ return lua_tointeger(L, index);
+ }
+ else {
+ hs_throw_error(L,
+ "expected boolean or number; got %s instead",
+ lua_typename(L, lua_type(L, index))
+ );
+ }
+}
diff --git a/src/gl/window.test.c b/src/gl/window.test.c
index 6d5c844..6b8e091 100644
--- a/src/gl/window.test.c
+++ b/src/gl/window.test.c
@@ -58,14 +58,21 @@ int mock_hs_throw_error(lua_State *L, const char *format_string, ...)
void gl_init_succeeds();
void gl_init_fail_glfwInit();
void glfw_window_hints_table();
+void tointeger_parses_bool();
+void tointeger_parses_int();
+void tointeger_fails_other();
void suite_window()
{
lily_run_test(gl_init_succeeds);
lily_run_test(gl_init_fail_glfwInit);
lily_run_test(glfw_window_hints_table);
+ lily_run_test(tointeger_parses_bool);
+ lily_run_test(tointeger_parses_int);
+ lily_run_test(tointeger_fails_other);
CLEAN_MOCK(mock_glfwInit);
+ CLEAN_MOCK(mock_hs_throw_error);
}
@@ -130,8 +137,8 @@ void glfw_window_hints_table()
lily_assert_int_equal(lua_gettop(L), 0);
create_glfw_window_hints_table(L);
- lily_assert_int_equal(lua_gettop(L), 1);
- lily_assert_true(lua_istable(L, -1));
+ lily_assert_int_equal(lua_gettop(L), 2);
+ lily_assert_true(lua_istable(L, 1));
/* window hints */
lily_assert_int_equal(
@@ -294,5 +301,136 @@ void glfw_window_hints_table()
GLFW_CONTEXT_NO_ERROR
);
+
+ /* special hint values */
+
+ lily_assert_int_equal(
+ get_int(L, 2, "dontCare"),
+ GLFW_DONT_CARE
+ );
+
+ /* client api */
+ lily_assert_int_equal(
+ get_int(L, 2, "glApi"),
+ GLFW_OPENGL_API
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "glesApi"),
+ GLFW_OPENGL_ES_API
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "noApi"),
+ GLFW_NO_API
+ );
+
+ /* context api */
+ lily_assert_int_equal(
+ get_int(L, 2, "nativeApi"),
+ GLFW_NATIVE_CONTEXT_API
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "eglApi"),
+ GLFW_EGL_CONTEXT_API
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "osMesaApi"),
+ GLFW_OSMESA_CONTEXT_API
+ );
+
+ /* robustness */
+ lily_assert_int_equal(
+ get_int(L, 2, "noRobustness"),
+ GLFW_NO_ROBUSTNESS
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "noResetNotification"),
+ GLFW_NO_RESET_NOTIFICATION
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "loseContextOnReset"),
+ GLFW_LOSE_CONTEXT_ON_RESET
+ );
+
+ /* release */
+ lily_assert_int_equal(
+ get_int(L, 2, "anyBehavior"),
+ GLFW_ANY_RELEASE_BEHAVIOR
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "flush"),
+ GLFW_RELEASE_BEHAVIOR_FLUSH
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "none"),
+ GLFW_RELEASE_BEHAVIOR_NONE
+ );
+
+ /* profile */
+ lily_assert_int_equal(
+ get_int(L, 2, "anyProfile"),
+ GLFW_OPENGL_ANY_PROFILE
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "compatabilityProfile"),
+ GLFW_OPENGL_COMPAT_PROFILE
+ );
+
+ lily_assert_int_equal(
+ get_int(L, 2, "coreProfile"),
+ GLFW_OPENGL_CORE_PROFILE
+ );
+
lua_close(L);
}
+
+
+void tointeger_parses_bool()
+{
+ USE_MOCK(mock_hs_throw_error);
+ lua_State *L = luaL_newstate();
+
+ lua_pushboolean(L, 0);
+ lily_assert_false(lua_toboolean(L, -1));
+ lily_assert_int_equal(tointeger(L, -1), 0);
+
+ lua_pushboolean(L, 1);
+ lily_assert_true(lua_toboolean(L, -1));
+ lily_assert_int_equal(tointeger(L, -1), 1);
+
+ lua_close(L);
+}
+
+
+void tointeger_parses_int()
+{
+ USE_MOCK(mock_hs_throw_error);
+ lua_State *L = luaL_newstate();
+
+ lua_pushinteger(L, 234);
+ lua_pushinteger(L, 55555);
+
+ lily_assert_int_equal(tointeger(L, -2), 234);
+ lily_assert_int_equal(tointeger(L, -1), 55555);
+
+ lua_close(L);
+}
+
+
+void tointeger_fails_other()
+{
+ USE_MOCK(mock_hs_throw_error);
+ lua_State *L = luaL_newstate();
+
+ lua_pushstring(L, "hey there babe");
+ tointeger(L, -1);
+ lily_assert_int_equal(mock_hs_throw_error_data->n_calls, 1);
+}