summaryrefslogtreecommitdiff
path: root/src/image/image.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-23 21:00:15 -0600
committersanine <sanine.not@pm.me>2023-02-23 21:00:15 -0600
commit98c6064fc679586251793ae47c3c6f57dd4d1cb1 (patch)
treee8d64ea85f3d61105feba7a01dbd1aef73386658 /src/image/image.c
parentf1ab76b1185247ca688f59f36d99f298d25c07b5 (diff)
refactor: remove honeysuckle from image
Diffstat (limited to 'src/image/image.c')
-rw-r--r--src/image/image.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/image/image.c b/src/image/image.c
index 183ff46..feea51a 100644
--- a/src/image/image.c
+++ b/src/image/image.c
@@ -1,8 +1,9 @@
#include <lua.h>
-#include <honeysuckle.h>
-/* assimp provides its own stb_image implementation */
+#include <lauxlib.h>
+/* nanovg provides its own stb_image implementation */
/*#define STB_IMAGE_IMPLEMENTATION*/
#include "stb_image.h"
+#include "util/util.h"
#include "image.h"
@@ -13,13 +14,14 @@ int free_image(lua_State *L);
void setup_image(lua_State *L, int honey_index)
{
- hs_create_table(L,
+ struct honey_tbl_t image[] = {
/* basic images */
- hs_str_cfunc("null", empty),
- hs_str_cfunc("load", load_image),
- hs_str_cfunc("destroy", free_image),
- );
-
+ H_FUNC("null", empty),
+ H_FUNC("load", load_image),
+ H_FUNC("destroy", free_image),
+ H_END
+ };
+ create_table(L, image);
lua_setfield(L, honey_index, "image");
}
@@ -32,16 +34,18 @@ int empty(lua_State *L)
return 1;
}
+
int load_image(lua_State *L)
{
- char *filename;
- lua_Integer requested_channels;
- hs_parse_args(L, hs_str(filename), hs_int(requested_channels));
+ const char *filename = luaL_checkstring(L, 1);
+ int requested_channels = luaL_checkinteger(L, 2);
int width, height, channels;
unsigned char *data = stbi_load(filename, &width, &height, &channels, requested_channels);
- if (data == NULL) hs_throw_error(L, "failed to load image '%s'", filename);
+ if (data == NULL) {
+ return luaL_error(L, "failed to load image '%s'", filename);
+ }
lua_pushlightuserdata(L, data);
lua_pushinteger(L, width);
@@ -53,8 +57,10 @@ int load_image(lua_State *L)
int free_image(lua_State *L)
{
- void *data;
- hs_parse_args(L, hs_light(data));
+ void *data = lua_touserdata(L, 1);
+ if (data == NULL) {
+ return luaL_typerror(L, 1, "userdata");
+ }
stbi_image_free(data);
return 0;
}