summaryrefslogtreecommitdiff
path: root/src/glm/mat4.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-10-04 14:53:08 -0500
committersanine <sanine.not@pm.me>2022-10-04 14:53:08 -0500
commit6d96b0e7ea1d98e44647d0bbbba232701a7d557e (patch)
tree15fa9d310f1db5767b662fb0bb4cad8a560d3650 /src/glm/mat4.c
parent0c55c0e1b48de55fea401ea1b2b3f2280ef0f93c (diff)
add first person demo
Diffstat (limited to 'src/glm/mat4.c')
-rw-r--r--src/glm/mat4.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/glm/mat4.c b/src/glm/mat4.c
index 02ef047..5197891 100644
--- a/src/glm/mat4.c
+++ b/src/glm/mat4.c
@@ -9,8 +9,13 @@ int mat4_set(lua_State *L);
int mat4_get(lua_State *L);
int mat4_identity(lua_State *L);
+const char *mat4_tname = "glm.mat4";
+
void setup_mat4(lua_State *L, int glm_tbl)
{
+ luaL_newmetatable(L, mat4_tname);
+ lua_pop(L, 1);
+
int tbl = hs_create_table(L,
hs_str_cfunc("mat4", mat4_create),
hs_str_cfunc("mat4_set", mat4_set),
@@ -26,37 +31,34 @@ void setup_mat4(lua_State *L, int glm_tbl)
int mat4_create(lua_State *L)
{
lua_newuserdata(L, 16*sizeof(float));
+ luaL_getmetatable(L, mat4_tname);
+ lua_setmetatable(L, -2);
return 1;
}
int mat4_set(lua_State *L)
{
- void *ptr;
- lua_Integer index;
- lua_Number value;
- hs_parse_args(L, hs_user(ptr), hs_int(index), hs_num(value));
- array_set(L, 16, ptr, index, value);
+ float *matrix = luaL_checkudata(L, 1, mat4_tname);
+ int index = luaL_checkinteger(L, 2);
+ float value = luaL_checknumber(L, 3);
+ array_set(L, 16, matrix, index, value);
return 0;
}
int mat4_get(lua_State *L)
{
- void *ptr;
- lua_Integer index;
- hs_parse_args(L, hs_user(ptr), hs_int(index));
- array_get(L, 16, ptr, index);
+ float *matrix = luaL_checkudata(L, 1, mat4_tname);
+ int index = luaL_checkinteger(L, 2);
+ array_get(L, 16, matrix, index);
return 1;
}
int mat4_identity(lua_State *L)
{
- void *ptr;
- hs_parse_args(L, hs_user(ptr));
- mat4 *m = ptr;
-
- glm_mat4_identity(*m);
+ void *m = luaL_checkudata(L, 1, mat4_tname);
+ glm_mat4_identity(m);
return 0;
}