shithub: slug

Download patch

ref: e929ff6b56ae907e96b25b65a6c91db90d8393d4
parent: 119d1c2d2cea3360ff0913ba919f143a149add80
author: phil9 <telephil9@gmail.com>
date: Wed Nov 30 09:36:08 EST 2022

implement size() function to set window size

	the size() function can be called in setup() to set the window size.
	Calling the function in draw() is a no-op.

--- a/a.h
+++ b/a.h
@@ -24,6 +24,7 @@
 
 Image*	getcolor(int);
 
+extern int drawing;
 extern Image* canvas;
 extern int width;
 extern int height;
--- a/api.c
+++ b/api.c
@@ -33,6 +33,21 @@
 }
 
 int
+csize(lua_State *L)
+{
+	int w, h;
+
+	w = luaL_checkinteger(L, 1);
+	h = luaL_checkinteger(L, 2);
+	if(drawing)
+		return 0;
+	width = w;
+	height = h;
+	resize(w, h);
+	return 0;
+}
+
+int
 cbackground(lua_State *L)
 {
 	Image *i;
@@ -237,6 +252,7 @@
 void
 registerfuncs(lua_State *L)
 {
+	registerfunc(L, "size", csize);
 	registerfunc(L, "background", cbackground);
 	registerfunc(L, "noStroke", cnostroke);
 	registerfunc(L, "stroke", cstroke);
--- a/slug.c
+++ b/slug.c
@@ -3,6 +3,7 @@
 
 Mousectl *mc;
 Keyboardctl *kc;
+int drawing;
 
 void
 lsetup(lua_State *L)
@@ -86,7 +87,9 @@
 	registerfuncs(L);
 	initstate();
 	resize(width, height);
+	drawing = 0;
 	lsetup(L);
+	drawing = 1;
 	for(;;){
 		ldraw(L);
 		switch(alt(alts)){