summaryrefslogtreecommitdiff
path: root/src/ode/setup.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-24 04:06:36 -0600
committersanine <sanine.not@pm.me>2023-02-24 04:06:36 -0600
commit2fa0047f4600ef95d32e864dd7c54e99e27265fe (patch)
treee592d63a38c087f8da7360a6df7e5904ca831dc8 /src/ode/setup.c
parent98c6064fc679586251793ae47c3c6f57dd4d1cb1 (diff)
refactor: bind (almost) all ode functions
Diffstat (limited to 'src/ode/setup.c')
-rw-r--r--src/ode/setup.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/ode/setup.c b/src/ode/setup.c
new file mode 100644
index 0000000..36e37c1
--- /dev/null
+++ b/src/ode/setup.c
@@ -0,0 +1,73 @@
+#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 NEW_METATABLE(name) luaL_newmetatable(L, name); lua_pop(L, 1);
+const char *ode_world_tname = "ode.WorldID";
+const char *ode_space_tname = "ode.SpaceID";
+const char *ode_body_tname = "ode.BodyID";
+const char *ode_geom_tname = "ode.GeomID";
+const char *ode_mass_tname = "ode.Mass";
+const char *ode_joint_tname = "ode.JointID";
+const char *ode_jointgroup_tname = "ode.JointGroupID";
+const char *ode_contact_tname = "ode.Contact";
+
+
+void setup_ode(lua_State *L, int honey_tbl)
+{
+ /* setup metatables */
+ NEW_METATABLE(ode_world_tname);
+ NEW_METATABLE(ode_space_tname);
+ NEW_METATABLE(ode_body_tname);
+ NEW_METATABLE(ode_geom_tname);
+ NEW_METATABLE(ode_mass_tname);
+ NEW_METATABLE(ode_joint_tname);
+ NEW_METATABLE(ode_jointgroup_tname);
+ NEW_METATABLE(ode_contact_tname);
+
+ /* 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
+ 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;
+}