Comparison

util-src/windows.c @ 3748:2237796ba228

util-src/windows.c: Added get_consolecolor, set_consolecolor.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 15 Dec 2010 01:53:33 +0500
parent 2924:8dc4e2e00129
child 4128:b6d072a3668d
comparison
equal deleted inserted replaced
3747:7d5b135bf268 3748:2237796ba228
41 luaL_error(L, "DnsQueryConfig returned %d", status); 41 luaL_error(L, "DnsQueryConfig returned %d", status);
42 return 0; // unreachable, but prevents a compiler warning 42 return 0; // unreachable, but prevents a compiler warning
43 } 43 }
44 } 44 }
45 45
46 static void lassert(lua_State *L, BOOL test, char* string) {
47 if (!test) {
48 luaL_error(L, "%s: %d", string, GetLastError());
49 }
50 }
51
52 static int Lget_consolecolor(lua_State *L) {
53 HWND console = GetStdHandle(STD_OUTPUT_HANDLE);
54 WORD color; DWORD read_len;
55
56 CONSOLE_SCREEN_BUFFER_INFO info;
57
58 lassert(L, console != INVALID_HANDLE_VALUE, "GetStdHandle");
59 lassert(L, GetConsoleScreenBufferInfo(console, &info), "GetConsoleScreenBufferInfo");
60 lassert(L, ReadConsoleOutputAttribute(console, &color, sizeof(WORD), info.dwCursorPosition, &read_len), "ReadConsoleOutputAttribute");
61
62 lua_pushnumber(L, color);
63 return 1;
64 }
65 static int Lset_consolecolor(lua_State *L) {
66 int color = luaL_checkint(L, 1);
67 HWND console = GetStdHandle(STD_OUTPUT_HANDLE);
68 lassert(L, console != INVALID_HANDLE_VALUE, "GetStdHandle");
69 lassert(L, SetConsoleTextAttribute(console, color), "SetConsoleTextAttribute");
70 return 0;
71 }
72
46 static const luaL_Reg Reg[] = 73 static const luaL_Reg Reg[] =
47 { 74 {
48 { "get_nameservers", Lget_nameservers }, 75 { "get_nameservers", Lget_nameservers },
76 { "get_consolecolor", Lget_consolecolor },
77 { "set_consolecolor", Lset_consolecolor },
49 { NULL, NULL } 78 { NULL, NULL }
50 }; 79 };
51 80
52 LUALIB_API int luaopen_util_windows(lua_State *L) { 81 LUALIB_API int luaopen_util_windows(lua_State *L) {
53 luaL_register(L, "windows", Reg); 82 luaL_register(L, "windows", Reg);