summaryrefslogtreecommitdiff
path: root/src/ode/setup.c
blob: 2b5b1e394a3953fea002f783031795e0b0026d3b (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
#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


void setup_ode(lua_State *L, int honey_tbl)
{
	/* setup metatables */
	#define X(name, mt) luaL_newmetatable(L, mt); 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;
}