diff --git a/src/api/audio.c b/src/api/audio.c index 2426e886..166aa460 100644 --- a/src/api/audio.c +++ b/src/api/audio.c @@ -248,8 +248,8 @@ static const luaL_Reg lovrAudio[] = { int luaopen_lovr_audio(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrAudio); - luax_registertype(L, "Microphone", lovrMicrophone); - luax_registertype(L, "Source", lovrSource); + luax_registertype(L, Microphone); + luax_registertype(L, Source); if (lovrAudioInit()) { luax_atexit(L, lovrAudioDestroy); } diff --git a/src/api/data.c b/src/api/data.c index b4b9745f..7d4e33f6 100644 --- a/src/api/data.c +++ b/src/api/data.c @@ -132,11 +132,11 @@ static const luaL_Reg lovrData[] = { int luaopen_lovr_data(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrData); - luax_registertype(L, "Blob", lovrBlob); - luax_registertype(L, "AudioStream", lovrAudioStream); - luax_registertype(L, "ModelData", lovrModelData); - luax_registertype(L, "Rasterizer", lovrRasterizer); - luax_extendtype(L, "Blob", "SoundData", lovrBlob, lovrSoundData); - luax_extendtype(L, "Blob", "TextureData", lovrBlob, lovrTextureData); + luax_registertype(L, Blob); + luax_registertype(L, AudioStream); + luax_registertype(L, ModelData); + luax_registertype(L, Rasterizer); + luax_extendtype(L, Blob, SoundData); + luax_extendtype(L, Blob, TextureData); return 1; } diff --git a/src/api/graphics.c b/src/api/graphics.c index a33ad625..0ca4bccc 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -1508,15 +1508,15 @@ static const luaL_Reg lovrGraphics[] = { int luaopen_lovr_graphics(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrGraphics); - luax_registertype(L, "Animator", lovrAnimator); - luax_registertype(L, "Font", lovrFont); - luax_registertype(L, "Material", lovrMaterial); - luax_registertype(L, "Mesh", lovrMesh); - luax_registertype(L, "Model", lovrModel); - luax_registertype(L, "Shader", lovrShader); - luax_registertype(L, "ShaderBlock", lovrShaderBlock); - luax_registertype(L, "Texture", lovrTexture); - luax_registertype(L, "Canvas", lovrCanvas); + luax_registertype(L, Animator); + luax_registertype(L, Font); + luax_registertype(L, Material); + luax_registertype(L, Mesh); + luax_registertype(L, Model); + luax_registertype(L, Shader); + luax_registertype(L, ShaderBlock); + luax_registertype(L, Texture); + luax_registertype(L, Canvas); luax_pushconf(L); diff --git a/src/api/headset.c b/src/api/headset.c index 12748a03..c9547ac8 100644 --- a/src/api/headset.c +++ b/src/api/headset.c @@ -331,7 +331,7 @@ static const luaL_Reg lovrHeadset[] = { int luaopen_lovr_headset(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrHeadset); - luax_registertype(L, "Controller", lovrController); + luax_registertype(L, Controller); luax_pushconf(L); lua_getfield(L, -1, "headset"); diff --git a/src/api/math.c b/src/api/math.c index a9632e49..c6b225f8 100644 --- a/src/api/math.c +++ b/src/api/math.c @@ -283,12 +283,12 @@ static int l_lovrLightUserdataOp(lua_State* L) { int luaopen_lovr_math(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrMath); - luax_registertype(L, "Curve", lovrCurve); - luax_registertype(L, "Pool", lovrPool); - luax_registertype(L, "RandomGenerator", lovrRandomGenerator); + luax_registertype(L, Curve); + luax_registertype(L, Pool); + luax_registertype(L, RandomGenerator); for (int i = 0; i < MAX_MATH_TYPES; i++) { - luax_registertype(L, lovrMathTypeNames[i], lovrMathTypes[i]); + _luax_registertype(L, lovrMathTypeNames[i], lovrMathTypes[i]); luaL_getmetatable(L, lovrMathTypeNames[i]); // Remove usual __gc handler diff --git a/src/api/physics.c b/src/api/physics.c index a60ffaa2..31404797 100644 --- a/src/api/physics.c +++ b/src/api/physics.c @@ -150,16 +150,16 @@ static const luaL_Reg lovrPhysics[] = { int luaopen_lovr_physics(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrPhysics); - luax_registertype(L, "World", lovrWorld); - luax_registertype(L, "Collider", lovrCollider); - luax_extendtype(L, "Joint", "BallJoint", lovrJoint, lovrBallJoint); - luax_extendtype(L, "Joint", "DistanceJoint", lovrJoint, lovrDistanceJoint); - luax_extendtype(L, "Joint", "HingeJoint", lovrJoint, lovrHingeJoint); - luax_extendtype(L, "Joint", "SliderJoint", lovrJoint, lovrSliderJoint); - luax_extendtype(L, "Shape", "SphereShape", lovrShape, lovrSphereShape); - luax_extendtype(L, "Shape", "BoxShape", lovrShape, lovrBoxShape); - luax_extendtype(L, "Shape", "CapsuleShape", lovrShape, lovrCapsuleShape); - luax_extendtype(L, "Shape", "CylinderShape", lovrShape, lovrCylinderShape); + luax_registertype(L, World); + luax_registertype(L, Collider); + luax_extendtype(L, Joint, BallJoint); + luax_extendtype(L, Joint, DistanceJoint); + luax_extendtype(L, Joint, HingeJoint); + luax_extendtype(L, Joint, SliderJoint); + luax_extendtype(L, Shape, SphereShape); + luax_extendtype(L, Shape, BoxShape); + luax_extendtype(L, Shape, CapsuleShape); + luax_extendtype(L, Shape, CylinderShape); if (lovrPhysicsInit()) { luax_atexit(L, lovrPhysicsDestroy); } diff --git a/src/api/thread.c b/src/api/thread.c index ad89203d..8161288e 100644 --- a/src/api/thread.c +++ b/src/api/thread.c @@ -67,8 +67,8 @@ static const luaL_Reg lovrThreadModule[] = { int luaopen_lovr_thread(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrThreadModule); - luax_registertype(L, "Thread", lovrThread); - luax_registertype(L, "Channel", lovrChannel); + luax_registertype(L, Thread); + luax_registertype(L, Channel); if (lovrThreadModuleInit()) { luax_atexit(L, lovrThreadModuleDestroy); } diff --git a/src/luax.c b/src/luax.c index 606fda2d..8dcca364 100644 --- a/src/luax.c +++ b/src/luax.c @@ -100,7 +100,7 @@ void luax_registerloader(lua_State* L, lua_CFunction loader, int index) { lua_pop(L, 1); } -void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions) { +void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions) { // Push metatable luaL_newmetatable(L, name); @@ -131,17 +131,10 @@ void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions lua_pop(L, 1); } -void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions) { - luax_registertype(L, name, functions); +void _luax_extendtype(lua_State* L, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions) { + _luax_registertype(L, name, functions); luaL_getmetatable(L, name); - - lua_pushstring(L, base); - lua_setfield(L, -2, "super"); - - if (baseFunctions) { - luaL_register(L, NULL, baseFunctions); - } - + luaL_register(L, NULL, baseFunctions); lua_pop(L, 1); } diff --git a/src/luax.h b/src/luax.h index 0fb3bd5c..0effdc24 100644 --- a/src/luax.h +++ b/src/luax.h @@ -11,6 +11,8 @@ #endif #define luax_len(L, i) (int) lua_objlen(L, i) +#define luax_registertype(L, T) _luax_registertype(L, #T, lovr ## T) +#define luax_extendtype(L, S, T) _luax_extendtype(L, #T, lovr ## S, lovr ## T) #define luax_totype(L, i, T) ((T*) _luax_totype(L, i, T_ ## T)) #define luax_checktype(L, i, T) ((T*) _luax_checktype(L, i, T_ ## T, #T)) #define luax_checkfloat(L, i) (float) luaL_checknumber(L, i) @@ -24,8 +26,8 @@ int luax_print(lua_State* L); void luax_setmainthread(lua_State* L); void luax_atexit(lua_State* L, luax_destructor destructor); void luax_registerloader(lua_State* L, lua_CFunction loader, int index); -void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions); -void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions); +void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions); +void _luax_extendtype(lua_State* L, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions); void* _luax_totype(lua_State* L, int index, Type type); void* _luax_checktype(lua_State* L, int index, Type type, const char* debug); void luax_pushobject(lua_State* L, void* object);