From 566c5e86394b8c3ee6ad7627a177b6336a966a09 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 5 Nov 2008 13:38:11 +0100 Subject: [PATCH] image: allow empty image creation Signed-off-by: Julien Danjou --- image.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/image.c b/image.c index 5c6f4e314..23133289d 100644 --- a/image.c +++ b/image.c @@ -156,17 +156,32 @@ image_new_from_file(const char *filename) * \param L The Lua stack. * \return The number of elements pushed on stack. * \luastack - * \lparam The image path. + * \lparam The image path, or nil to create an empty image. + * \lparam The image width if nil was set as first arg. + * \lparam The image height if nil was set as first arg. * \lreturn An image object. */ static int luaA_image_new(lua_State *L) { - const char *filename = luaL_checkstring(L, 2); - image_t *image; + const char *filename; - if((image = image_new_from_file(filename))) + if((filename = lua_tostring(L, 2))) + { + image_t *image; + if((image = image_new_from_file(filename))) + return luaA_image_userdata_new(L, image); + } + else if(lua_isnil(L, 2)) + { + int width = luaL_checknumber(L, 3); + int height = luaL_checknumber(L, 4); + Imlib_Image imimage = imlib_create_image(width, height); + image_t *image = p_new(image_t, 1); + image->image = imimage; + image_compute(image); return luaA_image_userdata_new(L, image); + } return 0; }