Software /
code /
prosody
Annotate
util-src/windows.c @ 12119:28f723cff236
util.prosodyctl.check: Remove obsolete settings from known globals
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 25 Dec 2021 13:02:48 +0100 |
parent | 10921:6eb5d2bb11af |
child | 12575:1f6f05a98fcd |
rev | line source |
---|---|
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
1 /* Prosody IM |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
4 -- |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
6 -- COPYING file in the source package for more information. |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
7 -- |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
8 */ |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
9 |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
10 /* |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
11 * windows.c |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
12 * Windows support functions for Lua |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
13 */ |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
14 |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
15 #include <stdio.h> |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
16 #include <windows.h> |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
17 #include <windns.h> |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
18 |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
19 #include "lua.h" |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
20 #include "lauxlib.h" |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
21 |
6789
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6615
diff
changeset
|
22 #if (LUA_VERSION_NUM == 501) |
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6615
diff
changeset
|
23 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) |
6413
a552f4170aed
util-src/*.c: Add macro for compiling with Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
6412
diff
changeset
|
24 #endif |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
25 #if (LUA_VERSION_NUM < 504) |
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
26 #define luaL_pushfail lua_pushnil |
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
27 #endif |
6413
a552f4170aed
util-src/*.c: Add macro for compiling with Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
6412
diff
changeset
|
28 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
29 static int Lget_nameservers(lua_State *L) { |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
30 char stack_buffer[1024]; // stack allocated buffer |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
31 IP4_ARRAY *ips = (IP4_ARRAY *) stack_buffer; |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
32 DWORD len = sizeof(stack_buffer); |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
33 DNS_STATUS status; |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
34 |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
35 status = DnsQueryConfig(DnsConfigDnsServerList, FALSE, NULL, NULL, ips, &len); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
36 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
37 if(status == 0) { |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
38 DWORD i; |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
39 lua_createtable(L, ips->AddrCount, 0); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
40 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
41 for(i = 0; i < ips->AddrCount; i++) { |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
42 DWORD ip = ips->AddrArray[i]; |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
43 char ip_str[16] = ""; |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
44 sprintf_s(ip_str, sizeof(ip_str), "%d.%d.%d.%d", (ip >> 0) & 255, (ip >> 8) & 255, (ip >> 16) & 255, (ip >> 24) & 255); |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
45 lua_pushstring(L, ip_str); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
46 lua_rawseti(L, -2, i + 1); |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
47 } |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
48 |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
49 return 1; |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
50 } else { |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
51 luaL_pushfail(L); |
4128
b6d072a3668d
windows.c: Return nil,err from functions instead of throwing errors.
Waqas Hussain <waqas20@gmail.com>
parents:
3748
diff
changeset
|
52 lua_pushfstring(L, "DnsQueryConfig returned %d", status); |
b6d072a3668d
windows.c: Return nil,err from functions instead of throwing errors.
Waqas Hussain <waqas20@gmail.com>
parents:
3748
diff
changeset
|
53 return 2; |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
54 } |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
55 } |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
56 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
57 static int lerror(lua_State *L, char *string) { |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
58 luaL_pushfail(L); |
4128
b6d072a3668d
windows.c: Return nil,err from functions instead of throwing errors.
Waqas Hussain <waqas20@gmail.com>
parents:
3748
diff
changeset
|
59 lua_pushfstring(L, "%s: %d", string, GetLastError()); |
b6d072a3668d
windows.c: Return nil,err from functions instead of throwing errors.
Waqas Hussain <waqas20@gmail.com>
parents:
3748
diff
changeset
|
60 return 2; |
3748
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
61 } |
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
62 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
63 static int Lget_consolecolor(lua_State *L) { |
3748
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
64 HWND console = GetStdHandle(STD_OUTPUT_HANDLE); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
65 WORD color; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
66 DWORD read_len; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
67 |
3748
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
68 CONSOLE_SCREEN_BUFFER_INFO info; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
69 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
70 if(console == INVALID_HANDLE_VALUE) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
71 return lerror(L, "GetStdHandle"); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
72 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
73 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
74 if(!GetConsoleScreenBufferInfo(console, &info)) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
75 return lerror(L, "GetConsoleScreenBufferInfo"); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
76 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
77 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
78 if(!ReadConsoleOutputAttribute(console, &color, 1, info.dwCursorPosition, &read_len)) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
79 return lerror(L, "ReadConsoleOutputAttribute"); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
80 } |
3748
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
81 |
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
82 lua_pushnumber(L, color); |
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
83 return 1; |
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
84 } |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
85 static int Lset_consolecolor(lua_State *L) { |
3748
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
86 int color = luaL_checkint(L, 1); |
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
87 HWND console = GetStdHandle(STD_OUTPUT_HANDLE); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
88 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
89 if(console == INVALID_HANDLE_VALUE) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
90 return lerror(L, "GetStdHandle"); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
91 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
92 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
93 if(!SetConsoleTextAttribute(console, color)) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
94 return lerror(L, "SetConsoleTextAttribute"); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
95 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
96 |
4128
b6d072a3668d
windows.c: Return nil,err from functions instead of throwing errors.
Waqas Hussain <waqas20@gmail.com>
parents:
3748
diff
changeset
|
97 lua_pushboolean(L, 1); |
b6d072a3668d
windows.c: Return nil,err from functions instead of throwing errors.
Waqas Hussain <waqas20@gmail.com>
parents:
3748
diff
changeset
|
98 return 1; |
3748
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
99 } |
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
100 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
101 static const luaL_Reg Reg[] = { |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
102 { "get_nameservers", Lget_nameservers }, |
3748
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
103 { "get_consolecolor", Lget_consolecolor }, |
2237796ba228
util-src/windows.c: Added get_consolecolor, set_consolecolor.
Waqas Hussain <waqas20@gmail.com>
parents:
2924
diff
changeset
|
104 { "set_consolecolor", Lset_consolecolor }, |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
105 { NULL, NULL } |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
106 }; |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
107 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
108 LUALIB_API int luaopen_util_windows(lua_State *L) { |
7818
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
109 #if (LUA_VERSION_NUM > 501) |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
110 luaL_checkversion(L); |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
111 #endif |
6411
6c8f6364bc48
util-src/*.c: Don't create globals when loaded
Kim Alvefur <zash@zash.se>
parents:
5864
diff
changeset
|
112 lua_newtable(L); |
6789
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6615
diff
changeset
|
113 luaL_setfuncs(L, Reg, 0); |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
114 lua_pushliteral(L, "-3.14"); |
6412
0e94f89d0e62
util-src/*.c: Use the more concise lua_setfield
Kim Alvefur <zash@zash.se>
parents:
6411
diff
changeset
|
115 lua_setfield(L, -2, "version"); |
2924
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
116 return 1; |
8dc4e2e00129
util.windows: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
2923
diff
changeset
|
117 } |