shithub: lua9

Download patch

ref: 9cd8f1f0e8a962efd05a1bfc7f8b4068bcb8d526
parent: 8e5103be04cc9432e01c794467be9b0761611a0b
author: telephil9 <[email protected]>
date: Thu Oct 22 00:22:20 EDT 2020

Expose missing Image attributes

Make clipr, chan, depth and repl attributes from Image struct available.

--- a/lua9.c
+++ b/lua9.c
@@ -301,32 +301,43 @@
 	return 1;
 }
 
+static void l_pushrect(lua_State *L, Rectangle r)
+{
+	lua_newtable(L);
+	lua_newtable(L);
+	lua_pushinteger(L, r.min.x);
+	lua_setfield(L, -2, "x");
+	lua_pushinteger(L, r.min.y);
+	lua_setfield(L, -2, "y");
+	lua_setfield(L, -2, "min");
+	lua_newtable(L);
+	lua_pushinteger(L, r.max.x);
+	lua_setfield(L, -2, "x");
+	lua_pushinteger(L, r.max.y);
+	lua_setfield(L, -2, "y");
+	lua_setfield(L, -2, "max");
+}
+
 static int l_image_index(lua_State *L) {
-	ImagePtr *i;
+	Image *i;
 	const char *s;
-	Rectangle r;
 
-	i = (ImagePtr*)luaL_checkudata(L, 1, IMAGE_META);
-	luaL_argcheck(L, i != NULL, 1, "draw: Image expected");
+	i = l_checkimage(L, 1);
 	s = luaL_checkstring(L, 2);
 	if(!strncmp(s, "r", 1)) {
-		r = i->p->r;
-		lua_newtable(L);
-		lua_newtable(L);
-		lua_pushinteger(L, r.min.x);
-		lua_setfield(L, -2, "x");
-		lua_pushinteger(L, r.min.y);
-		lua_setfield(L, -2, "y");
-		lua_setfield(L, -2, "min");
-		lua_newtable(L);
-		lua_pushinteger(L, r.max.x);
-		lua_setfield(L, -2, "x");
-		lua_pushinteger(L, r.max.y);
-		lua_setfield(L, -2, "y");
-		lua_setfield(L, -2, "max");
-		return 1;
+		l_pushrect(L, i->r);
+	} else if(!strncmp(s, "clipr", 5)) {
+		l_pushrect(L, i->clipr);
+	} else if(!strncmp(s, "chan", 4)) {
+		lua_pushinteger(L, i->chan);
+	} else if(!strncmp(s, "depth", 5)) {
+		lua_pushinteger(L, i->depth);
+	} else if(!strncmp(s, "repl", 4)) {
+		lua_pushinteger(L, i->repl);
+	} else {
+		return 0;
 	}
-	return 0;
+	return 1;
 }
 
 static const struct luaL_Reg image_funcs[] = {