shithub: lua9

Download patch

ref: 8e5103be04cc9432e01c794467be9b0761611a0b
parent: 18b85275bb4a995fbfcc7924ac488ba8df35de4a
author: telephil9 <telephil9@gmail.com>
date: Wed Oct 21 17:26:11 EDT 2020

Added ellipse() and fillellipse()

New libdraw functions added.
Sample modified to include calls to these new functions.

--- a/lua9.c
+++ b/lua9.c
@@ -227,6 +227,39 @@
 	return 0;
 }
 
+static int l_ellipse(lua_State *L)
+{
+	Image *dst, *src;
+	Point c, sp;
+	int a, b, thick;
+
+	dst   = l_checkimage(L, 1);
+	c     = l_checkpoint(L, 2);
+	a     = luaL_checkinteger(L, 3);
+	b     = luaL_checkinteger(L, 4);
+	thick = luaL_checkinteger(L, 5);
+	src   = l_checkimage(L, 6);
+	sp    = l_checkpoint(L, 7);
+	ellipse(dst, c, a, b, thick, src, sp);
+	return 0;
+}
+
+static int l_fillellipse(lua_State *L)
+{
+	Image *dst, *src;
+	Point c, sp;
+	int a, b;
+
+	dst   = l_checkimage(L, 1);
+	c     = l_checkpoint(L, 2);
+	a     = luaL_checkinteger(L, 3);
+	b     = luaL_checkinteger(L, 4);
+	src   = l_checkimage(L, 5);
+	sp    = l_checkpoint(L, 6);
+	fillellipse(dst, c, a, b, src, sp);
+	return 0;
+}
+
 static int l_string(lua_State *L) {
 	Image *dst, *src;
 	Font *f;
@@ -383,12 +416,14 @@
 }
 
 static const struct luaL_Reg drawlib [] = {
-	{ "initdraw", l_initdraw },
-	{ "einit",    l_einit },
-	{ "event",    l_event },
-	{ "draw",     l_draw },
-	{ "line",     l_line },
-	{ "string",   l_string },
+	{ "initdraw",    l_initdraw },
+	{ "einit",       l_einit },
+	{ "event",       l_event },
+	{ "draw",        l_draw },
+	{ "line",        l_line },
+	{ "ellipse",     l_ellipse },
+	{ "fillellipse", l_fillellipse },
+	{ "string",      l_string },
 	{ NULL, NULL }
 };
 
--- a/sample.lua
+++ b/sample.lua
@@ -16,7 +16,9 @@
 	draw.draw(screen, screen.r, display.white, nil, ZP)
 	draw.draw(screen, rect(50, 150, 100, 200), display.black, nil, ZP)
 	draw.string(screen, pt(110, 160), display.black, nil, font, 'Hello LUA')
-	draw.line(screen, pt(50, 210), pt(200, 210), draw.Endsquare, draw.Endarrow, 1, display.black, ZP)
+	draw.line(screen, pt(50, 210), pt(150, 210), draw.Endsquare, draw.Endarrow, 1, display.black, ZP)
+	draw.ellipse(screen, pt(300, 300), 200, 100, 2, display.black, ZP)
+	draw.fillellipse(screen, pt(300, 300), 20, 50, display.black, ZP)
 end
 
 draw.initdraw('lua sample')