summaryrefslogtreecommitdiff
path: root/src/glm_bindings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glm_bindings.c')
-rw-r--r--src/glm_bindings.c90
1 files changed, 84 insertions, 6 deletions
diff --git a/src/glm_bindings.c b/src/glm_bindings.c
index 9fdd7f2..1eb3df1 100644
--- a/src/glm_bindings.c
+++ b/src/glm_bindings.c
@@ -7,12 +7,77 @@ int honey_glm_mat4_mt_ref = LUA_NOREF;
void honey_setup_glm(lua_State* L)
{
- lua_pushnil(L);
+ /* vec3 metatable */
+ honey_lua_create_table
+ (L, 2,
+ HONEY_TABLE, "__index", 21,
+ HONEY_FUNCTION, "copyTo", honey_glm_vec3_copy,
+ HONEY_FUNCTION, "zero", honey_glm_vec3_zero,
+ HONEY_FUNCTION, "eye", honey_glm_vec3_eye,
+ HONEY_FUNCTION, "dot", honey_glm_vec3_dot,
+ HONEY_FUNCTION, "cross", honey_glm_vec3_cross,
+ HONEY_FUNCTION, "crossn", honey_glm_vec3_crossn,
+ HONEY_FUNCTION, "norm2", honey_glm_vec3_norm2,
+ HONEY_FUNCTION, "norm", honey_glm_vec3_norm,
+ HONEY_FUNCTION, "add", honey_glm_vec3_add,
+ HONEY_FUNCTION, "adds", honey_glm_vec3_adds,
+ HONEY_FUNCTION, "sub", honey_glm_vec3_sub,
+ HONEY_FUNCTION, "subs", honey_glm_vec3_subs,
+ HONEY_FUNCTION, "mul", honey_glm_vec3_mul,
+ HONEY_FUNCTION, "scale", honey_glm_vec3_scale,
+ HONEY_FUNCTION, "scaleAs", honey_glm_vec3_scale_as,
+ HONEY_FUNCTION, "div", honey_glm_vec3_div,
+ HONEY_FUNCTION, "negate", honey_glm_vec3_negate,
+ HONEY_FUNCTION, "normalize", honey_glm_vec3_normalize,
+ HONEY_FUNCTION, "angleTo", honey_glm_vec3_angle,
+ HONEY_FUNCTION, "clamp", honey_glm_vec3_clamp,
+ HONEY_FUNCTION, "lerpTo", honey_glm_vec3_lerp,
+
+
+ HONEY_FUNCTION, "__gc", honey_glm_array_destroy);
+ honey_glm_vec3_mt_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+
+ /* vec4 metatable */
+ honey_lua_create_table
+ (L, 2,
+ HONEY_TABLE, "__index", 18,
+ HONEY_FUNCTION, "copyTo", honey_glm_vec4_copy,
+ HONEY_FUNCTION, "zero", honey_glm_vec4_zero,
+ HONEY_FUNCTION, "eye", honey_glm_vec4_eye,
+ HONEY_FUNCTION, "dot", honey_glm_vec4_dot,
+ HONEY_FUNCTION, "norm2", honey_glm_vec4_norm2,
+ HONEY_FUNCTION, "norm", honey_glm_vec4_norm,
+ HONEY_FUNCTION, "add", honey_glm_vec4_add,
+ HONEY_FUNCTION, "adds", honey_glm_vec4_adds,
+ HONEY_FUNCTION, "sub", honey_glm_vec4_sub,
+ HONEY_FUNCTION, "subs", honey_glm_vec4_subs,
+ HONEY_FUNCTION, "mul", honey_glm_vec4_mul,
+ HONEY_FUNCTION, "scale", honey_glm_vec4_scale,
+ HONEY_FUNCTION, "scaleAs", honey_glm_vec4_scale_as,
+ HONEY_FUNCTION, "div", honey_glm_vec4_div,
+ HONEY_FUNCTION, "negate", honey_glm_vec4_negate,
+ HONEY_FUNCTION, "normalize", honey_glm_vec4_normalize,
+ HONEY_FUNCTION, "clamp", honey_glm_vec4_clamp,
+ HONEY_FUNCTION, "lerpTo", honey_glm_vec4_lerp,
+
+
+ HONEY_FUNCTION, "__gc", honey_glm_array_destroy);
+ honey_glm_vec4_mt_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ /* glm table */
+ honey_lua_create_table
+ (L, 4,
+ HONEY_FUNCTION, "vec3", honey_glm_new_vec3,
+ HONEY_FUNCTION, "vec4", honey_glm_new_vec4,
+ HONEY_FUNCTION, "mat3", honey_glm_new_mat3,
+ HONEY_FUNCTION, "mat4", honey_glm_new_mat4);
+ lua_setfield(L, -2, "glm");
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
- * GLM Array Setup Functions
+ * GLM Array Basic Functions
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
@@ -57,7 +122,7 @@ static void setup_new_array(lua_State* L,
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-static int honey_glm_new_vec3(lua_State* L)
+int honey_glm_new_vec3(lua_State* L)
{
honey_glm_array* vec3 = lua_newuserdata(L, sizeof(honey_glm_array));
setup_new_array(L, vec3, VEC3);
@@ -66,7 +131,7 @@ static int honey_glm_new_vec3(lua_State* L)
return 1;
}
-static int honey_glm_new_vec4(lua_State* L)
+int honey_glm_new_vec4(lua_State* L)
{
honey_glm_array* vec4 = lua_newuserdata(L, sizeof(honey_glm_array));
setup_new_array(L, vec4, VEC4);
@@ -75,7 +140,7 @@ static int honey_glm_new_vec4(lua_State* L)
return 1;
}
-static int honey_glm_new_mat3(lua_State* L)
+int honey_glm_new_mat3(lua_State* L)
{
honey_glm_array* mat3 = lua_newuserdata(L, sizeof(honey_glm_array));
setup_new_array(L, mat3, MAT3);
@@ -84,7 +149,7 @@ static int honey_glm_new_mat3(lua_State* L)
return 1;
}
-static int honey_glm_new_mat4(lua_State* L)
+int honey_glm_new_mat4(lua_State* L)
{
honey_glm_array* mat4 = lua_newuserdata(L, sizeof(honey_glm_array));
setup_new_array(L, mat4, MAT4);
@@ -92,3 +157,16 @@ static int honey_glm_new_mat4(lua_State* L)
lua_setmetatable(L, -2);
return 1;
}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+int honey_glm_array_destroy(lua_State* L)
+{
+ honey_glm_array* array;
+ honey_lua_parse_arguments(L, 1, 1, HONEY_USERDATA, &array);
+ free(array->data);
+ return 0;
+}
+
+
+