Mercurial > love-experiments
diff src/common/runtime.cpp @ 1168:fb1bf6a0dede
Catch errors in love.font.newRasterizer, add luax_pconvobj which pcalls, allowing love.graphics.newFont to clean up before re-erroring
| author | Bart van Strien <bart.bes+projects@gmail.com> |
|---|---|
| date | Sat, 15 Dec 2012 14:26:46 +0100 |
| parents | 3c6206da8bcf |
| children | c5286ec34327 b7f097053d74 |
line wrap: on
line diff
--- a/src/common/runtime.cpp Sat Dec 15 14:13:23 2012 +0100 +++ b/src/common/runtime.cpp Sat Dec 15 14:26:46 2012 +0100 @@ -343,6 +343,30 @@ return 0; } +int luax_pconvobj(lua_State *L, int idx, const char *mod, const char *fn) +{ + // Convert string to a file. + luax_getfunction(L, mod, fn); + lua_pushvalue(L, idx); // The initial argument. + int ret = lua_pcall(L, 1, 1, 0); // Call the function, one arg, one return value. + if (ret == 0) + lua_replace(L, idx); // Replace the initial argument with the new object. + return ret; +} + +int luax_pconvobj(lua_State *L, int idxs[], int n, const char *mod, const char *fn) +{ + luax_getfunction(L, mod, fn); + for (int i = 0; i < n; i++) + { + lua_pushvalue(L, idxs[i]); // The arguments. + } + int ret = lua_pcall(L, n, 1, 0); // Call the function, n args, one return value. + if (ret == 0) + lua_replace(L, idxs[0]); // Replace the initial argument with the new object. + return ret; +} + int luax_strtofile(lua_State *L, int idx) { return luax_convobj(L, idx, "filesystem", "newFile");
