From bc055321ee2e599b713c79f02a56ed959f01edb7 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 3 Dec 2024 18:40:01 +0000 Subject: [PATCH] library: createsurfacefrompng api fixes --- src/library/doc.texi | 6 ++++-- src/library/plugin/plugin_api.c | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/library/doc.texi b/src/library/doc.texi index 2fbb33d..c7bab79 100644 --- a/src/library/doc.texi +++ b/src/library/doc.texi @@ -447,7 +447,9 @@ local mysurface = bolt.createsurfacefromrgba(2, 2, rgba) @section createsurfacefrompng Creates and returns a new @ref{objects-surface} from -the PNG file at the given path. +the PNG file at the given path. The first returned value is the surface +object and the second and third values are the width and height +respectively. The path will be interpreted similarly to require(), i.e. relative to the plugin directory, using '.' as file separators, and must not include @@ -464,7 +466,7 @@ to the plugin directory. @example lua @verbatim -local mysurface = bolt.createsurfacefrompng(800, 608, "images.icon") +local mysurface, width, height = bolt.createsurfacefrompng("images.icon") @end verbatim @end example diff --git a/src/library/plugin/plugin_api.c b/src/library/plugin/plugin_api.c index 134bef4..54f700f 100644 --- a/src/library/plugin/plugin_api.c +++ b/src/library/plugin/plugin_api.c @@ -451,12 +451,12 @@ static int api_createsurfacefrompng(lua_State* state) { lua_pop(state, 3); #undef CALL_SPNG - lua_pushinteger(state, ihdr.width); - lua_pushinteger(state, ihdr.height); struct SurfaceFunctions* functions = lua_newuserdata(state, sizeof(struct SurfaceFunctions)); managed_functions->surface_init(functions, ihdr.width, ihdr.height, rgba); lua_getfield(state, LUA_REGISTRYINDEX, "surfacemeta"); lua_setmetatable(state, -2); + lua_pushinteger(state, ihdr.width); + lua_pushinteger(state, ihdr.height); free(rgba); return 3; }