summaryrefslogtreecommitdiff
path: root/src/glm/setup.c
blob: 332987b24acdabfb9b400e81d1a41fbb0288b467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <lua.h>
#include <lauxlib.h>
#include "util/util.h"
#include "glm.h"


const char *glm_mat2_tname = "glm.mat2";
const char *glm_mat3_tname = "glm.mat3";
const char *glm_mat4_tname = "glm.mat4";
const char *glm_vec2_tname = "glm.vec2";
const char *glm_vec3_tname = "glm.vec3";
const char *glm_vec4_tname = "glm.vec4";
const char *glm_versor_tname = "glm.versor";


void setup_glm(lua_State *L, int honey_index)
{
	luaL_newmetatable(L, glm_mat2_tname); lua_pop(L, 1);
	luaL_newmetatable(L, glm_mat3_tname); lua_pop(L, 1);
	luaL_newmetatable(L, glm_mat4_tname); lua_pop(L, 1);
	luaL_newmetatable(L, glm_vec2_tname); lua_pop(L, 1);
	luaL_newmetatable(L, glm_vec3_tname); lua_pop(L, 1);
	luaL_newmetatable(L, glm_vec4_tname); lua_pop(L, 1);
	luaL_newmetatable(L, glm_versor_tname); lua_pop(L, 1);

	struct honey_tbl_t glm[] = {
		#define X(name, func) H_FUNC(name, func),
		GLM_FUNCTIONS
		#undef X
		H_END,
	};
	create_table(L, glm);
	lua_setfield(L, honey_index, "glm");
}


void array_get(lua_State *L, int max, float *array, int index)
{
	if (index < 0 || index >= max)
		luaL_error(L, "index %d is out of range [0-%d]", index, max-1);
	lua_pushnumber(L, array[index]);
}


void array_set(lua_State *L, int max, float *array, int index, float value)
{
	if (index < 0 || index >= max)
		luaL_error(L, "index %d is out of range [0-%d]", index, max-1);
	array[index] = value;
}