luasocket.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Copyright (c) 2006-2015 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. #include "luasocket.h"
  21. // LuaSocket
  22. extern "C" {
  23. #include "libluasocket/luasocket.h"
  24. #include "libluasocket/mime.h"
  25. }
  26. // Quick macro for adding functions to
  27. // the preloder.
  28. #define PRELOAD(name, function) \
  29. lua_getglobal(L, "package"); \
  30. lua_getfield(L, -1, "preload"); \
  31. lua_pushcfunction(L, function); \
  32. lua_setfield(L, -2, name); \
  33. lua_pop(L, 2);
  34. namespace love
  35. {
  36. namespace luasocket
  37. {
  38. int __open(lua_State * L)
  39. {
  40. // Preload code from LuaSocket.
  41. PRELOAD("socket.core", luaopen_socket_core);
  42. PRELOAD("mime.core", luaopen_mime_core);
  43. PRELOAD("socket", __open_luasocket_socket);
  44. PRELOAD("socket.ftp", __open_luasocket_ftp)
  45. PRELOAD("socket.http", __open_luasocket_http);
  46. PRELOAD("ltn12", __open_luasocket_ltn12);
  47. PRELOAD("mime", __open_luasocket_mime)
  48. PRELOAD("socket.smtp", __open_luasocket_smtp);
  49. PRELOAD("socket.tp", __open_luasocket_tp)
  50. PRELOAD("socket.url", __open_luasocket_url)
  51. // No need to register garbage collector function.
  52. return 0;
  53. }
  54. int __open_luasocket_socket(lua_State * L)
  55. {
  56. #include "libluasocket/socket.lua.h"
  57. lua_getglobal(L, "socket");
  58. return 1;
  59. }
  60. int __open_luasocket_ftp(lua_State * L)
  61. {
  62. #include "libluasocket/ftp.lua.h"
  63. lua_getglobal(L, "socket.ftp");
  64. return 1;
  65. }
  66. int __open_luasocket_http(lua_State * L)
  67. {
  68. #include "libluasocket/http.lua.h"
  69. lua_getglobal(L, "socket.http");
  70. return 1;
  71. }
  72. int __open_luasocket_ltn12(lua_State * L)
  73. {
  74. #include "libluasocket/ltn12.lua.h"
  75. lua_getglobal(L, "ltn12");
  76. return 1;
  77. }
  78. int __open_luasocket_mime(lua_State * L)
  79. {
  80. #include "libluasocket/mime.lua.h"
  81. lua_getglobal(L, "mime");
  82. return 1;
  83. }
  84. int __open_luasocket_smtp(lua_State * L)
  85. {
  86. #include "libluasocket/smtp.lua.h"
  87. lua_getglobal(L, "socket.smtp");
  88. return 1;
  89. }
  90. int __open_luasocket_tp(lua_State * L)
  91. {
  92. #include "libluasocket/tp.lua.h"
  93. lua_getglobal(L, "socket.tp");
  94. return 1;
  95. }
  96. int __open_luasocket_url(lua_State * L)
  97. {
  98. #include "libluasocket/url.lua.h"
  99. lua_getglobal(L, "socket.url");
  100. return 1;
  101. }
  102. } // luasocket
  103. } // love