summaryrefslogtreecommitdiff
path: root/src/ode/setup.c
blob: 3655b1e7deaa260e1ac5c09e7449b805ccd9b488 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <lua.h>
#include <lauxlib.h>
#include <ode/ode.h>
#include "util/util.h"
#include "ode_bindings.h"


/* setup/teardown */
int init_ode(lua_State *L);
int close_ode(lua_State *L);

#define X(name, mt) const char *mt = name;
ODE_METATABLES
#undef X


int generic_eq(lua_State *L)
{
	void **a = lua_touserdata(L, 1);
	void **b = lua_touserdata(L, 2);
	lua_pushboolean(L, *a == *b);
	return 1;
}


void setup_ode(lua_State *L, int honey_tbl)
{
	/* setup metatables */
	#define X(name, mt) \
		luaL_newmetatable(L, mt); \
		lua_pushcfunction(L, generic_eq); \
		lua_setfield(L, -2, "__eq"); \
		lua_pop(L, 1);
	ODE_METATABLES
	#undef X

	/* create main table */
	struct honey_tbl_t ode[] = {
		H_FUNC("InitODE", init_ode),
		H_FUNC("CloseODE", close_ode),
		#define X(name, func) H_FUNC(name, func),
		ODE_FUNCTIONS
		#undef X
		#define X(name, value) H_INT(name, value),
		ODE_ENUMS
		#undef X
		H_NUM("Infinity", dInfinity),
		H_END
	};
	create_table(L, ode);
	int ode_tbl = lua_gettop(L);

	/* add empty (normal) joint group */
	ode_push_jointgroup(L, 0);
	lua_setfield(L, ode_tbl, "JointGroup0");

	/* add null space */
	ode_push_space(L, 0);
	lua_setfield(L, ode_tbl, "Space0");

	lua_setfield(L, honey_tbl, "ode");
}


/* --===== setup/teardown =====-- */

int init_ode(lua_State *L)
{
	dInitODE();
	return 0;
}


int close_ode(lua_State *L)
{
	dCloseODE();
	return 0;
}