mirror of https://github.com/bjornbytes/lovr.git
Shape:getUserData; Shape:setUserData;
This commit is contained in:
parent
e93bfb30ad
commit
a70edfe2a5
|
@ -44,3 +44,27 @@ int l_lovrShapeSetEnabled(lua_State* L) {
|
|||
lovrShapeSetEnabled(shape, enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrShapeGetUserData(lua_State* L) {
|
||||
Shape* shape = luax_checktypeof(L, 1, Shape);
|
||||
int ref = (int) lovrShapeGetUserData(shape);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrShapeSetUserData(lua_State* L) {
|
||||
Shape* shape = luax_checktypeof(L, 1, Shape);
|
||||
uint64_t ref = (int) lovrShapeGetUserData(shape);
|
||||
if (ref) {
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
||||
}
|
||||
|
||||
if (lua_gettop(L) < 2) {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
|
||||
lua_settop(L, 2);
|
||||
ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
lovrShapeSetUserData(shape, (void*) ref);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -295,3 +295,11 @@ void lovrShapeSetEnabled(Shape* shape, int enabled) {
|
|||
dGeomDisable(shape->id);
|
||||
}
|
||||
}
|
||||
|
||||
void* lovrShapeGetUserData(Shape* shape) {
|
||||
return dGeomGetData(shape->id);
|
||||
}
|
||||
|
||||
void lovrShapeSetUserData(Shape* shape, void* data) {
|
||||
dGeomSetData(shape->id, data);
|
||||
}
|
||||
|
|
|
@ -80,3 +80,5 @@ Body* lovrShapeGetBody(Shape* shape);
|
|||
void lovrShapeSetBody(Shape* shape, Body* body);
|
||||
int lovrShapeIsEnabled(Shape* shape);
|
||||
void lovrShapeSetEnabled(Shape* shape, int enabled);
|
||||
void* lovrShapeGetUserData(Shape* shape);
|
||||
void lovrShapeSetUserData(Shape* shape, void* data);
|
||||
|
|
Loading…
Reference in New Issue