This project provides a Lua module that uses LuaJIT's FFI to access the cURL library for network I/O. It includes a compiled shared library (curl.so) for macOS and a Lua wrapper (curl.lua).
- macOS: The provided
curl.sois compiled for macOS. - LuaJIT: You need LuaJIT installed to run the scripts.
- OpenSSL: The cURL library is linked against OpenSSL (installed via Homebrew).
- Ensure
curl.luaandcurl.soare in the same directory as your script. - Install LuaJIT if you haven't already:
brew install luajit
Require the module in your Lua script:
local curl = require("curl")local ffi = require("ffi")
local curl = require("curl")
local easy = curl.curl_easy_init()
curl.curl_easy_setopt(easy, curl.CURLOPT_URL, "https://httpbin.org/get")
curl.curl_easy_perform(easy)
curl.curl_easy_cleanup(easy)A demo script cURL Network Demo.lua is provided to test GET and POST requests.
Run it with LuaJIT:
luajit "cURL Network Demo.lua"If you need to rebuild curl.so:
- Clone the cURL repository:
git clone https://github.com/curl/curl.git cd curl git checkout curl-8_5_0 - Build with CMake (ensure OpenSSL is installed):
mkdir build && cd build cmake .. -DBUILD_SHARED_LIBS=ON -DCURL_USE_OPENSSL=ON -DOPENSSL_ROOT_DIR=$(brew --prefix openssl) make
- Copy the resulting dylib to your project root and rename it:
cp lib/libcurl.dylib ../../curl.so
This project uses libcurl, which is licensed under the curl license (MIT/X derivate).