From 2d48b5eae1dde314faa5bd0e570426aaa0baa6ec Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 14 Jun 2014 14:20:04 +0100 Subject: [PATCH] Made `filename` argument optional in love.graphics.newFont() --- doc/api.md | 5 +++-- src/font.c | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/api.md b/doc/api.md index 6f95784..3970c74 100644 --- a/doc/api.md +++ b/doc/api.md @@ -137,10 +137,11 @@ dimensions as the screen. ##### love.graphics.newQuad(x, y, width, height) Creates and returns a new quad. -##### love.graphics.newFont(filename) +##### love.graphics.newFont([filename]) Creates and returns a new font. `filename` should be the name of a black and white 8bit .pcx image file representing all 256 characters in a 16 x 16 -character grid. +character grid. If no `filename` is given then the default embedded font image +is used. ##### love.graphics.present() Flips the current screen buffer with the displayed screen buffer. This is diff --git a/src/font.c b/src/font.c index def0cf2..2505756 100644 --- a/src/font.c +++ b/src/font.c @@ -85,11 +85,15 @@ void font_blit(font_t *self, pixel_t *buf, int bufw, int bufh, int l_font_new(lua_State *L) { - const char *filename = luaL_checkstring(L, 1); + const char *filename = lua_isnoneornil(L, 1) ? NULL : luaL_checkstring(L, 1); font_t *self = luaobj_newudata(L, sizeof(*self)); luaobj_setclass(L, CLASS_TYPE, CLASS_NAME); - const char *err = font_init(self, filename); - if (err) luaL_error(L, err); + if (filename) { + const char *err = font_init(self, filename); + if (err) luaL_error(L, err); + } else { + font_initEmbedded(self); + } return 1; }