Handle numbers more consistently in Lua API;

I still don't know if I should cast or not, but at least now things
will be consistently right or wrong.
This commit is contained in:
bjorn 2019-01-11 22:37:54 -08:00
parent 538f5f8aa1
commit 90cacd03ca
22 changed files with 92 additions and 96 deletions

View File

@ -146,8 +146,8 @@ static int l_lovrAudioRewind(lua_State* L) {
} }
static int l_lovrAudioSetDopplerEffect(lua_State* L) { static int l_lovrAudioSetDopplerEffect(lua_State* L) {
float factor = luaL_optnumber(L, 1, 1.); float factor = luaL_optnumber(L, 1, 1.f);
float speedOfSound = luaL_optnumber(L, 2, 343.29); float speedOfSound = luaL_optnumber(L, 2, 343.29f);
lovrAudioSetDopplerEffect(factor, speedOfSound); lovrAudioSetDopplerEffect(factor, speedOfSound);
return 0; return 0;
} }

View File

@ -55,10 +55,10 @@ static int l_lovrDataNewRasterizer(lua_State* L) {
float size; float size;
if (lua_type(L, 1) == LUA_TNUMBER || lua_isnoneornil(L, 1)) { if (lua_type(L, 1) == LUA_TNUMBER || lua_isnoneornil(L, 1)) {
size = luaL_optnumber(L, 1, 32); size = luaL_optnumber(L, 1, 32.f);
} else { } else {
blob = luax_readblob(L, 1, "Font"); blob = luax_readblob(L, 1, "Font");
size = luaL_optnumber(L, 2, 32); size = luaL_optnumber(L, 2, 32.f);
} }
Rasterizer* rasterizer = lovrRasterizerCreate(blob, size); Rasterizer* rasterizer = lovrRasterizerCreate(blob, size);
@ -99,8 +99,8 @@ static int l_lovrDataNewSoundData(lua_State* L) {
static int l_lovrDataNewTextureData(lua_State* L) { static int l_lovrDataNewTextureData(lua_State* L) {
TextureData* textureData = NULL; TextureData* textureData = NULL;
if (lua_type(L, 1) == LUA_TNUMBER) { if (lua_type(L, 1) == LUA_TNUMBER) {
int width = luaL_checknumber(L, 1); int width = luaL_checkinteger(L, 1);
int height = luaL_checknumber(L, 2); int height = luaL_checkinteger(L, 2);
TextureFormat format = luaL_checkoption(L, 3, "rgba", TextureFormats); TextureFormat format = luaL_checkoption(L, 3, "rgba", TextureFormats);
textureData = lovrTextureDataCreate(width, height, 0x0, format); textureData = lovrTextureDataCreate(width, height, 0x0, format);
} else { } else {

View File

@ -407,11 +407,7 @@ static int l_lovrGraphicsGetBackgroundColor(lua_State* L) {
} }
static int l_lovrGraphicsSetBackgroundColor(lua_State* L) { static int l_lovrGraphicsSetBackgroundColor(lua_State* L) {
Color color; Color color = luax_checkcolor(L, 1);
color.r = luaL_checknumber(L, 1);
color.g = luaL_checknumber(L, 2);
color.b = luaL_checknumber(L, 3);
color.a = luaL_optnumber(L, 4, 1.);
lovrGraphicsSetBackgroundColor(color); lovrGraphicsSetBackgroundColor(color);
return 0; return 0;
} }
@ -481,7 +477,7 @@ static int l_lovrGraphicsGetDefaultFilter(lua_State* L) {
static int l_lovrGraphicsSetDefaultFilter(lua_State* L) { static int l_lovrGraphicsSetDefaultFilter(lua_State* L) {
FilterMode mode = luaL_checkoption(L, 1, NULL, FilterModes); FilterMode mode = luaL_checkoption(L, 1, NULL, FilterModes);
float anisotropy = luaL_optnumber(L, 2, 1.); float anisotropy = luaL_optnumber(L, 2, 1.f);
lovrGraphicsSetDefaultFilter((TextureFilter) { .mode = mode, .anisotropy = anisotropy }); lovrGraphicsSetDefaultFilter((TextureFilter) { .mode = mode, .anisotropy = anisotropy });
return 0; return 0;
} }
@ -670,7 +666,7 @@ static int l_lovrGraphicsClear(lua_State* L) {
color.r = luaL_checknumber(L, index++); color.r = luaL_checknumber(L, index++);
color.g = luaL_checknumber(L, index++); color.g = luaL_checknumber(L, index++);
color.b = luaL_checknumber(L, index++); color.b = luaL_checknumber(L, index++);
color.a = luaL_optnumber(L, index++, 1.); color.a = luaL_optnumber(L, index++, 1.f);
} else { } else {
clearColor = lua_toboolean(L, index++); clearColor = lua_toboolean(L, index++);
} }
@ -794,8 +790,8 @@ static int l_lovrGraphicsArc(lua_State* L) {
} }
float transform[16]; float transform[16];
index = luax_readmat4(L, index, transform, 1, NULL); index = luax_readmat4(L, index, transform, 1, NULL);
float r1 = luaL_optnumber(L, index++, 0); float r1 = luaL_optnumber(L, index++, 0.f);
float r2 = luaL_optnumber(L, index++, 2 * M_PI); float r2 = luaL_optnumber(L, index++, 2.f * M_PI);
int segments = luaL_optinteger(L, index, 64) * (MIN(fabsf(r2 - r1), 2 * M_PI) / (2 * 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); lovrGraphicsArc(style, mode, material, transform, r1, r2, segments);
return 0; return 0;
@ -811,7 +807,7 @@ static int l_lovrGraphicsCircle(lua_State* L) {
} }
float transform[16]; float transform[16];
int index = luax_readmat4(L, 2, transform, 1, NULL); int index = luax_readmat4(L, 2, transform, 1, NULL);
int segments = luaL_optnumber(L, index, 32); int segments = luaL_optinteger(L, index, 32);
lovrGraphicsCircle(style, material, transform, segments); lovrGraphicsCircle(style, material, transform, segments);
return 0; return 0;
} }
@ -821,10 +817,10 @@ static int l_lovrGraphicsCylinder(lua_State* L) {
int index = 1; int index = 1;
Material* material = lua_isuserdata(L, index) ? luax_checktype(L, index++, Material) : NULL; Material* material = lua_isuserdata(L, index) ? luax_checktype(L, index++, Material) : NULL;
index = luax_readmat4(L, index, transform, 1, NULL); index = luax_readmat4(L, index, transform, 1, NULL);
float r1 = luaL_optnumber(L, index++, 1.); float r1 = luaL_optnumber(L, index++, 1.f);
float r2 = luaL_optnumber(L, index++, 1.); float r2 = luaL_optnumber(L, index++, 1.f);
bool capped = lua_isnoneornil(L, index) ? true : lua_toboolean(L, index++); bool capped = lua_isnoneornil(L, index) ? true : lua_toboolean(L, index++);
int segments = luaL_optnumber(L, index, floorf(16 + 16 * MAX(r1, r2))); int segments = luaL_optinteger(L, index, (lua_Integer) floorf(16 + 16 * MAX(r1, r2)));
lovrGraphicsCylinder(material, transform, r1, r2, capped, segments); lovrGraphicsCylinder(material, transform, r1, r2, capped, segments);
return 0; return 0;
} }
@ -834,17 +830,17 @@ static int l_lovrGraphicsSphere(lua_State* L) {
int index = 1; int index = 1;
Material* material = lua_isuserdata(L, index) ? luax_checktype(L, index++, Material) : NULL; Material* material = lua_isuserdata(L, index) ? luax_checktype(L, index++, Material) : NULL;
index = luax_readmat4(L, index, transform, 1, NULL); index = luax_readmat4(L, index, transform, 1, NULL);
int segments = luaL_optnumber(L, index, 30); int segments = luaL_optinteger(L, index, 30);
lovrGraphicsSphere(material, transform, segments); lovrGraphicsSphere(material, transform, segments);
return 0; return 0;
} }
static int l_lovrGraphicsSkybox(lua_State* L) { static int l_lovrGraphicsSkybox(lua_State* L) {
Texture* texture = luax_checktexture(L, 1); Texture* texture = luax_checktexture(L, 1);
float angle = luaL_optnumber(L, 2, 0); float angle = luaL_optnumber(L, 2, 0.f);
float ax = luaL_optnumber(L, 3, 0); float ax = luaL_optnumber(L, 3, 0.f);
float ay = luaL_optnumber(L, 4, 1); float ay = luaL_optnumber(L, 4, 1.f);
float az = luaL_optnumber(L, 5, 0); float az = luaL_optnumber(L, 5, 0.f);
lovrGraphicsSkybox(texture, angle, ax, ay, az); lovrGraphicsSkybox(texture, angle, ax, ay, az);
return 0; return 0;
} }
@ -854,7 +850,7 @@ static int l_lovrGraphicsPrint(lua_State* L) {
const char* str = luaL_checklstring(L, 1, &length); const char* str = luaL_checklstring(L, 1, &length);
float transform[16]; float transform[16];
int index = luax_readmat4(L, 2, transform, 1, NULL); int index = luax_readmat4(L, 2, transform, 1, NULL);
float wrap = luaL_optnumber(L, index++, 0); float wrap = luaL_optnumber(L, index++, 0.f);
HorizontalAlign halign = luaL_checkoption(L, index++, "center", HorizontalAligns); HorizontalAlign halign = luaL_checkoption(L, index++, "center", HorizontalAligns);
VerticalAlign valign = luaL_checkoption(L, index++, "middle", VerticalAligns); VerticalAlign valign = luaL_checkoption(L, index++, "middle", VerticalAligns);
lovrGraphicsPrint(str, length, transform, wrap, halign, valign); lovrGraphicsPrint(str, length, transform, wrap, halign, valign);
@ -877,10 +873,10 @@ static int l_lovrGraphicsStencil(lua_State* L) {
static int l_lovrGraphicsFill(lua_State* L) { static int l_lovrGraphicsFill(lua_State* L) {
Texture* texture = lua_isnoneornil(L, 1) ? NULL : luax_checktexture(L, 1); Texture* texture = lua_isnoneornil(L, 1) ? NULL : luax_checktexture(L, 1);
float u = luaL_optnumber(L, 2, 0.); float u = luaL_optnumber(L, 2, 0.f);
float v = luaL_optnumber(L, 3, 0.); float v = luaL_optnumber(L, 3, 0.f);
float w = luaL_optnumber(L, 4, 1. - u); float w = luaL_optnumber(L, 4, 1.f - u);
float h = luaL_optnumber(L, 5, 1. - v); float h = luaL_optnumber(L, 5, 1.f - v);
lovrGraphicsFill(texture, u, v, w, h); lovrGraphicsFill(texture, u, v, w, h);
return 0; return 0;
} }
@ -1068,10 +1064,10 @@ static int l_lovrGraphicsNewFont(lua_State* L) {
float size; float size;
if (lua_type(L, 1) == LUA_TNUMBER || lua_isnoneornil(L, 1)) { if (lua_type(L, 1) == LUA_TNUMBER || lua_isnoneornil(L, 1)) {
size = luaL_optnumber(L, 1, 32); size = luaL_optinteger(L, 1, 32);
} else { } else {
blob = luax_readblob(L, 1, "Font"); blob = luax_readblob(L, 1, "Font");
size = luaL_optnumber(L, 2, 32); size = luaL_optinteger(L, 2, 32);
} }
rasterizer = lovrRasterizerCreate(blob, size); rasterizer = lovrRasterizerCreate(blob, size);

View File

@ -355,12 +355,12 @@ int luaopen_lovr_headset(lua_State* L) {
// Offset // Offset
lua_getfield(L, -1, "offset"); lua_getfield(L, -1, "offset");
offset = luaL_optnumber(L, -1, 1.7); offset = luaL_optnumber(L, -1, 1.7f);
lua_pop(L, 1); lua_pop(L, 1);
// MSAA // MSAA
lua_getfield(L, -1, "msaa"); lua_getfield(L, -1, "msaa");
msaa = luaL_optnumber(L, -1, 4); msaa = luaL_optinteger(L, -1, 4);
lua_pop(L, 1); lua_pop(L, 1);
} }

View File

@ -121,7 +121,7 @@ static int l_lovrMathNewRandomGenerator(lua_State* L) {
static int l_lovrMathLookAt(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 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 to[3] = { luaL_checknumber(L, 4), luaL_checknumber(L, 5), luaL_checknumber(L, 6) };
float up[3] = { luaL_optnumber(L, 7, 0), luaL_optnumber(L, 8, 1), luaL_optnumber(L, 9, 0) }; float up[3] = { luaL_optnumber(L, 7, 0.f), luaL_optnumber(L, 8, 1.f), luaL_optnumber(L, 9, 0.f) };
float m[16], q[4], angle, ax, ay, az; float m[16], q[4], angle, ax, ay, az;
mat4_lookAt(m, from, to, up); mat4_lookAt(m, from, to, up);
quat_fromMat4(q, m); quat_fromMat4(q, m);
@ -135,9 +135,9 @@ static int l_lovrMathLookAt(lua_State* L) {
static int l_lovrMathOrientationToDirection(lua_State* L) { static int l_lovrMathOrientationToDirection(lua_State* L) {
float angle = luaL_checknumber(L, 1); float angle = luaL_checknumber(L, 1);
float ax = luaL_optnumber(L, 2, 0); float ax = luaL_optnumber(L, 2, 0.f);
float ay = luaL_optnumber(L, 3, 1); float ay = luaL_optnumber(L, 3, 1.f);
float az = luaL_optnumber(L, 4, 0); float az = luaL_optnumber(L, 4, 0.f);
float v[3]; float v[3];
lovrMathOrientationToDirection(angle, ax, ay, az, v); lovrMathOrientationToDirection(angle, ax, ay, az, v);
lua_pushnumber(L, v[0]); lua_pushnumber(L, v[0]);

View File

@ -19,7 +19,7 @@ const char* JointTypes[] = {
static int l_lovrPhysicsNewWorld(lua_State* L) { static int l_lovrPhysicsNewWorld(lua_State* L) {
float xg = luaL_optnumber(L, 1, 0.f); float xg = luaL_optnumber(L, 1, 0.f);
float yg = luaL_optnumber(L, 2, -9.81); float yg = luaL_optnumber(L, 2, -9.81f);
float zg = luaL_optnumber(L, 3, 0.f); float zg = luaL_optnumber(L, 3, 0.f);
bool allowSleep = lua_gettop(L) < 4 || lua_toboolean(L, 4); bool allowSleep = lua_gettop(L) < 4 || lua_toboolean(L, 4);
const char* tags[16]; const char* tags[16];

View File

@ -12,7 +12,7 @@ static int l_lovrTimerGetAverageDelta(lua_State* L) {
} }
static int l_lovrTimerGetFPS(lua_State* L) { static int l_lovrTimerGetFPS(lua_State* L) {
lua_pushnumber(L, lovrTimerGetFPS()); lua_pushinteger(L, lovrTimerGetFPS());
return 1; return 1;
} }

View File

@ -277,7 +277,7 @@ int l_lovrColliderGetLinearDamping(lua_State* L) {
int l_lovrColliderSetLinearDamping(lua_State* L) { int l_lovrColliderSetLinearDamping(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider); Collider* collider = luax_checktype(L, 1, Collider);
float damping = luaL_checknumber(L, 2); float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01); float threshold = luaL_optnumber(L, 3, .01f);
lovrColliderSetLinearDamping(collider, damping, threshold); lovrColliderSetLinearDamping(collider, damping, threshold);
return 0; return 0;
} }
@ -294,7 +294,7 @@ int l_lovrColliderGetAngularDamping(lua_State* L) {
int l_lovrColliderSetAngularDamping(lua_State* L) { int l_lovrColliderSetAngularDamping(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider); Collider* collider = luax_checktype(L, 1, Collider);
float damping = luaL_checknumber(L, 2); float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01); float threshold = luaL_optnumber(L, 3, .01f);
lovrColliderSetAngularDamping(collider, damping, threshold); lovrColliderSetAngularDamping(collider, damping, threshold);
return 0; return 0;
} }

View File

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

View File

@ -26,8 +26,8 @@ int l_lovrCurveGetTangent(lua_State* L) {
int l_lovrCurveRender(lua_State* L) { int l_lovrCurveRender(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve); Curve* curve = luax_checktype(L, 1, Curve);
int n = luaL_optinteger(L, 2, 32); int n = luaL_optinteger(L, 2, 32);
float t1 = luaL_optnumber(L, 3, 0.f); float t1 = luaL_optnumber(L, 3, 0.);
float t2 = luaL_optnumber(L, 4, 1.f); float t2 = luaL_optnumber(L, 4, 1.);
float* points = malloc(3 * n * sizeof(float)); float* points = malloc(3 * n * sizeof(float));
lovrCurveRender(curve, t1, t2, points, n); lovrCurveRender(curve, t1, t2, points, n);
lua_createtable(L, n, 0); lua_createtable(L, n, 0);

View File

@ -5,7 +5,7 @@ int l_lovrFontGetWidth(lua_State* L) {
Font* font = luax_checktype(L, 1, Font); Font* font = luax_checktype(L, 1, Font);
size_t length; size_t length;
const char* string = luaL_checklstring(L, 2, &length); const char* string = luaL_checklstring(L, 2, &length);
float wrap = luaL_optnumber(L, 3, 0); float wrap = luaL_optnumber(L, 3, 0.f);
float width; float width;
uint32_t lineCount; uint32_t lineCount;
uint32_t glyphCount; uint32_t glyphCount;
@ -59,7 +59,7 @@ int l_lovrFontGetPixelDensity(lua_State* L) {
int l_lovrFontSetPixelDensity(lua_State* L) { int l_lovrFontSetPixelDensity(lua_State* L) {
Font* font = luax_checktype(L, 1, Font); Font* font = luax_checktype(L, 1, Font);
float pixelDensity = luaL_optnumber(L, 2, -1); float pixelDensity = luaL_optnumber(L, 2, -1.f);
lovrFontSetPixelDensity(font, pixelDensity); lovrFontSetPixelDensity(font, pixelDensity);
return 0; return 0;
} }

View File

@ -172,16 +172,16 @@ static int l_lovrMat4GetTransform(lua_State* L) {
static int l_lovrMat4SetTransform(lua_State* L) { static int l_lovrMat4SetTransform(lua_State* L) {
mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL); mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL);
float x = luaL_optnumber(L, 2, 0.); float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0.); float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.); float z = luaL_optnumber(L, 4, 0.f);
float sx = luaL_optnumber(L, 5, 1.); float sx = luaL_optnumber(L, 5, 1.f);
float sy = luaL_optnumber(L, 6, sx); float sy = luaL_optnumber(L, 6, sx);
float sz = luaL_optnumber(L, 7, sx); float sz = luaL_optnumber(L, 7, sx);
float angle = luaL_optnumber(L, 8, 0.); float angle = luaL_optnumber(L, 8, 0.f);
float ax = luaL_optnumber(L, 9, 0.); float ax = luaL_optnumber(L, 9, 0.f);
float ay = luaL_optnumber(L, 10, 1.); float ay = luaL_optnumber(L, 10, 1.f);
float az = luaL_optnumber(L, 11, 0.); float az = luaL_optnumber(L, 11, 0.f);
mat4_setTransform(m, x, y, z, sx, sy, sz, angle, ax, ay, az); mat4_setTransform(m, x, y, z, sx, sy, sz, angle, ax, ay, az);
lua_settop(L, 1); lua_settop(L, 1);
return 1; return 1;

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); quat_set(q, 0, 0, 0, 0);
return ++index; return ++index;
case LUA_TNUMBER: case LUA_TNUMBER:
angle = luaL_optnumber(L, index++, 0.); angle = luaL_optnumber(L, index++, 0.f);
ax = luaL_optnumber(L, index++, 0.); ax = luaL_optnumber(L, index++, 0.f);
ay = luaL_optnumber(L, index++, 1.); ay = luaL_optnumber(L, index++, 1.f);
az = luaL_optnumber(L, index++, 0.); az = luaL_optnumber(L, index++, 0.f);
quat_fromAngleAxis(q, angle, ax, ay, az); quat_fromAngleAxis(q, angle, ax, ay, az);
return index; return index;
default: default:

View File

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

View File

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

View File

@ -92,7 +92,7 @@ int l_lovrTextureReplacePixels(lua_State* L) {
int l_lovrTextureSetFilter(lua_State* L) { int l_lovrTextureSetFilter(lua_State* L) {
Texture* texture = luax_checktype(L, 1, Texture); Texture* texture = luax_checktype(L, 1, Texture);
FilterMode mode = luaL_checkoption(L, 2, NULL, FilterModes); FilterMode mode = luaL_checkoption(L, 2, NULL, FilterModes);
float anisotropy = luaL_optnumber(L, 3, 1.); float anisotropy = luaL_optnumber(L, 3, 1.f);
TextureFilter filter = { .mode = mode, .anisotropy = anisotropy }; TextureFilter filter = { .mode = mode, .anisotropy = anisotropy };
lovrTextureSetFilter(texture, filter); lovrTextureSetFilter(texture, filter);
return 0; 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; v[0] = v[1] = v[2] = 0.f;
return ++index; return ++index;
case LUA_TNUMBER: case LUA_TNUMBER:
v[0] = luaL_optnumber(L, index++, 0.); v[0] = luaL_optnumber(L, index++, 0.f);
v[1] = luaL_optnumber(L, index++, 0.); v[1] = luaL_optnumber(L, index++, 0.f);
v[2] = luaL_optnumber(L, index++, 0.); v[2] = luaL_optnumber(L, index++, 0.f);
return index; return index;
default: default:
vec3_init(v, luax_checkmathtype(L, index++, MATH_VEC3, expected ? expected : "vec3 or number")); vec3_init(v, luax_checkmathtype(L, index++, MATH_VEC3, expected ? expected : "vec3 or number"));
@ -28,7 +28,7 @@ int luax_readscale(lua_State* L, int index, vec3 v, int components, const char*
return index + components; return index + components;
case LUA_TNUMBER: case LUA_TNUMBER:
if (components == 1) { if (components == 1) {
v[0] = v[1] = v[2] = luaL_optnumber(L, index++, 0.); v[0] = v[1] = v[2] = luaL_optnumber(L, index++, 0.f);
} else { } else {
v[0] = 1.f; v[0] = 1.f;
for (int i = 0; i < components; i++) { for (int i = 0; i < components; i++) {
@ -67,7 +67,7 @@ static int l_lovrVec3Unpack(lua_State* L) {
int l_lovrVec3Set(lua_State* L) { int l_lovrVec3Set(lua_State* L) {
vec3 v = luax_checkmathtype(L, 1, MATH_VEC3, NULL); vec3 v = luax_checkmathtype(L, 1, MATH_VEC3, NULL);
if (lua_isnoneornil(L, 2) || lua_type(L, 2) == LUA_TNUMBER) { if (lua_isnoneornil(L, 2) || lua_type(L, 2) == LUA_TNUMBER) {
float x = luaL_optnumber(L, 2, 0.); float x = luaL_optnumber(L, 2, 0.f);
vec3_set(v, x, luaL_optnumber(L, 3, x), luaL_optnumber(L, 4, x)); vec3_set(v, x, luaL_optnumber(L, 3, x), luaL_optnumber(L, 4, x));
} else { } else {
vec3 u = luax_checkmathtype(L, 2, MATH_VEC3, "vec3 or number"); vec3 u = luax_checkmathtype(L, 2, MATH_VEC3, "vec3 or number");

View File

@ -199,7 +199,7 @@ int l_lovrVertexDataSetVertices(lua_State* L) {
VertexFormat* format = &vertexData->format; VertexFormat* format = &vertexData->format;
luaL_checktype(L, 2, LUA_TTABLE); luaL_checktype(L, 2, LUA_TTABLE);
uint32_t vertexCount = lua_objlen(L, 2); uint32_t vertexCount = lua_objlen(L, 2);
int start = luaL_optnumber(L, 3, 1) - 1; int start = luaL_optinteger(L, 3, 1) - 1;
lovrAssert(start + vertexCount <= vertexData->count, "VertexData can only hold %d vertices", vertexData->count); lovrAssert(start + vertexCount <= vertexData->count, "VertexData can only hold %d vertices", vertexData->count);
VertexPointer vertices = { .raw = vertexData->blob.data }; VertexPointer vertices = { .raw = vertexData->blob.data };
vertices.bytes += start * format->stride; vertices.bytes += start * format->stride;

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) { int l_lovrWorldNewCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0); float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0); float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0); float z = luaL_optnumber(L, 4, 0.f);
Collider* collider = lovrColliderCreate(world, x, y, z); Collider* collider = lovrColliderCreate(world, x, y, z);
luax_pushobject(L, collider); luax_pushobject(L, collider);
lovrRelease(collider); lovrRelease(collider);
@ -50,9 +50,9 @@ int l_lovrWorldNewCollider(lua_State* L) {
int l_lovrWorldNewBoxCollider(lua_State* L) { int l_lovrWorldNewBoxCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0); float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0); float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0); float z = luaL_optnumber(L, 4, 0.f);
float sx = luaL_optnumber(L, 5, 1.f); float sx = luaL_optnumber(L, 5, 1.f);
float sy = luaL_optnumber(L, 6, sx); float sy = luaL_optnumber(L, 6, sx);
float sz = luaL_optnumber(L, 7, sx); float sz = luaL_optnumber(L, 7, sx);
@ -67,9 +67,9 @@ int l_lovrWorldNewBoxCollider(lua_State* L) {
int l_lovrWorldNewCapsuleCollider(lua_State* L) { int l_lovrWorldNewCapsuleCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0); float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0); float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0); float z = luaL_optnumber(L, 4, 0.f);
float radius = luaL_optnumber(L, 5, 1.f); float radius = luaL_optnumber(L, 5, 1.f);
float length = luaL_optnumber(L, 6, 1.f); float length = luaL_optnumber(L, 6, 1.f);
Collider* collider = lovrColliderCreate(world, x, y, z); Collider* collider = lovrColliderCreate(world, x, y, z);
@ -83,9 +83,9 @@ int l_lovrWorldNewCapsuleCollider(lua_State* L) {
int l_lovrWorldNewCylinderCollider(lua_State* L) { int l_lovrWorldNewCylinderCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0); float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0); float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0); float z = luaL_optnumber(L, 4, 0.f);
float radius = luaL_optnumber(L, 5, 1.f); float radius = luaL_optnumber(L, 5, 1.f);
float length = luaL_optnumber(L, 6, 1.f); float length = luaL_optnumber(L, 6, 1.f);
Collider* collider = lovrColliderCreate(world, x, y, z); Collider* collider = lovrColliderCreate(world, x, y, z);
@ -99,9 +99,9 @@ int l_lovrWorldNewCylinderCollider(lua_State* L) {
int l_lovrWorldNewSphereCollider(lua_State* L) { int l_lovrWorldNewSphereCollider(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
float x = luaL_optnumber(L, 2, 0); float x = luaL_optnumber(L, 2, 0.f);
float y = luaL_optnumber(L, 3, 0); float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0); float z = luaL_optnumber(L, 4, 0.f);
float radius = luaL_optnumber(L, 5, 1.f); float radius = luaL_optnumber(L, 5, 1.f);
Collider* collider = lovrColliderCreate(world, x, y, z); Collider* collider = lovrColliderCreate(world, x, y, z);
SphereShape* shape = lovrSphereShapeCreate(radius); SphereShape* shape = lovrSphereShapeCreate(radius);
@ -144,8 +144,8 @@ int l_lovrWorldCollide(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
Shape* a = luax_checktype(L, 2, Shape); Shape* a = luax_checktype(L, 2, Shape);
Shape* b = luax_checktype(L, 3, Shape); Shape* b = luax_checktype(L, 3, Shape);
float friction = luaL_optnumber(L, 4, -1); float friction = luaL_optnumber(L, 4, -1.f);
float restitution = luaL_optnumber(L, 5, -1); float restitution = luaL_optnumber(L, 5, -1.f);
lua_pushboolean(L, lovrWorldCollide(world, a, b, friction, restitution)); lua_pushboolean(L, lovrWorldCollide(world, a, b, friction, restitution));
return 1; return 1;
} }
@ -181,7 +181,7 @@ int l_lovrWorldGetLinearDamping(lua_State* L) {
int l_lovrWorldSetLinearDamping(lua_State* L) { int l_lovrWorldSetLinearDamping(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
float damping = luaL_checknumber(L, 2); float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01); float threshold = luaL_optnumber(L, 3, .01f);
lovrWorldSetLinearDamping(world, damping, threshold); lovrWorldSetLinearDamping(world, damping, threshold);
return 0; return 0;
} }
@ -198,7 +198,7 @@ int l_lovrWorldGetAngularDamping(lua_State* L) {
int l_lovrWorldSetAngularDamping(lua_State* L) { int l_lovrWorldSetAngularDamping(lua_State* L) {
World* world = luax_checktype(L, 1, World); World* world = luax_checktype(L, 1, World);
float damping = luaL_checknumber(L, 2); float damping = luaL_checknumber(L, 2);
float threshold = luaL_optnumber(L, 3, .01); float threshold = luaL_optnumber(L, 3, .01f);
lovrWorldSetAngularDamping(world, damping, threshold); lovrWorldSetAngularDamping(world, damping, threshold);
return 0; return 0;
} }

View File

@ -5,7 +5,7 @@
#include "msdfgen-c.h" #include "msdfgen-c.h"
#include <math.h> #include <math.h>
Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, int size) { Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, float size) {
stbtt_fontinfo* font = &rasterizer->font; stbtt_fontinfo* font = &rasterizer->font;
unsigned char* data = blob ? blob->data : VarelaRound_ttf; unsigned char* data = blob ? blob->data : VarelaRound_ttf;
if (!stbtt_InitFont(font, data, stbtt_GetFontOffsetForIndex(data, 0))) { if (!stbtt_InitFont(font, data, stbtt_GetFontOffsetForIndex(data, 0))) {

View File

@ -14,7 +14,7 @@ typedef struct {
Ref ref; Ref ref;
stbtt_fontinfo font; stbtt_fontinfo font;
Blob* blob; Blob* blob;
int size; float size;
float scale; float scale;
int glyphCount; int glyphCount;
int height; int height;
@ -38,7 +38,7 @@ typedef struct {
typedef map_t(Glyph) map_glyph_t; typedef map_t(Glyph) map_glyph_t;
Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, int size); Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, float size);
#define lovrRasterizerCreate(...) lovrRasterizerInit(lovrAlloc(Rasterizer), __VA_ARGS__) #define lovrRasterizerCreate(...) lovrRasterizerInit(lovrAlloc(Rasterizer), __VA_ARGS__)
void lovrRasterizerDestroy(void* ref); void lovrRasterizerDestroy(void* ref);
bool lovrRasterizerHasGlyph(Rasterizer* fontData, uint32_t character); bool lovrRasterizerHasGlyph(Rasterizer* fontData, uint32_t character);

View File

@ -275,13 +275,13 @@ Color luax_checkcolor(lua_State* L, int index) {
color.r = luaL_checknumber(L, -4); color.r = luaL_checknumber(L, -4);
color.g = luaL_checknumber(L, -3); color.g = luaL_checknumber(L, -3);
color.b = luaL_checknumber(L, -2); color.b = luaL_checknumber(L, -2);
color.a = luaL_optnumber(L, -1, 1); color.a = luaL_optnumber(L, -1, 1.f);
lua_pop(L, 4); lua_pop(L, 4);
} else if (lua_gettop(L) >= index + 2) { } else if (lua_gettop(L) >= index + 2) {
color.r = luaL_checknumber(L, index); color.r = luaL_checknumber(L, index);
color.g = luaL_checknumber(L, index + 1); color.g = luaL_checknumber(L, index + 1);
color.b = luaL_checknumber(L, index + 2); color.b = luaL_checknumber(L, index + 2);
color.a = luaL_optnumber(L, index + 3, 1); color.a = luaL_optnumber(L, index + 3, 1.f);
} else { } else {
luaL_error(L, "Invalid color, expected 3 numbers, 4 numbers, or a table"); luaL_error(L, "Invalid color, expected 3 numbers, 4 numbers, or a table");
} }