1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #include "luasocket.h" |
22 | |
23 | // LuaSocket |
24 | extern "C" { |
25 | #include "libluasocket/luasocket.h" |
26 | #include "libluasocket/mime.h" |
27 | } |
28 | |
29 | // Quick macro for adding functions to |
30 | // the preloder. |
31 | #define PRELOAD(name, function) \ |
32 | lua_getglobal(L, "package"); \ |
33 | lua_getfield(L, -1, "preload"); \ |
34 | lua_pushcfunction(L, function); \ |
35 | lua_setfield(L, -2, name); \ |
36 | lua_pop(L, 2); |
37 | |
38 | namespace love |
39 | { |
40 | namespace luasocket |
41 | { |
42 | |
43 | int __open(lua_State * L) |
44 | { |
45 | |
46 | // Preload code from LuaSocket. |
47 | PRELOAD("socket.core" , luaopen_socket_core); |
48 | PRELOAD("mime.core" , luaopen_mime_core); |
49 | |
50 | PRELOAD("socket" , __open_luasocket_socket); |
51 | PRELOAD("socket.ftp" , __open_luasocket_ftp) |
52 | PRELOAD("socket.http" , __open_luasocket_http); |
53 | PRELOAD("ltn12" , __open_luasocket_ltn12); |
54 | PRELOAD("mime" , __open_luasocket_mime) |
55 | PRELOAD("socket.smtp" , __open_luasocket_smtp); |
56 | PRELOAD("socket.tp" , __open_luasocket_tp) |
57 | PRELOAD("socket.url" , __open_luasocket_url) |
58 | PRELOAD("socket.headers" , __open_luasocket_headers) |
59 | PRELOAD("mbox" , __open_luasocket_mbox) |
60 | |
61 | // No need to register garbage collector function. |
62 | |
63 | return 0; |
64 | } |
65 | |
66 | int __open_luasocket_socket(lua_State * L) |
67 | { |
68 | #include "libluasocket/socket.lua.h" |
69 | return 1; |
70 | } |
71 | |
72 | int __open_luasocket_ftp(lua_State * L) |
73 | { |
74 | #include "libluasocket/ftp.lua.h" |
75 | return 1; |
76 | } |
77 | |
78 | int __open_luasocket_http(lua_State * L) |
79 | { |
80 | #include "libluasocket/http.lua.h" |
81 | return 1; |
82 | } |
83 | |
84 | int __open_luasocket_ltn12(lua_State * L) |
85 | { |
86 | #include "libluasocket/ltn12.lua.h" |
87 | return 1; |
88 | } |
89 | |
90 | int __open_luasocket_mime(lua_State * L) |
91 | { |
92 | #include "libluasocket/mime.lua.h" |
93 | return 1; |
94 | } |
95 | |
96 | int __open_luasocket_smtp(lua_State * L) |
97 | { |
98 | #include "libluasocket/smtp.lua.h" |
99 | return 1; |
100 | } |
101 | |
102 | int __open_luasocket_tp(lua_State * L) |
103 | { |
104 | #include "libluasocket/tp.lua.h" |
105 | return 1; |
106 | } |
107 | |
108 | int __open_luasocket_url(lua_State * L) |
109 | { |
110 | #include "libluasocket/url.lua.h" |
111 | return 1; |
112 | } |
113 | |
114 | int (lua_State * L) |
115 | { |
116 | #include "libluasocket/headers.lua.h" |
117 | return 1; |
118 | } |
119 | |
120 | int __open_luasocket_mbox(lua_State * L) |
121 | { |
122 | #include "libluasocket/mbox.lua.h" |
123 | return 1; |
124 | } |
125 | |
126 | } // luasocket |
127 | } // love |
128 | |