Changeset

3868:72d68f996f45

util-src/windows.c: Added get_consolecolor, set_consolecolor.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 15 Dec 2010 01:53:33 +0500
parents 3867:f61693852711
children 3869:692a428f57e7
files util-src/windows.c
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util-src/windows.c	Tue Dec 14 18:29:40 2010 +0000
+++ b/util-src/windows.c	Wed Dec 15 01:53:33 2010 +0500
@@ -43,9 +43,38 @@
 	}
 }
 
+static void lassert(lua_State *L, BOOL test, char* string) {
+	if (!test) {
+		luaL_error(L, "%s: %d", string, GetLastError());
+	}
+}
+
+static int Lget_consolecolor(lua_State *L) {
+	HWND console = GetStdHandle(STD_OUTPUT_HANDLE);
+	WORD color; DWORD read_len;
+	
+	CONSOLE_SCREEN_BUFFER_INFO info;
+	
+	lassert(L, console != INVALID_HANDLE_VALUE, "GetStdHandle");
+	lassert(L, GetConsoleScreenBufferInfo(console, &info), "GetConsoleScreenBufferInfo");
+	lassert(L, ReadConsoleOutputAttribute(console, &color, sizeof(WORD), info.dwCursorPosition, &read_len), "ReadConsoleOutputAttribute");
+
+	lua_pushnumber(L, color);
+	return 1;
+}
+static int Lset_consolecolor(lua_State *L) {
+	int color = luaL_checkint(L, 1);
+	HWND console = GetStdHandle(STD_OUTPUT_HANDLE);
+	lassert(L, console != INVALID_HANDLE_VALUE, "GetStdHandle");
+	lassert(L, SetConsoleTextAttribute(console, color), "SetConsoleTextAttribute");
+	return 0;
+}
+
 static const luaL_Reg Reg[] =
 {
 	{ "get_nameservers",	Lget_nameservers	},
+	{ "get_consolecolor",	Lget_consolecolor	},
+	{ "set_consolecolor",	Lset_consolecolor	},
 	{ NULL,		NULL	}
 };