diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index 3482c89d4..c983966a5 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -489,7 +489,8 @@ int luax_convobj(lua_State *L, int idxs[], int n, const char *mod, const char *f lua_call(L, n, 2); // Call the function, n args, one return value (plus optional errstring.) luax_assert_nilerror(L, -2); // Make sure the function returned something. lua_pop(L, 1); // Pop the second return value now that we don't need it. - lua_replace(L, idxs[0]); // Replace the initial argument with the new object. + if (n > 0) + lua_replace(L, idxs[0]); // Replace the initial argument with the new object. return 0; } diff --git a/src/modules/font/wrap_Font.cpp b/src/modules/font/wrap_Font.cpp index 01b4dfa20..1acf83b5c 100644 --- a/src/modules/font/wrap_Font.cpp +++ b/src/modules/font/wrap_Font.cpp @@ -37,7 +37,7 @@ namespace font int w_newRasterizer(lua_State *L) { - if (lua_type(L, 1) == LUA_TNUMBER || lua_type(L, 2) == LUA_TNUMBER) + if (lua_type(L, 1) == LUA_TNUMBER || lua_type(L, 2) == LUA_TNUMBER || lua_isnone(L, 1)) { // First or second argument is a number: call newTrueTypeRasterizer. return w_newTrueTypeRasterizer(L); @@ -69,10 +69,10 @@ int w_newTrueTypeRasterizer(lua_State *L) Rasterizer *t = nullptr; TrueTypeRasterizer::Hinting hinting = TrueTypeRasterizer::HINTING_NORMAL; - if (lua_type(L, 1) == LUA_TNUMBER) + if (lua_type(L, 1) == LUA_TNUMBER || lua_isnone(L, 1)) { // First argument is a number: use the default TrueType font. - int size = luaL_checkint(L, 1); + int size = luaL_optint(L, 1, 12); const char *hintstr = lua_isnoneornil(L, 2) ? nullptr : luaL_checkstring(L, 2); if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))