{"id":28586366,"url":"https://github.com/paintdream/ngx_lua_cpp","last_synced_at":"2026-05-04T12:34:57.539Z","repository":{"id":296841286,"uuid":"994635062","full_name":"paintdream/ngx_lua_cpp","owner":"paintdream","description":"Developing plugable OpenResty ngx_lua extensions with C++ (including coroutines). Based on iristorm library.","archived":false,"fork":false,"pushed_at":"2026-03-23T05:30:02.000Z","size":80,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-24T01:55:20.859Z","etag":null,"topics":["cpp20","iristorm","lua","nginx","openresty"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paintdream.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-02T08:42:24.000Z","updated_at":"2026-03-23T05:30:05.000Z","dependencies_parsed_at":"2025-06-02T21:48:58.165Z","dependency_job_id":"057845ef-9c5e-4b50-92ca-f8fcde84b574","html_url":"https://github.com/paintdream/ngx_lua_cpp","commit_stats":null,"previous_names":["paintdream/ngx_lua_cpp"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/paintdream/ngx_lua_cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paintdream%2Fngx_lua_cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paintdream%2Fngx_lua_cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paintdream%2Fngx_lua_cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paintdream%2Fngx_lua_cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paintdream","download_url":"https://codeload.github.com/paintdream/ngx_lua_cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paintdream%2Fngx_lua_cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32607725,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp20","iristorm","lua","nginx","openresty"],"created_at":"2025-06-11T07:00:45.976Z","updated_at":"2026-05-04T12:34:57.533Z","avatar_url":"https://github.com/paintdream.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ngx_lua_cpp\nDeveloping OpenResty ngx_lua extensions with C++ (including coroutines). Based on [iris](https://github.com/paintdream/iris) library.\n\n## License\n\nngx_lua_cpp is distributed under MIT License.\n\n## Build\n\nngx_lua_cpp requires a C++ 20 compatible compiler (Visual Studio 2019+, GCC 11+, Clang 14+).\n\nJust use CMake to generate project with CMakeLists.txt.\n\nIf you got problem in finding LuaJIT, please configure its installation path (usually it could be found at OpenResty's installation directory) to environment variable LUA_DIR.\n\nNotice that ngx_lua_cpp is an isolated component for LuaJIT. You do not need any header files from OpenResty. All related OpenResty/Nginx declarations could be find at ngx_lua_cpp.cpp. Modify these declarations if it is incompatible with your custom OpenResty build. (Usually you needn't do this.)\n\n## Install\n\nConfigure **nginx.conf**, add these lines to your stream/http block:\n\n```lua\n\tinit_worker_by_lua_block {\n\t\tpackage.path = package.path .. \";[[ngx_lua_cpp source directory]]/demo/?.lua\"\n\t\tpackage.cpath = package.cpath .. \";[[ngx_lua_cpp binary directory]]/?.dll;[[ngx_lua_cpp binary directory]]/lib?.so;\"\n\t\trequire(\"init_ngx_lua_cpp\")\n\t}\n```\n\n**init_gnx_lua_cpp.lua** is a lua module shared by all requests. It initializes a **ngx_lua_cpp** instance and return it as its module instance. \n\n```lua\n-- init_ngx_lua_cpp.lua\n\nlocal lib = require(\"ngx_lua_cpp\")\nif lib then\n\tlocal inst = lib.new()\n\tinst:start(4) -- thread count\n\treturn inst\nelse\n\tngx.log(ngx.ERR, \"ngx_lua_cpp not found!\")\nend\n\n```\n\nFor http, configure at **http/server** block:\n\n```lua\n\tlocation ~ /lua.html {\n\t\tdefault_type text/html;\n\t\tcontent_by_lua_block {\n\t\t\tlocal inst = require(\"init_ngx_lua_cpp\")\n\t\t\tlocal value = inst:sleep(40)\n\t\t\tngx.say(\"ngx_lua_cpp http demo! Running \" .. tostring(inst:is_running()) .. \" | \" .. tostring(value))\n\t\t}\n\t}\n}\n```\n\nFor stream, configure at **stream** block)\n\n```lua\n\tserver {\n\t\tlisten 1234;\n\n\t\tcontent_by_lua_block {\n\t\t\tlocal inst = require(\"init_ngx_lua_cpp\")\n\t\t\tlocal value = inst:sleep(40)\n\t\t\tngx.say(\"ngx_lua_cpp stream demo! Running \" .. tostring(inst:is_running()) .. \" | \" .. tostring(value))\n\t\t}\n\t}\n```\n\n## Usage\n\nIn ngx_lua_cpp.cpp, you could see an example function: **a coroutine-based asynchornized \"sleep\"**.\n\nIt is registered in ngx_lua_cpp_t::lua_registar():\n\n```C++\nvoid ngx_lua_cpp_t::lua_registar(lua_t lua, iris_lua_traits_t\u003cngx_lua_cpp_t\u003e) {\n\t// ...\n\tlua.set_current\u003c\u0026ngx_lua_cpp_t::sleep\u003e(\"sleep\");\n}\n```\n\nHere is the implementation:\n\n```C++\ncoroutine_t\u003csize_t\u003e ngx_lua_cpp_t::sleep(size_t millseconds) {\n\twarp_t* current = co_await iris_switch\u003cwarp_t\u003e(nullptr);\n\tstd::this_thread::sleep_for(std::chrono::milliseconds(millseconds));\n\tco_await iris_switch(current);\n\tco_return std::move(millseconds);\n}\n```\n\nYou can use coroutines and the warp (strand) system from the iris library, which are fully compatible with OpenResty/Nginx's task scheduler.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaintdream%2Fngx_lua_cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaintdream%2Fngx_lua_cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaintdream%2Fngx_lua_cpp/lists"}