Explicitly convert lua_Numbers to floats;

This commit is contained in:
bjorn 2019-01-29 02:28:55 -08:00 committed by Bjorn Swenson
parent 03e3e14718
commit bf89216997
28 changed files with 305 additions and 303 deletions

View File

@ -157,8 +157,8 @@ static int l_lovrAudioRewind(lua_State* L) {
}
static int l_lovrAudioSetDopplerEffect(lua_State* L) {
float factor = luaL_optnumber(L, 1, 1.f);
float speedOfSound = luaL_optnumber(L, 2, 343.29f);
float factor = luax_optfloat(L, 1, 1.f);
float speedOfSound = luax_optfloat(L, 2, 343.29f);
lovrAudioSetDopplerEffect(factor, speedOfSound);
return 0;
}
@ -185,7 +185,7 @@ static int l_lovrAudioSetVelocity(lua_State* L) {
}
static int l_lovrAudioSetVolume(lua_State* L) {
float volume = luaL_checknumber(L, 1);
float volume = luax_checkfloat(L, 1);
lovrAudioSetVolume(volume);
return 0;
}

View File

@ -58,10 +58,10 @@ static int l_lovrDataNewRasterizer(lua_State* L) {
float size;
if (lua_type(L, 1) == LUA_TNUMBER || lua_isnoneornil(L, 1)) {
size = luaL_optnumber(L, 1, 32.f);
size = luax_optfloat(L, 1, 32.f);
} else {
blob = luax_readblob(L, 1, "Font");
size = luaL_optnumber(L, 2, 32.f);
size = luax_optfloat(L, 2, 32.f);
}
Rasterizer* rasterizer = lovrRasterizerCreate(blob, size);

View File

@ -484,7 +484,7 @@ static int l_lovrGraphicsGetDefaultFilter(lua_State* L) {
static int l_lovrGraphicsSetDefaultFilter(lua_State* L) {
FilterMode mode = luaL_checkoption(L, 1, NULL, FilterModes);
float anisotropy = luaL_optnumber(L, 2, 1.f);
float anisotropy = luax_optfloat(L, 2, 1.f);
lovrGraphicsSetDefaultFilter((TextureFilter) { .mode = mode, .anisotropy = anisotropy });
return 0;
}
@ -540,7 +540,7 @@ static int l_lovrGraphicsGetPointSize(lua_State* L) {
}
static int l_lovrGraphicsSetPointSize(lua_State* L) {
float size = luaL_optnumber(L, 1, 1.f);
float size = luax_optfloat(L, 1, 1.f);
lovrGraphicsSetPointSize(size);
return 0;
}
@ -670,10 +670,10 @@ static int l_lovrGraphicsClear(lua_State* L) {
if (top >= index) {
if (lua_type(L, index) == LUA_TNUMBER) {
color.r = luaL_checknumber(L, index++);
color.g = luaL_checknumber(L, index++);
color.b = luaL_checknumber(L, index++);
color.a = luaL_optnumber(L, index++, 1.f);
color.r = luax_checkfloat(L, index++);
color.g = luax_checkfloat(L, index++);
color.b = luax_checkfloat(L, index++);
color.a = luax_optfloat(L, index++, 1.f);
} else {
clearColor = lua_toboolean(L, index++);
}
@ -681,7 +681,7 @@ static int l_lovrGraphicsClear(lua_State* L) {
if (top >= index) {
if (lua_type(L, index) == LUA_TNUMBER) {
depth = luaL_checknumber(L, index++);
depth = luax_checkfloat(L, index++);
} else {
clearDepth = lua_toboolean(L, index++);
}
@ -797,8 +797,8 @@ static int l_lovrGraphicsArc(lua_State* L) {
}
float transform[16];
index = luax_readmat4(L, index, transform, 1, NULL);
float r1 = luaL_optnumber(L, index++, 0.f);
float r2 = luaL_optnumber(L, index++, 2.f * M_PI);
float r1 = luax_optfloat(L, index++, 0.f);
float r2 = luax_optfloat(L, index++, 2.f * M_PI);
int segments = luaL_optinteger(L, index, 64) * (MIN(fabsf(r2 - r1), 2 * M_PI) / (2 * M_PI));
lovrGraphicsArc(style, mode, material, transform, r1, r2, segments);
return 0;
@ -824,8 +824,8 @@ static int l_lovrGraphicsCylinder(lua_State* L) {
int index = 1;
Material* material = lua_isuserdata(L, index) ? luax_checktype(L, index++, Material) : NULL;
index = luax_readmat4(L, index, transform, 1, NULL);
float r1 = luaL_optnumber(L, index++, 1.f);
float r2 = luaL_optnumber(L, index++, 1.f);
float r1 = luax_optfloat(L, index++, 1.f);
float r2 = luax_optfloat(L, index++, 1.f);
bool capped = lua_isnoneornil(L, index) ? true : lua_toboolean(L, index++);
int segments = luaL_optinteger(L, index, (lua_Integer) floorf(16 + 16 * MAX(r1, r2)));
lovrGraphicsCylinder(material, transform, r1, r2, capped, segments);
@ -844,10 +844,10 @@ static int l_lovrGraphicsSphere(lua_State* L) {
static int l_lovrGraphicsSkybox(lua_State* L) {
Texture* texture = luax_checktexture(L, 1);
float angle = luaL_optnumber(L, 2, 0.f);
float ax = luaL_optnumber(L, 3, 0.f);
float ay = luaL_optnumber(L, 4, 1.f);
float az = luaL_optnumber(L, 5, 0.f);
float angle = luax_optfloat(L, 2, 0.f);
float ax = luax_optfloat(L, 3, 0.f);
float ay = luax_optfloat(L, 4, 1.f);
float az = luax_optfloat(L, 5, 0.f);
lovrGraphicsSkybox(texture, angle, ax, ay, az);
return 0;
}
@ -857,7 +857,7 @@ static int l_lovrGraphicsPrint(lua_State* L) {
const char* str = luaL_checklstring(L, 1, &length);
float transform[16];
int index = luax_readmat4(L, 2, transform, 1, NULL);
float wrap = luaL_optnumber(L, index++, 0.f);
float wrap = luax_optfloat(L, index++, 0.f);
HorizontalAlign halign = luaL_checkoption(L, index++, "center", HorizontalAligns);
VerticalAlign valign = luaL_checkoption(L, index++, "middle", VerticalAligns);
lovrGraphicsPrint(str, length, transform, wrap, halign, valign);
@ -880,10 +880,10 @@ static int l_lovrGraphicsStencil(lua_State* L) {
static int l_lovrGraphicsFill(lua_State* L) {
Texture* texture = lua_isnoneornil(L, 1) ? NULL : luax_checktexture(L, 1);
float u = luaL_optnumber(L, 2, 0.f);
float v = luaL_optnumber(L, 3, 0.f);
float w = luaL_optnumber(L, 4, 1.f - u);
float h = luaL_optnumber(L, 5, 1.f - v);
float u = luax_optfloat(L, 2, 0.f);
float v = luax_optfloat(L, 3, 0.f);
float w = luax_optfloat(L, 4, 1.f - u);
float h = luax_optfloat(L, 5, 1.f - v);
lovrGraphicsFill(texture, u, v, w, h);
return 0;
}

View File

@ -149,8 +149,8 @@ static int l_lovrHeadsetGetClipDistance(lua_State* L) {
}
static int l_lovrHeadsetSetClipDistance(lua_State* L) {
float clipNear = luaL_checknumber(L, 1);
float clipFar = luaL_checknumber(L, 2);
float clipNear = luax_checkfloat(L, 1);
float clipFar = luax_checkfloat(L, 2);
lovrHeadsetDriver->setClipDistance(clipNear, clipFar);
return 0;
}
@ -287,7 +287,7 @@ static int l_lovrHeadsetRenderTo(lua_State* L) {
static int l_lovrHeadsetUpdate(lua_State* L) {
if (lovrHeadsetDriver->update) {
lovrHeadsetDriver->update(luaL_checknumber(L, 1));
lovrHeadsetDriver->update(luax_checkfloat(L, 1));
}
return 0;
@ -356,7 +356,7 @@ int luaopen_lovr_headset(lua_State* L) {
// Offset
lua_getfield(L, -1, "offset");
offset = luaL_optnumber(L, -1, 1.7f);
offset = luax_optfloat(L, -1, 1.7f);
lua_pop(L, 1);
// MSAA

View File

@ -118,9 +118,9 @@ static int l_lovrMathNewRandomGenerator(lua_State* L) {
}
static int l_lovrMathLookAt(lua_State* L) {
float from[3] = { luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3) };
float to[3] = { luaL_checknumber(L, 4), luaL_checknumber(L, 5), luaL_checknumber(L, 6) };
float up[3] = { luaL_optnumber(L, 7, 0.f), luaL_optnumber(L, 8, 1.f), luaL_optnumber(L, 9, 0.f) };
float from[3] = { luax_checkfloat(L, 1), luax_checkfloat(L, 2), luax_checkfloat(L, 3) };
float to[3] = { luax_checkfloat(L, 4), luax_checkfloat(L, 5), luax_checkfloat(L, 6) };
float up[3] = { luax_optfloat(L, 7, 0.f), luax_optfloat(L, 8, 1.f), luax_optfloat(L, 9, 0.f) };
float m[16], q[4], angle, ax, ay, az;
mat4_lookAt(m, from, to, up);
quat_fromMat4(q, m);
@ -133,10 +133,10 @@ static int l_lovrMathLookAt(lua_State* L) {
}
static int l_lovrMathOrientationToDirection(lua_State* L) {
float angle = luaL_checknumber(L, 1);
float ax = luaL_optnumber(L, 2, 0.f);
float ay = luaL_optnumber(L, 3, 1.f);
float az = luaL_optnumber(L, 4, 0.f);
float angle = luax_checkfloat(L, 1);
float ax = luax_optfloat(L, 2, 0.f);
float ay = luax_optfloat(L, 3, 1.f);
float az = luax_optfloat(L, 4, 0.f);
float v[3];
lovrMathOrientationToDirection(angle, ax, ay, az, v);
lua_pushnumber(L, v[0]);
@ -148,12 +148,12 @@ static int l_lovrMathOrientationToDirection(lua_State* L) {
static int l_lovrMathNoise(lua_State* L) {
switch (lua_gettop(L)) {
case 0:
case 1: lua_pushnumber(L, lovrMathNoise1(luaL_checknumber(L, 1))); return 1;
case 2: lua_pushnumber(L, lovrMathNoise2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1;
case 3: lua_pushnumber(L, lovrMathNoise3(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3))); return 1;
case 1: lua_pushnumber(L, lovrMathNoise1(luax_checkfloat(L, 1))); return 1;
case 2: lua_pushnumber(L, lovrMathNoise2(luax_checkfloat(L, 1), luax_checkfloat(L, 2))); return 1;
case 3: lua_pushnumber(L, lovrMathNoise3(luax_checkfloat(L, 1), luax_checkfloat(L, 2), luax_checkfloat(L, 3))); return 1;
case 4:
default:
lua_pushnumber(L, lovrMathNoise4(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4)));
lua_pushnumber(L, lovrMathNoise4(luax_checkfloat(L, 1), luax_checkfloat(L, 2), luax_checkfloat(L, 3), luax_checkfloat(L, 4)));
return 1;
}
}
@ -186,14 +186,14 @@ static int l_lovrMathGammaToLinear(lua_State* L) {
if (lua_istable(L, 1)) {
for (int i = 0; i < 3; i++) {
lua_rawgeti(L, 1, i + 1);
lua_pushnumber(L, lovrMathGammaToLinear(luaL_checknumber(L, -1)));
lua_pushnumber(L, lovrMathGammaToLinear(luax_checkfloat(L, -1)));
}
lua_pop(L, 3);
return 3;
} else {
int n = CLAMP(lua_gettop(L), 1, 3);
for (int i = 0; i < n; i++) {
lua_pushnumber(L, lovrMathGammaToLinear(luaL_checknumber(L, i + 1)));
lua_pushnumber(L, lovrMathGammaToLinear(luax_checkfloat(L, i + 1)));
}
return n;
}
@ -203,14 +203,14 @@ static int l_lovrMathLinearToGamma(lua_State* L) {
if (lua_istable(L, 1)) {
for (int i = 0; i < 3; i++) {
lua_rawgeti(L, 1, i + 1);
lua_pushnumber(L, lovrMathLinearToGamma(luaL_checknumber(L, -1)));
lua_pushnumber(L, lovrMathLinearToGamma(luax_checkfloat(L, -1)));
}
lua_pop(L, 3);
return 3;
} else {
int n = CLAMP(lua_gettop(L), 1, 3);
for (int i = 0; i < n; i++) {
lua_pushnumber(L, lovrMathLinearToGamma(luaL_checknumber(L, i + 1)));
lua_pushnumber(L, lovrMathLinearToGamma(luax_checkfloat(L, i + 1)));
}
return n;
}

View File

@ -18,9 +18,9 @@ const char* JointTypes[] = {
};
static int l_lovrPhysicsNewWorld(lua_State* L) {
float xg = luaL_optnumber(L, 1, 0.f);
float yg = luaL_optnumber(L, 2, -9.81f);
float zg = luaL_optnumber(L, 3, 0.f);
float xg = luax_optfloat(L, 1, 0.f);
float yg = luax_optfloat(L, 2, -9.81f);
float zg = luax_optfloat(L, 3, 0.f);
bool allowSleep = lua_gettop(L) < 4 || lua_toboolean(L, 4);
const char* tags[16];
int tagCount;
@ -47,9 +47,9 @@ static int l_lovrPhysicsNewWorld(lua_State* L) {
static int l_lovrPhysicsNewBallJoint(lua_State* L) {
Collider* a = luax_checktype(L, 1, Collider);
Collider* b = luax_checktype(L, 2, Collider);
float x = luaL_checknumber(L, 3);
float y = luaL_checknumber(L, 4);
float z = luaL_checknumber(L, 5);
float x = luax_checkfloat(L, 3);
float y = luax_checkfloat(L, 4);
float z = luax_checkfloat(L, 5);
BallJoint* joint = lovrBallJointCreate(a, b, x, y, z);
luax_pushobject(L, joint);
lovrRelease(joint);
@ -57,9 +57,9 @@ static int l_lovrPhysicsNewBallJoint(lua_State* L) {
}
static int l_lovrPhysicsNewBoxShape(lua_State* L) {
float x = luaL_optnumber(L, 1, 1.f);
float y = luaL_optnumber(L, 2, x);
float z = luaL_optnumber(L, 3, x);
float x = luax_optfloat(L, 1, 1.f);
float y = luax_optfloat(L, 2, x);
float z = luax_optfloat(L, 3, x);
BoxShape* box = lovrBoxShapeCreate(x, y, z);
luax_pushobject(L, box);
lovrRelease(box);
@ -67,8 +67,8 @@ static int l_lovrPhysicsNewBoxShape(lua_State* L) {
}
static int l_lovrPhysicsNewCapsuleShape(lua_State* L) {
float radius = luaL_optnumber(L, 1, 1.f);
float length = luaL_optnumber(L, 2, 1.f);
float radius = luax_optfloat(L, 1, 1.f);
float length = luax_optfloat(L, 2, 1.f);
CapsuleShape* capsule = lovrCapsuleShapeCreate(radius, length);
luax_pushobject(L, capsule);
lovrRelease(capsule);
@ -76,8 +76,8 @@ static int l_lovrPhysicsNewCapsuleShape(lua_State* L) {
}
static int l_lovrPhysicsNewCylinderShape(lua_State* L) {
float radius = luaL_optnumber(L, 1, 1.f);
float length = luaL_optnumber(L, 2, 1.f);
float radius = luax_optfloat(L, 1, 1.f);
float length = luax_optfloat(L, 2, 1.f);
CylinderShape* cylinder = lovrCylinderShapeCreate(radius, length);
luax_pushobject(L, cylinder);
lovrRelease(cylinder);
@ -87,12 +87,12 @@ static int l_lovrPhysicsNewCylinderShape(lua_State* L) {
static int l_lovrPhysicsNewDistanceJoint(lua_State* L) {
Collider* a = luax_checktype(L, 1, Collider);
Collider* b = luax_checktype(L, 2, Collider);
float x1 = luaL_checknumber(L, 3);
float y1 = luaL_checknumber(L, 4);
float z1 = luaL_checknumber(L, 5);
float x2 = luaL_checknumber(L, 6);
float y2 = luaL_checknumber(L, 7);
float z2 = luaL_checknumber(L, 8);
float x1 = luax_checkfloat(L, 3);
float y1 = luax_checkfloat(L, 4);
float z1 = luax_checkfloat(L, 5);
float x2 = luax_checkfloat(L, 6);
float y2 = luax_checkfloat(L, 7);
float z2 = luax_checkfloat(L, 8);
DistanceJoint* joint = lovrDistanceJointCreate(a, b, x1, y1, z1, x2, y2, z2);
luax_pushobject(L, joint);
lovrRelease(joint);
@ -102,12 +102,12 @@ static int l_lovrPhysicsNewDistanceJoint(lua_State* L) {
static int l_lovrPhysicsNewHingeJoint(lua_State* L) {
Collider* a = luax_checktype(L, 1, Collider);
Collider* b = luax_checktype(L, 2, Collider);
float x = luaL_checknumber(L, 3);
float y = luaL_checknumber(L, 4);
float z = luaL_checknumber(L, 5);
float ax = luaL_checknumber(L, 6);
float ay = luaL_checknumber(L, 7);
float az = luaL_checknumber(L, 8);
float x = luax_checkfloat(L, 3);
float y = luax_checkfloat(L, 4);
float z = luax_checkfloat(L, 5);
float ax = luax_checkfloat(L, 6);
float ay = luax_checkfloat(L, 7);
float az = luax_checkfloat(L, 8);
HingeJoint* joint = lovrHingeJointCreate(a, b, x, y, z, ax, ay, az);
luax_pushobject(L, joint);
lovrRelease(joint);
@ -117,9 +117,9 @@ static int l_lovrPhysicsNewHingeJoint(lua_State* L) {
static int l_lovrPhysicsNewSliderJoint(lua_State* L) {
Collider* a = luax_checktype(L, 1, Collider);
Collider* b = luax_checktype(L, 2, Collider);
float ax = luaL_checknumber(L, 3);
float ay = luaL_checknumber(L, 4);
float az = luaL_checknumber(L, 5);
float ax = luax_checkfloat(L, 3);
float ay = luax_checkfloat(L, 4);
float az = luax_checkfloat(L, 5);
SliderJoint* joint = lovrSliderJointCreate(a, b, ax, ay, az);
luax_pushobject(L, joint);
lovrRelease(joint);
@ -127,7 +127,7 @@ static int l_lovrPhysicsNewSliderJoint(lua_State* L) {
}
static int l_lovrPhysicsNewSphereShape(lua_State* L) {
float radius = luaL_optnumber(L, 1, 1.f);
float radius = luax_optfloat(L, 1, 1.f);
SphereShape* sphere = lovrSphereShapeCreate(radius);
luax_pushobject(L, sphere);
lovrRelease(sphere);

View File

@ -9,7 +9,7 @@ int l_lovrAnimatorReset(lua_State* L) {
int l_lovrAnimatorUpdate(lua_State* L) {
Animator* animator = luax_checktype(L, 1, Animator);
float dt = luaL_checknumber(L, 2);
float dt = luax_checkfloat(L, 2);
lovrAnimatorUpdate(animator, dt);
return 0;
}
@ -70,7 +70,7 @@ int l_lovrAnimatorResume(lua_State* L) {
int l_lovrAnimatorSeek(lua_State* L) {
Animator* animator = luax_checktype(L, 1, Animator);
const char* animation = luaL_checkstring(L, 2);
float time = luaL_checknumber(L, 3);
float time = luax_checkfloat(L, 3);
lovrAnimatorSeek(animator, animation, time);
return 0;
}
@ -94,7 +94,7 @@ int l_lovrAnimatorGetAlpha(lua_State* L) {
int l_lovrAnimatorSetAlpha(lua_State* L) {
Animator* animator = luax_checktype(L, 1, Animator);
const char* animation = luaL_checkstring(L, 2);
float alpha = luaL_checknumber(L, 3);
float alpha = luax_checkfloat(L, 3);
lovrAnimatorSetAlpha(animator, animation, alpha);
return 0;
}
@ -164,10 +164,10 @@ int l_lovrAnimatorSetSpeed(lua_State* L) {
Animator* animator = luax_checktype(L, 1, Animator);
if (lua_type(L, 2) == LUA_TSTRING) {
const char* animation = luaL_checkstring(L, 2);
float speed = luaL_checknumber(L, 3);
float speed = luax_checkfloat(L, 3);
lovrAnimatorSetSpeed(animator, animation, speed);
} else {
float speed = luaL_checknumber(L, 2);
float speed = luax_checkfloat(L, 2);
lovrAnimatorSetSpeed(animator, NULL, speed);
}
return 0;

View File

@ -13,7 +13,7 @@ static void luax_checktimeout(lua_State* L, int index, double* timeout) {
*timeout = lua_toboolean(L, index) ? INFINITY : NAN;
break;
default:
*timeout = luaL_checknumber(L, index);
*timeout = luax_checkfloat(L, index);
break;
}
}

View File

@ -135,7 +135,7 @@ int l_lovrColliderGetMass(lua_State* L) {
int l_lovrColliderSetMass(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float mass = luaL_checknumber(L, 2);
float mass = luax_checkfloat(L, 2);
lovrColliderSetMass(collider, mass);
return 0;
}
@ -159,10 +159,10 @@ int l_lovrColliderGetMassData(lua_State* L) {
int l_lovrColliderSetMassData(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float cx = luaL_checknumber(L, 2);
float cy = luaL_checknumber(L, 3);
float cz = luaL_checknumber(L, 4);
float mass = luaL_checknumber(L, 5);
float cx = luax_checkfloat(L, 2);
float cy = luax_checkfloat(L, 3);
float cz = luax_checkfloat(L, 4);
float mass = luax_checkfloat(L, 5);
float inertia[6];
if (lua_istable(L, 6) && lua_objlen(L, 6) >= 6) {
for (int i = 0; i < 6; i++) {
@ -199,9 +199,9 @@ int l_lovrColliderGetPosition(lua_State* L) {
int l_lovrColliderSetPosition(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrColliderSetPosition(collider, x, y, z);
return 0;
}
@ -219,10 +219,10 @@ int l_lovrColliderGetOrientation(lua_State* L) {
int l_lovrColliderSetOrientation(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float angle = luaL_checknumber(L, 2);
float x = luaL_checknumber(L, 3);
float y = luaL_checknumber(L, 4);
float z = luaL_checknumber(L, 5);
float angle = luax_checkfloat(L, 2);
float x = luax_checkfloat(L, 3);
float y = luax_checkfloat(L, 4);
float z = luax_checkfloat(L, 5);
lovrColliderSetOrientation(collider, angle, x, y, z);
return 0;
}
@ -239,9 +239,9 @@ int l_lovrColliderGetLinearVelocity(lua_State* L) {
int l_lovrColliderSetLinearVelocity(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrColliderSetLinearVelocity(collider, x, y, z);
return 0;
}
@ -258,9 +258,9 @@ int l_lovrColliderGetAngularVelocity(lua_State* L) {
int l_lovrColliderSetAngularVelocity(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrColliderSetAngularVelocity(collider, x, y, z);
return 0;
}
@ -276,8 +276,8 @@ int l_lovrColliderGetLinearDamping(lua_State* L) {
int l_lovrColliderSetLinearDamping(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01f);
float damping = luax_checkfloat(L, 2);
float threshold = luax_optfloat(L, 3, .01f);
lovrColliderSetLinearDamping(collider, damping, threshold);
return 0;
}
@ -293,22 +293,22 @@ int l_lovrColliderGetAngularDamping(lua_State* L) {
int l_lovrColliderSetAngularDamping(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01f);
float damping = luax_checkfloat(L, 2);
float threshold = luax_optfloat(L, 3, .01f);
lovrColliderSetAngularDamping(collider, damping, threshold);
return 0;
}
int l_lovrColliderApplyForce(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
if (lua_gettop(L) > 4) {
float cx = luaL_checknumber(L, 5);
float cy = luaL_checknumber(L, 6);
float cz = luaL_checknumber(L, 7);
float cx = luax_checkfloat(L, 5);
float cy = luax_checkfloat(L, 6);
float cz = luax_checkfloat(L, 7);
lovrColliderApplyForceAtPosition(collider, x, y, z, cx, cy, cz);
} else {
lovrColliderApplyForce(collider, x, y, z);
@ -319,9 +319,9 @@ int l_lovrColliderApplyForce(lua_State* L) {
int l_lovrColliderApplyTorque(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrColliderApplyTorque(collider, x, y, z);
return 0;
}
@ -338,9 +338,9 @@ int l_lovrColliderGetLocalCenter(lua_State* L) {
int l_lovrColliderGetLocalPoint(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float wx = luaL_checknumber(L, 2);
float wy = luaL_checknumber(L, 3);
float wz = luaL_checknumber(L, 4);
float wx = luax_checkfloat(L, 2);
float wy = luax_checkfloat(L, 3);
float wz = luax_checkfloat(L, 4);
float x, y, z;
lovrColliderGetLocalPoint(collider, wx, wy, wz, &x, &y, &z);
lua_pushnumber(L, x);
@ -351,9 +351,9 @@ int l_lovrColliderGetLocalPoint(lua_State* L) {
int l_lovrColliderGetWorldPoint(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
float wx, wy, wz;
lovrColliderGetWorldPoint(collider, x, y, z, &wx, &wy, &wz);
lua_pushnumber(L, wx);
@ -364,9 +364,9 @@ int l_lovrColliderGetWorldPoint(lua_State* L) {
int l_lovrColliderGetLocalVector(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float wx = luaL_checknumber(L, 2);
float wy = luaL_checknumber(L, 3);
float wz = luaL_checknumber(L, 4);
float wx = luax_checkfloat(L, 2);
float wy = luax_checkfloat(L, 3);
float wz = luax_checkfloat(L, 4);
float x, y, z;
lovrColliderGetLocalVector(collider, wx, wy, wz, &x, &y, &z);
lua_pushnumber(L, x);
@ -377,9 +377,9 @@ int l_lovrColliderGetLocalVector(lua_State* L) {
int l_lovrColliderGetWorldVector(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
float wx, wy, wz;
lovrColliderGetWorldVector(collider, x, y, z, &wx, &wy, &wz);
lua_pushnumber(L, wx);
@ -390,9 +390,9 @@ int l_lovrColliderGetWorldVector(lua_State* L) {
int l_lovrColliderGetLinearVelocityFromLocalPoint(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
float vx, vy, vz;
lovrColliderGetLinearVelocityFromLocalPoint(collider, x, y, z, &vx, &vy, &vz);
lua_pushnumber(L, vx);
@ -403,9 +403,9 @@ int l_lovrColliderGetLinearVelocityFromLocalPoint(lua_State* L) {
int l_lovrColliderGetLinearVelocityFromWorldPoint(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
float vx, vy, vz;
lovrColliderGetLinearVelocityFromWorldPoint(collider, x, y, z, &vx, &vy, &vz);
lua_pushnumber(L, vx);
@ -432,7 +432,7 @@ int l_lovrColliderGetFriction(lua_State* L) {
int l_lovrColliderSetFriction(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float friction = luaL_checknumber(L, 2);
float friction = luax_checkfloat(L, 2);
lovrColliderSetFriction(collider, friction);
return 0;
}
@ -445,7 +445,7 @@ int l_lovrColliderGetRestitution(lua_State* L) {
int l_lovrColliderSetRestitution(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
float restitution = luaL_checknumber(L, 2);
float restitution = luax_checkfloat(L, 2);
lovrColliderSetRestitution(collider, restitution);
return 0;
}

View File

@ -95,8 +95,8 @@ int l_lovrControllerIsTouched(lua_State* L) {
int l_lovrControllerVibrate(lua_State* L) {
Controller* controller = luax_checktype(L, 1, Controller);
float duration = luaL_optnumber(L, 2, .5f);
float power = luaL_optnumber(L, 3, 1.f);
float duration = luax_optfloat(L, 2, .5f);
float power = luax_optfloat(L, 3, 1.f);
lovrHeadsetDriver->controllerVibrate(controller, duration, power);
return 0;
}

View File

@ -4,7 +4,7 @@
int l_lovrCurveEvaluate(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
float t = luaL_checknumber(L, 2);
float t = luax_checkfloat(L, 2);
float point[3];
lovrCurveEvaluate(curve, t, point);
lua_pushnumber(L, point[0]);
@ -15,7 +15,7 @@ int l_lovrCurveEvaluate(lua_State* L) {
int l_lovrCurveGetTangent(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
float t = luaL_checknumber(L, 2);
float t = luax_checkfloat(L, 2);
float point[3];
lovrCurveGetTangent(curve, t, point);
lua_pushnumber(L, point[0]);
@ -27,8 +27,8 @@ int l_lovrCurveGetTangent(lua_State* L) {
int l_lovrCurveRender(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
int n = luaL_optinteger(L, 2, 32);
float t1 = luaL_optnumber(L, 3, 0.);
float t2 = luaL_optnumber(L, 4, 1.);
float t1 = luax_optfloat(L, 3, 0.);
float t2 = luax_optfloat(L, 4, 1.);
float* points = malloc(3 * n * sizeof(float));
lovrAssert(points, "Out of memory");
lovrCurveRender(curve, t1, t2, points, n);
@ -43,8 +43,8 @@ int l_lovrCurveRender(lua_State* L) {
int l_lovrCurveSlice(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
float t1 = luaL_checknumber(L, 2);
float t2 = luaL_checknumber(L, 3);
float t1 = luax_checkfloat(L, 2);
float t2 = luax_checkfloat(L, 3);
Curve* subcurve = lovrCurveSlice(curve, t1, t2);
luax_pushobject(L, subcurve);
return 1;

View File

@ -5,7 +5,7 @@ int l_lovrFontGetWidth(lua_State* L) {
Font* font = luax_checktype(L, 1, Font);
size_t length;
const char* string = luaL_checklstring(L, 2, &length);
float wrap = luaL_optnumber(L, 3, 0.f);
float wrap = luax_optfloat(L, 3, 0.f);
float width;
uint32_t lineCount;
uint32_t glyphCount;
@ -46,7 +46,7 @@ int l_lovrFontGetLineHeight(lua_State* L) {
int l_lovrFontSetLineHeight(lua_State* L) {
Font* font = luax_checktype(L, 1, Font);
float lineHeight = luaL_checknumber(L, 2);
float lineHeight = luax_checkfloat(L, 2);
lovrFontSetLineHeight(font, lineHeight);
return 0;
}
@ -74,7 +74,7 @@ int l_lovrFontSetPixelDensity(lua_State* L) {
if (lua_isnoneornil(L, 2)) {
lovrFontSetPixelDensity(font, lovrFontGetRasterizer(font)->height);
} else {
float pixelDensity = luaL_optnumber(L, 2, -1.f);
float pixelDensity = luax_optfloat(L, 2, -1.f);
lovrFontSetPixelDensity(font, pixelDensity);
}
return 0;

View File

@ -71,9 +71,9 @@ int l_lovrBallJointGetAnchors(lua_State* L) {
int l_lovrBallJointSetAnchor(lua_State* L) {
BallJoint* joint = luax_checktype(L, 1, BallJoint);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrBallJointSetAnchor(joint, x, y, z);
return 0;
}
@ -99,12 +99,12 @@ int l_lovrDistanceJointGetAnchors(lua_State* L) {
int l_lovrDistanceJointSetAnchors(lua_State* L) {
DistanceJoint* joint = luax_checktype(L, 1, DistanceJoint);
float x1 = luaL_checknumber(L, 2);
float y1 = luaL_checknumber(L, 3);
float z1 = luaL_checknumber(L, 4);
float x2 = luaL_checknumber(L, 5);
float y2 = luaL_checknumber(L, 6);
float z2 = luaL_checknumber(L, 7);
float x1 = luax_checkfloat(L, 2);
float y1 = luax_checkfloat(L, 3);
float z1 = luax_checkfloat(L, 4);
float x2 = luax_checkfloat(L, 5);
float y2 = luax_checkfloat(L, 6);
float z2 = luax_checkfloat(L, 7);
lovrDistanceJointSetAnchors(joint, x1, y1, z1, x2, y2, z2);
return 0;
}
@ -117,7 +117,7 @@ int l_lovrDistanceJointGetDistance(lua_State* L) {
int l_lovrDistanceJointSetDistance(lua_State* L) {
DistanceJoint* joint = luax_checktype(L, 1, DistanceJoint);
float distance = luaL_checknumber(L, 2);
float distance = luax_checkfloat(L, 2);
lovrDistanceJointSetDistance(joint, distance);
return 0;
}
@ -145,9 +145,9 @@ int l_lovrHingeJointGetAnchors(lua_State* L) {
int l_lovrHingeJointSetAnchor(lua_State* L) {
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrHingeJointSetAnchor(joint, x, y, z);
return 0;
}
@ -164,9 +164,9 @@ int l_lovrHingeJointGetAxis(lua_State* L) {
int l_lovrHingeJointSetAxis(lua_State* L) {
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrHingeJointSetAxis(joint, x, y, z);
return 0;
}
@ -185,7 +185,7 @@ int l_lovrHingeJointGetLowerLimit(lua_State* L) {
int l_lovrHingeJointSetLowerLimit(lua_State* L) {
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float limit = luaL_checknumber(L, 2);
float limit = luax_checkfloat(L, 2);
lovrHingeJointSetLowerLimit(joint, limit);
return 0;
}
@ -198,7 +198,7 @@ int l_lovrHingeJointGetUpperLimit(lua_State* L) {
int l_lovrHingeJointSetUpperLimit(lua_State* L) {
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float limit = luaL_checknumber(L, 2);
float limit = luax_checkfloat(L, 2);
lovrHingeJointSetUpperLimit(joint, limit);
return 0;
}
@ -212,8 +212,8 @@ int l_lovrHingeJointGetLimits(lua_State* L) {
int l_lovrHingeJointSetLimits(lua_State* L) {
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float lower = luaL_checknumber(L, 2);
float upper = luaL_checknumber(L, 3);
float lower = luax_checkfloat(L, 2);
float upper = luax_checkfloat(L, 3);
lovrHingeJointSetLowerLimit(joint, lower);
lovrHingeJointSetUpperLimit(joint, upper);
return 0;
@ -246,9 +246,9 @@ int l_lovrSliderJointGetAxis(lua_State* L) {
int l_lovrSliderJointSetAxis(lua_State* L) {
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrSliderJointSetAxis(joint, x, y, z);
return 0;
}
@ -267,7 +267,7 @@ int l_lovrSliderJointGetLowerLimit(lua_State* L) {
int l_lovrSliderJointSetLowerLimit(lua_State* L) {
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float limit = luaL_checknumber(L, 2);
float limit = luax_checkfloat(L, 2);
lovrSliderJointSetLowerLimit(joint, limit);
return 0;
}
@ -280,7 +280,7 @@ int l_lovrSliderJointGetUpperLimit(lua_State* L) {
int l_lovrSliderJointSetUpperLimit(lua_State* L) {
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float limit = luaL_checknumber(L, 2);
float limit = luax_checkfloat(L, 2);
lovrSliderJointSetUpperLimit(joint, limit);
return 0;
}
@ -294,8 +294,8 @@ int l_lovrSliderJointGetLimits(lua_State* L) {
int l_lovrSliderJointSetLimits(lua_State* L) {
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float lower = luaL_checknumber(L, 2);
float upper = luaL_checknumber(L, 3);
float lower = luax_checkfloat(L, 2);
float upper = luax_checkfloat(L, 3);
lovrSliderJointSetLowerLimit(joint, lower);
lovrSliderJointSetUpperLimit(joint, upper);
return 0;

View File

@ -47,10 +47,10 @@ int l_lovrMat4Set(lua_State* L) {
mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL);
switch (lua_gettop(L)) {
case 1: mat4_identity(m); break;
case 2: m[0] = m[5] = m[10] = m[15] = luaL_checknumber(L, 2); break;
case 2: m[0] = m[5] = m[10] = m[15] = luax_checkfloat(L, 2); break;
default:
for (int i = 0; i < 16; i++) {
m[i] = luaL_checknumber(L, i + 2);
m[i] = luax_checkfloat(L, i + 2);
}
break;
}
@ -91,7 +91,7 @@ static int l_lovrMat4Transpose(lua_State* L) {
static int l_lovrMat4Translate(lua_State* L) {
mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL);
if (lua_type(L, 2) == LUA_TNUMBER) {
mat4_translate(m, luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4));
mat4_translate(m, luax_checkfloat(L, 2), luax_checkfloat(L, 3), luax_checkfloat(L, 4));
} else {
float* v = luax_checkmathtype(L, 2, MATH_VEC3, "vec3 or number");
mat4_translate(m, v[0], v[1], v[2]);
@ -103,7 +103,7 @@ static int l_lovrMat4Translate(lua_State* L) {
static int l_lovrMat4Rotate(lua_State* L) {
mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL);
if (lua_type(L, 2) == LUA_TNUMBER) {
mat4_rotate(m, luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), luaL_checknumber(L, 5));
mat4_rotate(m, luax_checkfloat(L, 2), luax_checkfloat(L, 3), luax_checkfloat(L, 4), luax_checkfloat(L, 5));
} else {
float* q = luax_checkmathtype(L, 2, MATH_QUAT, "quat or number");
mat4_rotateQuat(m, q);
@ -115,8 +115,8 @@ static int l_lovrMat4Rotate(lua_State* L) {
static int l_lovrMat4Scale(lua_State* L) {
mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL);
if (lua_type(L, 2) == LUA_TNUMBER) {
float x = luaL_checknumber(L, 2);
mat4_scale(m, x, luaL_optnumber(L, 3, x), luaL_optnumber(L, 4, x));
float x = luax_checkfloat(L, 2);
mat4_scale(m, x, luax_optfloat(L, 3, x), luax_optfloat(L, 4, x));
} else {
float* s = luax_checkmathtype(L, 2, MATH_VEC3, "vec3 or number");
mat4_scale(m, s[0], s[1], s[2]);
@ -170,16 +170,16 @@ static int l_lovrMat4GetTransform(lua_State* L) {
static int l_lovrMat4SetTransform(lua_State* L) {
mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL);
float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.f);
float sx = luaL_optnumber(L, 5, 1.f);
float sy = luaL_optnumber(L, 6, sx);
float sz = luaL_optnumber(L, 7, sx);
float angle = luaL_optnumber(L, 8, 0.f);
float ax = luaL_optnumber(L, 9, 0.f);
float ay = luaL_optnumber(L, 10, 1.f);
float az = luaL_optnumber(L, 11, 0.f);
float x = luax_optfloat(L, 2, 0.f);
float y = luax_optfloat(L, 3, 0.f);
float z = luax_optfloat(L, 4, 0.f);
float sx = luax_optfloat(L, 5, 1.f);
float sy = luax_optfloat(L, 6, sx);
float sz = luax_optfloat(L, 7, sx);
float angle = luax_optfloat(L, 8, 0.f);
float ax = luax_optfloat(L, 9, 0.f);
float ay = luax_optfloat(L, 10, 1.f);
float az = luax_optfloat(L, 11, 0.f);
mat4_setTransform(m, x, y, z, sx, sy, sz, angle, ax, ay, az);
lua_settop(L, 1);
return 1;
@ -198,10 +198,10 @@ static int l_lovrMat4TransformPoint(lua_State* L) {
static int l_lovrMat4Perspective(lua_State* L) {
mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL);
float clipNear = luaL_checknumber(L, 2);
float clipFar = luaL_checknumber(L, 3);
float fov = luaL_checknumber(L, 4);
float aspect = luaL_checknumber(L, 5);
float clipNear = luax_checkfloat(L, 2);
float clipFar = luax_checkfloat(L, 3);
float fov = luax_checkfloat(L, 4);
float aspect = luax_checkfloat(L, 5);
mat4_perspective(m, clipNear, clipFar, fov, aspect);
lua_settop(L, 1);
return 1;
@ -209,12 +209,12 @@ static int l_lovrMat4Perspective(lua_State* L) {
static int l_lovrMat4Orthographic(lua_State* L) {
mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL);
float left = luaL_checknumber(L, 2);
float right = luaL_checknumber(L, 3);
float top = luaL_checknumber(L, 4);
float bottom = luaL_checknumber(L, 5);
float clipNear = luaL_checknumber(L, 6);
float clipFar = luaL_checknumber(L, 7);
float left = luax_checkfloat(L, 2);
float right = luax_checkfloat(L, 3);
float top = luax_checkfloat(L, 4);
float bottom = luax_checkfloat(L, 5);
float clipNear = luax_checkfloat(L, 6);
float clipFar = luax_checkfloat(L, 7);
mat4_orthographic(m, left, right, top, bottom, clipNear, clipFar);
lua_settop(L, 1);
return 1;

View File

@ -37,7 +37,7 @@ int l_lovrMaterialGetScalar(lua_State* L) {
int l_lovrMaterialSetScalar(lua_State* L) {
Material* material = luax_checktype(L, 1, Material);
MaterialScalar scalarType = luaL_checkoption(L, 2, NULL, MaterialScalars);
float value = luaL_checknumber(L, 3);
float value = luax_checkfloat(L, 3);
lovrMaterialSetScalar(material, scalarType, value);
return 0;
}
@ -77,11 +77,11 @@ int l_lovrMaterialGetTransform(lua_State* L) {
int l_lovrMaterialSetTransform(lua_State* L) {
Material* material = luax_checktype(L, 1, Material);
float ox = luaL_optnumber(L, 2, 0.f);
float oy = luaL_optnumber(L, 3, 0.f);
float sx = luaL_optnumber(L, 4, 1.f);
float sy = luaL_optnumber(L, 5, sx);
float angle = luaL_optnumber(L, 6, 0.f);
float ox = luax_optfloat(L, 2, 0.f);
float oy = luax_optfloat(L, 3, 0.f);
float sx = luax_optfloat(L, 4, 1.f);
float sy = luax_optfloat(L, 5, sx);
float angle = luax_optfloat(L, 6, 0.f);
lovrMaterialSetTransform(material, ox, oy, sx, sy, angle);
return 0;
}

View File

@ -10,10 +10,10 @@ int luax_readquat(lua_State* L, int index, quat q, const char* expected) {
quat_set(q, 0, 0, 0, 0);
return ++index;
case LUA_TNUMBER:
angle = luaL_optnumber(L, index++, 0.f);
ax = luaL_optnumber(L, index++, 0.f);
ay = luaL_optnumber(L, index++, 1.f);
az = luaL_optnumber(L, index++, 0.f);
angle = luax_optfloat(L, index++, 0.f);
ax = luax_optfloat(L, index++, 0.f);
ay = luax_optfloat(L, index++, 1.f);
az = luax_optfloat(L, index++, 0.f);
quat_fromAngleAxis(q, angle, ax, ay, az);
return index;
default:
@ -48,9 +48,9 @@ int l_lovrQuatSet(lua_State* L) {
} else if (lua_type(L, 2) == LUA_TNUMBER) {
float x = lua_tonumber(L, 2);
if (lua_type(L, 3) == LUA_TNUMBER) {
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float w = luaL_checknumber(L, 5);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
float w = luax_checkfloat(L, 5);
bool raw = lua_toboolean(L, 6);
if (raw) {
quat_set(q, x, y, z, w);
@ -119,7 +119,7 @@ static int l_lovrQuatNormalize(lua_State* L) {
static int l_lovrQuatSlerp(lua_State* L) {
quat q = luax_checkmathtype(L, 1, MATH_QUAT, NULL);
quat r = luax_checkmathtype(L, 2, MATH_QUAT, NULL);
float t = luaL_checknumber(L, 3);
float t = luax_checkfloat(L, 3);
quat_slerp(q, r, t);
lua_settop(L, 1);
return 1;

View File

@ -79,8 +79,8 @@ int l_lovrRandomGeneratorRandom(lua_State* L) {
int l_lovrRandomGeneratorRandomNormal(lua_State* L) {
RandomGenerator* generator = luax_checktype(L, 1, RandomGenerator);
float sigma = luaL_optnumber(L, 2, 1.f);
float mu = luaL_optnumber(L, 3, 0.f);
float sigma = luax_optfloat(L, 2, 1.f);
float mu = luax_optfloat(L, 3, 0.f);
lua_pushnumber(L, mu + lovrRandomGeneratorRandomNormal(generator) * sigma);
return 1;
}

View File

@ -59,7 +59,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des
}
switch (uniformType) {
case UNIFORM_FLOAT: *((float*) dest + i) = luaL_optnumber(L, j, 0.f); break;
case UNIFORM_FLOAT: *((float*) dest + i) = luax_optfloat(L, j, 0.f); break;
case UNIFORM_INT: *((int*) dest + i) = luaL_optinteger(L, j, 0); break;
case UNIFORM_SAMPLER:
*((Texture**) dest + i) = luax_checktype(L, j, Texture);
@ -124,7 +124,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des
switch (uniformType) {
case UNIFORM_FLOAT:
case UNIFORM_MATRIX:
*((float*) dest + i * components + j) = luaL_optnumber(L, -1, 0.f);
*((float*) dest + i * components + j) = luax_optfloat(L, -1, 0.f);
break;
case UNIFORM_INT:
@ -163,7 +163,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des
switch (uniformType) {
case UNIFORM_FLOAT:
case UNIFORM_MATRIX:
*((float*) dest + i * components + j) = luaL_optnumber(L, -1, 0.f);
*((float*) dest + i * components + j) = luax_optfloat(L, -1, 0.f);
break;
case UNIFORM_INT:

View File

@ -68,9 +68,9 @@ int l_lovrShapeGetPosition(lua_State* L) {
int l_lovrShapeSetPosition(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrShapeSetPosition(shape, x, y, z);
return 0;
}
@ -88,17 +88,17 @@ int l_lovrShapeGetOrientation(lua_State* L) {
int l_lovrShapeSetOrientation(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
float angle = luaL_checknumber(L, 2);
float x = luaL_checknumber(L, 3);
float y = luaL_checknumber(L, 4);
float z = luaL_checknumber(L, 5);
float angle = luax_checkfloat(L, 2);
float x = luax_checkfloat(L, 3);
float y = luax_checkfloat(L, 4);
float z = luax_checkfloat(L, 5);
lovrShapeSetOrientation(shape, angle, x, y, z);
return 0;
}
int l_lovrShapeGetMass(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
float density = luaL_checknumber(L, 2);
float density = luax_checkfloat(L, 2);
float cx, cy, cz, mass;
float inertia[6];
lovrShapeGetMass(shape, density, &cx, &cy, &cz, &mass, inertia);
@ -149,7 +149,7 @@ int l_lovrSphereShapeGetRadius(lua_State* L) {
int l_lovrSphereShapeSetRadius(lua_State* L) {
SphereShape* sphere = luax_checktype(L, 1, SphereShape);
float radius = luaL_checknumber(L, 2);
float radius = luax_checkfloat(L, 2);
lovrSphereShapeSetRadius(sphere, radius);
return 0;
}
@ -172,9 +172,9 @@ int l_lovrBoxShapeGetDimensions(lua_State* L) {
int l_lovrBoxShapeSetDimensions(lua_State* L) {
BoxShape* box = luax_checktype(L, 1, BoxShape);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrBoxShapeSetDimensions(box, x, y, z);
return 0;
}
@ -193,7 +193,7 @@ int l_lovrCapsuleShapeGetRadius(lua_State* L) {
int l_lovrCapsuleShapeSetRadius(lua_State* L) {
CapsuleShape* capsule = luax_checktype(L, 1, CapsuleShape);
float radius = luaL_checknumber(L, 2);
float radius = luax_checkfloat(L, 2);
lovrCapsuleShapeSetRadius(capsule, radius);
return 0;
}
@ -206,7 +206,7 @@ int l_lovrCapsuleShapeGetLength(lua_State* L) {
int l_lovrCapsuleShapeSetLength(lua_State* L) {
CapsuleShape* capsule = luax_checktype(L, 1, CapsuleShape);
float length = luaL_checknumber(L, 2);
float length = luax_checkfloat(L, 2);
lovrCapsuleShapeSetLength(capsule, length);
return 0;
}
@ -227,7 +227,7 @@ int l_lovrCylinderShapeGetRadius(lua_State* L) {
int l_lovrCylinderShapeSetRadius(lua_State* L) {
CylinderShape* cylinder = luax_checktype(L, 1, CylinderShape);
float radius = luaL_checknumber(L, 2);
float radius = luax_checkfloat(L, 2);
lovrCylinderShapeSetRadius(cylinder, radius);
return 0;
}
@ -240,7 +240,7 @@ int l_lovrCylinderShapeGetLength(lua_State* L) {
int l_lovrCylinderShapeSetLength(lua_State* L) {
CylinderShape* cylinder = luax_checktype(L, 1, CylinderShape);
float length = luaL_checknumber(L, 2);
float length = luax_checkfloat(L, 2);
lovrCylinderShapeSetLength(cylinder, length);
return 0;
}

View File

@ -41,7 +41,7 @@ int l_lovrSoundDataGetSampleRate(lua_State* L) {
int l_lovrSoundDataSetSample(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
int index = luaL_checkinteger(L, 2);
float value = luaL_checknumber(L, 3);
float value = luax_checkfloat(L, 3);
lovrSoundDataSetSample(soundData, index, value);
return 0;
}

View File

@ -161,7 +161,7 @@ int l_lovrSourceSeek(lua_State* L) {
TimeUnit unit = luaL_checkoption(L, 3, "seconds", TimeUnits);
if (unit == UNIT_SECONDS) {
float seconds = luaL_checknumber(L, 2);
float seconds = luax_checkfloat(L, 2);
int sampleRate = lovrSourceGetSampleRate(source);
lovrSourceSeek(source, (int) (seconds * sampleRate + .5f));
} else {
@ -173,18 +173,18 @@ int l_lovrSourceSeek(lua_State* L) {
int l_lovrSourceSetCone(lua_State* L) {
Source* source = luax_checktype(L, 1, Source);
float innerAngle = luaL_checknumber(L, 1);
float outerAngle = luaL_checknumber(L, 2);
float outerGain = luaL_checknumber(L, 3);
float innerAngle = luax_checkfloat(L, 1);
float outerAngle = luax_checkfloat(L, 2);
float outerGain = luax_checkfloat(L, 3);
lovrSourceSetCone(source, innerAngle, outerAngle, outerGain);
return 0;
}
int l_lovrSourceSetFalloff(lua_State* L) {
Source* source = luax_checktype(L, 1, Source);
float reference = luaL_checknumber(L, 2);
float max = luaL_checknumber(L, 3);
float rolloff = luaL_checknumber(L, 4);
float reference = luax_checkfloat(L, 2);
float max = luax_checkfloat(L, 3);
float rolloff = luax_checkfloat(L, 4);
lovrSourceSetFalloff(source, reference, max, rolloff);
return 0;
}
@ -203,7 +203,7 @@ int l_lovrSourceSetDirection(lua_State* L) {
}
int l_lovrSourceSetPitch(lua_State* L) {
lovrSourceSetPitch(luax_checktype(L, 1, Source), luaL_checknumber(L, 2));
lovrSourceSetPitch(luax_checktype(L, 1, Source), luax_checkfloat(L, 2));
return 0;
}
@ -231,12 +231,12 @@ int l_lovrSourceSetVelocity(lua_State* L) {
}
int l_lovrSourceSetVolume(lua_State* L) {
lovrSourceSetVolume(luax_checktype(L, 1, Source), luaL_checknumber(L, 2));
lovrSourceSetVolume(luax_checktype(L, 1, Source), luax_checkfloat(L, 2));
return 0;
}
int l_lovrSourceSetVolumeLimits(lua_State* L) {
lovrSourceSetVolumeLimits(luax_checktype(L, 1, Source), luaL_checknumber(L, 2), luaL_checknumber(L, 3));
lovrSourceSetVolumeLimits(luax_checktype(L, 1, Source), luax_checkfloat(L, 2), luax_checkfloat(L, 3));
return 0;
}

View File

@ -92,7 +92,7 @@ int l_lovrTextureReplacePixels(lua_State* L) {
int l_lovrTextureSetFilter(lua_State* L) {
Texture* texture = luax_checktype(L, 1, Texture);
FilterMode mode = luaL_checkoption(L, 2, NULL, FilterModes);
float anisotropy = luaL_optnumber(L, 3, 1.f);
float anisotropy = luax_optfloat(L, 3, 1.f);
TextureFilter filter = { .mode = mode, .anisotropy = anisotropy };
lovrTextureSetFilter(texture, filter);
return 0;

View File

@ -45,10 +45,10 @@ int l_lovrTextureDataSetPixel(lua_State* L) {
int x = luaL_checkinteger(L, 2);
int y = luaL_checkinteger(L, 3);
Color color = {
luaL_checknumber(L, 4),
luaL_checknumber(L, 5),
luaL_checknumber(L, 6),
luaL_optnumber(L, 7, 1.f)
luax_checkfloat(L, 4),
luax_checkfloat(L, 5),
luax_checkfloat(L, 6),
luax_optfloat(L, 7, 1.f)
};
lovrTextureDataSetPixel(textureData, x, y, color);
return 0;

View File

@ -10,9 +10,9 @@ int luax_readvec3(lua_State* L, int index, vec3 v, const char* expected) {
v[0] = v[1] = v[2] = 0.f;
return ++index;
case LUA_TNUMBER:
v[0] = luaL_optnumber(L, index++, 0.f);
v[1] = luaL_optnumber(L, index++, 0.f);
v[2] = luaL_optnumber(L, index++, 0.f);
v[0] = luax_optfloat(L, index++, 0.f);
v[1] = luax_optfloat(L, index++, 0.f);
v[2] = luax_optfloat(L, index++, 0.f);
return index;
default:
vec3_init(v, luax_checkmathtype(L, index++, MATH_VEC3, expected ? expected : "vec3 or number"));
@ -28,11 +28,11 @@ int luax_readscale(lua_State* L, int index, vec3 v, int components, const char*
return index + components;
case LUA_TNUMBER:
if (components == 1) {
v[0] = v[1] = v[2] = luaL_optnumber(L, index++, 0.f);
v[0] = v[1] = v[2] = luax_optfloat(L, index++, 0.f);
} else {
v[0] = 1.f;
for (int i = 0; i < components; i++) {
v[i] = luaL_optnumber(L, index++, v[0]);
v[i] = luax_optfloat(L, index++, v[0]);
}
}
return index;
@ -53,8 +53,8 @@ static int l_lovrVec3Unpack(lua_State* L) {
int l_lovrVec3Set(lua_State* L) {
vec3 v = luax_checkmathtype(L, 1, MATH_VEC3, NULL);
if (lua_isnoneornil(L, 2) || lua_type(L, 2) == LUA_TNUMBER) {
float x = luaL_optnumber(L, 2, 0.f);
vec3_set(v, x, luaL_optnumber(L, 3, x), luaL_optnumber(L, 4, x));
float x = luax_optfloat(L, 2, 0.f);
vec3_set(v, x, luax_optfloat(L, 3, x), luax_optfloat(L, 4, x));
} else {
vec3 u = luax_checkmathtype(L, 2, MATH_VEC3, "vec3 or number");
vec3_init(v, u);
@ -150,7 +150,7 @@ static int l_lovrVec3Cross(lua_State* L) {
static int l_lovrVec3Lerp(lua_State* L) {
vec3 v = luax_checkmathtype(L, 1, MATH_VEC3, NULL);
vec3 u = luax_checkmathtype(L, 2, MATH_VEC3, NULL);
float t = luaL_checknumber(L, 3);
float t = luax_checkfloat(L, 3);
vec3_lerp(v, u, t);
lua_settop(L, 1);
return 1;

View File

@ -16,7 +16,7 @@ int luax_loadvertices(lua_State* L, int index, VertexFormat* format, VertexPoint
for (int k = 0; k < attribute.count; k++) {
lua_rawgeti(L, -1, ++component);
switch (attribute.type) {
case ATTR_FLOAT: *vertices.floats++ = luaL_optnumber(L, -1, 0.f); break;
case ATTR_FLOAT: *vertices.floats++ = luax_optfloat(L, -1, 0.f); break;
case ATTR_BYTE: *vertices.bytes++ = luaL_optint(L, -1, 255); break;
case ATTR_INT: *vertices.ints++ = luaL_optint(L, -1, 0); break;
}
@ -105,7 +105,7 @@ int luax_pushvertex(lua_State* L, VertexPointer* vertex, VertexFormat* format) {
void luax_setvertexattribute(lua_State* L, int index, VertexPointer* vertex, Attribute attribute) {
for (int i = 0; i < attribute.count; i++) {
switch (attribute.type) {
case ATTR_FLOAT: *vertex->floats++ = luaL_optnumber(L, index++, 0.f); break;
case ATTR_FLOAT: *vertex->floats++ = luax_optfloat(L, index++, 0.f); break;
case ATTR_BYTE: *vertex->bytes++ = luaL_optint(L, index++, 255); break;
case ATTR_INT: *vertex->ints++ = luaL_optint(L, index++, 0); break;
}
@ -120,7 +120,7 @@ void luax_setvertex(lua_State* L, int index, VertexPointer* vertex, VertexFormat
for (int j = 0; j < attribute.count; j++) {
lua_rawgeti(L, index, ++component);
switch (attribute.type) {
case ATTR_FLOAT: *vertex->floats++ = luaL_optnumber(L, -1, 0.f); break;
case ATTR_FLOAT: *vertex->floats++ = luax_optfloat(L, -1, 0.f); break;
case ATTR_BYTE: *vertex->bytes++ = luaL_optint(L, -1, 255); break;
case ATTR_INT: *vertex->ints++ = luaL_optint(L, -1, 0); break;
}

View File

@ -39,9 +39,9 @@ static void raycastCallback(Shape* shape, float x, float y, float z, float nx, f
int l_lovrWorldNewCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.f);
float x = luax_optfloat(L, 2, 0.f);
float y = luax_optfloat(L, 3, 0.f);
float z = luax_optfloat(L, 4, 0.f);
Collider* collider = lovrColliderCreate(world, x, y, z);
luax_pushobject(L, collider);
lovrRelease(collider);
@ -50,12 +50,12 @@ int l_lovrWorldNewCollider(lua_State* L) {
int l_lovrWorldNewBoxCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.f);
float sx = luaL_optnumber(L, 5, 1.f);
float sy = luaL_optnumber(L, 6, sx);
float sz = luaL_optnumber(L, 7, sx);
float x = luax_optfloat(L, 2, 0.f);
float y = luax_optfloat(L, 3, 0.f);
float z = luax_optfloat(L, 4, 0.f);
float sx = luax_optfloat(L, 5, 1.f);
float sy = luax_optfloat(L, 6, sx);
float sz = luax_optfloat(L, 7, sx);
Collider* collider = lovrColliderCreate(world, x, y, z);
BoxShape* shape = lovrBoxShapeCreate(sx, sy, sz);
lovrColliderAddShape(collider, shape);
@ -67,11 +67,11 @@ int l_lovrWorldNewBoxCollider(lua_State* L) {
int l_lovrWorldNewCapsuleCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.f);
float radius = luaL_optnumber(L, 5, 1.f);
float length = luaL_optnumber(L, 6, 1.f);
float x = luax_optfloat(L, 2, 0.f);
float y = luax_optfloat(L, 3, 0.f);
float z = luax_optfloat(L, 4, 0.f);
float radius = luax_optfloat(L, 5, 1.f);
float length = luax_optfloat(L, 6, 1.f);
Collider* collider = lovrColliderCreate(world, x, y, z);
CapsuleShape* shape = lovrCapsuleShapeCreate(radius, length);
lovrColliderAddShape(collider, shape);
@ -83,11 +83,11 @@ int l_lovrWorldNewCapsuleCollider(lua_State* L) {
int l_lovrWorldNewCylinderCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.f);
float radius = luaL_optnumber(L, 5, 1.f);
float length = luaL_optnumber(L, 6, 1.f);
float x = luax_optfloat(L, 2, 0.f);
float y = luax_optfloat(L, 3, 0.f);
float z = luax_optfloat(L, 4, 0.f);
float radius = luax_optfloat(L, 5, 1.f);
float length = luax_optfloat(L, 6, 1.f);
Collider* collider = lovrColliderCreate(world, x, y, z);
CylinderShape* shape = lovrCylinderShapeCreate(radius, length);
lovrColliderAddShape(collider, shape);
@ -99,10 +99,10 @@ int l_lovrWorldNewCylinderCollider(lua_State* L) {
int l_lovrWorldNewSphereCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.f);
float radius = luaL_optnumber(L, 5, 1.f);
float x = luax_optfloat(L, 2, 0.f);
float y = luax_optfloat(L, 3, 0.f);
float z = luax_optfloat(L, 4, 0.f);
float radius = luax_optfloat(L, 5, 1.f);
Collider* collider = lovrColliderCreate(world, x, y, z);
SphereShape* shape = lovrSphereShapeCreate(radius);
lovrColliderAddShape(collider, shape);
@ -121,7 +121,7 @@ int l_lovrWorldDestroy(lua_State* L) {
int l_lovrWorldUpdate(lua_State* L) {
lua_settop(L, 3);
World* world = luax_checktype(L, 1, World);
float dt = luaL_checknumber(L, 2);
float dt = luax_checkfloat(L, 2);
CollisionResolver resolver = lua_type(L, 3) == LUA_TFUNCTION ? collisionResolver : NULL;
lovrWorldUpdate(world, dt, resolver, L);
return 0;
@ -144,8 +144,8 @@ int l_lovrWorldCollide(lua_State* L) {
World* world = luax_checktype(L, 1, World);
Shape* a = luax_checktype(L, 2, Shape);
Shape* b = luax_checktype(L, 3, Shape);
float friction = luaL_optnumber(L, 4, -1.f);
float restitution = luaL_optnumber(L, 5, -1.f);
float friction = luax_optfloat(L, 4, -1.f);
float restitution = luax_optfloat(L, 5, -1.f);
lua_pushboolean(L, lovrWorldCollide(world, a, b, friction, restitution));
return 1;
}
@ -162,9 +162,9 @@ int l_lovrWorldGetGravity(lua_State* L) {
int l_lovrWorldSetGravity(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);
float z = luaL_checknumber(L, 4);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
lovrWorldSetGravity(world, x, y, z);
return 0;
}
@ -180,8 +180,8 @@ int l_lovrWorldGetLinearDamping(lua_State* L) {
int l_lovrWorldSetLinearDamping(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01f);
float damping = luax_checkfloat(L, 2);
float threshold = luax_optfloat(L, 3, .01f);
lovrWorldSetLinearDamping(world, damping, threshold);
return 0;
}
@ -197,8 +197,8 @@ int l_lovrWorldGetAngularDamping(lua_State* L) {
int l_lovrWorldSetAngularDamping(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01f);
float damping = luax_checkfloat(L, 2);
float threshold = luax_optfloat(L, 3, .01f);
lovrWorldSetAngularDamping(world, damping, threshold);
return 0;
}
@ -218,12 +218,12 @@ int l_lovrWorldSetSleepingAllowed(lua_State* L) {
int l_lovrWorldRaycast(lua_State* L) {
World* world = luax_checktype(L, 1, World);
float x1 = luaL_checknumber(L, 2);
float y1 = luaL_checknumber(L, 3);
float z1 = luaL_checknumber(L, 4);
float x2 = luaL_checknumber(L, 5);
float y2 = luaL_checknumber(L, 6);
float z2 = luaL_checknumber(L, 7);
float x1 = luax_checkfloat(L, 2);
float y1 = luax_checkfloat(L, 3);
float z1 = luax_checkfloat(L, 4);
float x2 = luax_checkfloat(L, 5);
float y2 = luax_checkfloat(L, 6);
float z2 = luax_checkfloat(L, 7);
luaL_checktype(L, 8, LUA_TFUNCTION);
lua_settop(L, 8);
lovrWorldRaycast(world, x1, y1, z1, x2, y2, z2, raycastCallback, L);

View File

@ -272,16 +272,16 @@ Color luax_checkcolor(lua_State* L, int index) {
for (int i = 1; i <= 4; i++) {
lua_rawgeti(L, 1, i);
}
color.r = luaL_checknumber(L, -4);
color.g = luaL_checknumber(L, -3);
color.b = luaL_checknumber(L, -2);
color.a = luaL_optnumber(L, -1, 1.);
color.r = luax_checkfloat(L, -4);
color.g = luax_checkfloat(L, -3);
color.b = luax_checkfloat(L, -2);
color.a = luax_optfloat(L, -1, 1.);
lua_pop(L, 4);
} else if (lua_gettop(L) >= index + 2) {
color.r = luaL_checknumber(L, index);
color.g = luaL_checknumber(L, index + 1);
color.b = luaL_checknumber(L, index + 2);
color.a = luaL_optnumber(L, index + 3, 1.);
color.r = luax_checkfloat(L, index);
color.g = luax_checkfloat(L, index + 1);
color.b = luax_checkfloat(L, index + 2);
color.a = luax_optfloat(L, index + 3, 1.);
} else {
luaL_error(L, "Invalid color, expected 3 numbers, 4 numbers, or a table");
}

View File

@ -8,6 +8,8 @@
#define luax_totype(L, i, T) ((T*) _luax_totype(L, i, #T))
#define luax_checktype(L, i, T) ((T*) _luax_checktype(L, i, #T))
#define luax_checkfloat(L, i) (float) luaL_checknumber(L, i)
#define luax_optfloat(L, i, x) (float) luaL_optnumber(L, i, x)
typedef void (*luax_destructor)(void);
int luax_print(lua_State* L);