aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/windows.c
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-12-17 13:50:33 +0000
committerMatthew Wild <mwild1@gmail.com>2010-12-17 13:50:33 +0000
commit8ee0fb71fcba10a54760d4a047a4a91e2ab97ad1 (patch)
tree08ff2f81be281c7d1f399e2e3ff5b74f1671b77b /util-src/windows.c
parentc1efda1ffd82e6988ab20b4be5f75ecf31fb551e (diff)
parent07e945631dc2abe7a2afe204919a72d25398c687 (diff)
downloadprosody-8ee0fb71fcba10a54760d4a047a4a91e2ab97ad1.tar.gz
prosody-8ee0fb71fcba10a54760d4a047a4a91e2ab97ad1.zip
Merge Tobias->trunk
Diffstat (limited to 'util-src/windows.c')
-rw-r--r--util-src/windows.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/util-src/windows.c b/util-src/windows.c
index 12bd7ce9..e1e07608 100644
--- a/util-src/windows.c
+++ b/util-src/windows.c
@@ -43,9 +43,38 @@ static int Lget_nameservers(lua_State *L) {
}
}
+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 }
};