shithub: lua9

Download patch

ref: 86ec26aa5f2406240ada06bdbf6b7bf8cd5765f2
parent: c9c18dc389837a2662b96c6b25689dea5db9e853
author: telephil9 <[email protected]>
date: Sun Oct 25 05:31:00 EDT 2020

Move all libdraw event related function to an event module

	draw.einit() becomes event.init()
	Constants are cased properly (i.e. Emouse => event.MOUSE)

--- a/ldraw.h
+++ b/ldraw.h
@@ -27,6 +27,7 @@
 
 /* libs */
 int openlibdraw(lua_State *L);
+int openlibevent(lua_State *L);
 int openlibkey(lua_State *L);
 int openlibcolor(lua_State *L);
 
--- a/lua9.c
+++ b/lua9.c
@@ -58,30 +58,6 @@
 }
 
 static int
-leinit(lua_State *L)
-{
-	lua_Integer i;
-
-	i = luaL_checknumber(L, -1);
-	einit((ulong)i);
-	return 0;
-}
-
-static int
-levent(lua_State *L)
-{
-	Event ev;
-	int e;
-
-	e = event(&ev);
-	lua_pushnumber(L, e);
-	lua_newtable(L);
-	lua_pushinteger(L, ev.kbdc);
-	lua_setfield(L, -2, "kbdc");
-	return 2;
-}
-
-static int
 ldraw(lua_State *L)
 {
 	Image *dst, *src, *mask;
@@ -191,8 +167,6 @@
 
 static const struct luaL_Reg libdraw [] = {
 	{ "initdraw",    linitdraw },
-	{ "einit",       leinit },
-	{ "event",       levent },
 	{ "draw",        ldraw },
 	{ "line",        lline },
 	{ "ellipse",     lellipse },
@@ -209,8 +183,6 @@
 	registerimagemeta(L);
 	registerfontmeta(L);
 	luaL_newlib(L, libdraw);
-	pushglobal(L, "Emouse", Emouse);
-	pushglobal(L, "Ekeyboard", Ekeyboard);
 	pushglobal(L, "END_SQUARE", Endsquare);
 	pushglobal(L, "END_DISC", Enddisc);
 	pushglobal(L, "END_ARROW", Endarrow);
@@ -221,6 +193,7 @@
 
 static const luaL_Reg libs[] = {
 	{ "draw", openlibdraw },
+	{ "event", openlibevent },
 	{ "key",  openlibkey },
 	{ "color", openlibcolor },
 	{ NULL, NULL },
--- a/mkfile
+++ b/mkfile
@@ -10,6 +10,7 @@
 	font.$O \
 	image.$O \
 	geometry.$O \
+	event.$O \
 	key.$O \
 	color.$O \
 	utils.$O \
--- a/sample.lua
+++ b/sample.lua
@@ -23,14 +23,14 @@
 end
 
 draw.initdraw('lua sample')
-draw.einit(draw.Emouse|draw.Ekeyboard)
+event.init(event.MOUSE|event.KEYBOARD)
 red = draw.allocimage(display, rect(0,0,1,1), screen.chan, 1, color.RED)
 eresized()
 while true do
-	local e, ev = draw.event()
-	if e == draw.Emouse then
+	local e, ev = event.event()
+	if e == event.MOUSE then
 		--print 'Mouse event'
-	elseif e == draw.Ekeyboard then
+	elseif e == event.KEYBOARD then
 		if key.eq(ev.kbdc, 'q') or ev.kbdc == key.DEL then
 			os.exit()
 		end