|
| 1 | +# lua-https |
| 2 | + |
| 3 | +lua-https is a simple Lua HTTPS module using native platform backends |
| 4 | +specifically written for [LÖVE](https://love2d.org) 12.0 and supports |
| 5 | +Windows, Linux, macOS, iOS, and Android. |
| 6 | + |
| 7 | +## Reference |
| 8 | + |
| 9 | +To use lua-https, load it with require like `local https = require("https")`. |
| 10 | +lua-https does not create global variables! |
| 11 | + |
| 12 | +The https module exposes a single function: `https.request`. |
| 13 | + |
| 14 | +## Synopsis |
| 15 | + |
| 16 | +Simplified form: |
| 17 | + |
| 18 | +```lua |
| 19 | +code, body = https.request( url ) |
| 20 | +``` |
| 21 | + |
| 22 | +If you need to specify headers in the request or get them in the |
| 23 | +response, you can use the full form: |
| 24 | + |
| 25 | +```lua |
| 26 | +code, body, headers = https.request( url, options ) |
| 27 | +``` |
| 28 | + |
| 29 | +### Arguments |
| 30 | + |
| 31 | +* string `url`: HTTP or HTTPS URL to access. |
| 32 | +* table `options`: Optional options for advanced mode. |
| 33 | + * string `data`: Additional data to send as application/x-www-form-urlencoded (unless specified otherwise in Content-Type header). |
| 34 | + * string `method`: HTTP method. If absent, it's either "GET" or "POST" depending on the data field above. |
| 35 | + * table `headers`: Additional headers to add to the request as key-value pairs. |
| 36 | + |
| 37 | +### Return values |
| 38 | + |
| 39 | +* number `code`: HTTP status code, or 0 on failure. |
| 40 | +* string `body`: HTTP response body or nil on failure. |
| 41 | +* table `headers`: HTTP response headers as key-value pairs or nil on failure or option parameter above is nil. |
| 42 | + |
| 43 | +## Compile From Source |
| 44 | + |
| 45 | +While lua-https is bundled in LÖVE 12.0 by default, it's possible to |
| 46 | +compile the module from source and use it on earlier version of LÖVE |
| 47 | +or Lua. All compilation requires Lua 5.1 (or LuaJIT) headers and libraries. |
| 48 | + |
| 49 | +### Linux |
| 50 | + |
| 51 | +Ensure you have CMake as well as the OpenSSL and cURL development |
| 52 | +libraries installed. |
| 53 | + |
| 54 | +``` |
| 55 | +cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install |
| 56 | +cmake --build build --target install |
| 57 | +``` |
| 58 | + |
| 59 | +`https.so` can be found in the `install` folder. |
| 60 | + |
| 61 | +### Windows |
| 62 | + |
| 63 | +Compilation is done using CMake. This assume MSVC toolchain is |
| 64 | +used. Change "x64" to "Win32" to compile for x86 32-bit platform or |
| 65 | +"ARM64" for ARM64 platform. |
| 66 | + |
| 67 | +``` |
| 68 | +cmake -Bbuild -S. -A x64 -DCMAKE_INSTALL_PREFIX=%CD%\install |
| 69 | +cmake --build build --config Release --target install |
| 70 | +``` |
| 71 | + |
| 72 | +https.dll can be found in the install folder. |
| 73 | + |
| 74 | +### Android |
| 75 | + |
| 76 | +Available since LÖVE 11.4 |
| 77 | +Proper 3rd-party C module support requires this LÖVE version. |
| 78 | + |
| 79 | +Compilation is done by placing lua-https source code in |
| 80 | +`<love-android>/love/src/jni/lua-modules`. The structure will look like this: |
| 81 | + |
| 82 | +`<love-android>/love/src/jni/lua-modules/lua-https` |
| 83 | ++ example |
| 84 | ++ src |
| 85 | ++ Android.mk |
| 86 | ++ CMakeLists.txt |
| 87 | ++ java.txt |
| 88 | ++ license.txt |
| 89 | + |
| 90 | +Afterwards compile love-android as usual. The modules will be |
| 91 | +automatically embedded to the APK. This can be verified by checking |
| 92 | +the APK with Zip viewer application and inspecting files in |
| 93 | +lib/arm64-v8a and lib/armeabi-v7a. |
| 94 | + |
| 95 | +## Copyright |
| 96 | + |
| 97 | +Copyright © 2019-2025 LOVE Development Team |
| 98 | + |
| 99 | +lua-https is licensed under [zLib license](license.txt), same as LÖVE. |
0 commit comments