{"id":22526787,"url":"https://github.com/yinheli/lua-bridge","last_synced_at":"2026-05-04T03:34:18.359Z","repository":{"id":250566636,"uuid":"833896679","full_name":"yinheli/lua-bridge","owner":"yinheli","description":"一个简单的 TCP 代理，lua 脚本可以处理双向数据流","archived":false,"fork":false,"pushed_at":"2024-08-01T06:04:36.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T04:19:41.222Z","etag":null,"topics":["freelancing","lua","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yinheli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-07-26T02:01:29.000Z","updated_at":"2024-08-01T06:04:39.000Z","dependencies_parsed_at":"2024-08-01T07:39:08.299Z","dependency_job_id":null,"html_url":"https://github.com/yinheli/lua-bridge","commit_stats":null,"previous_names":["yinheli/lua-bridge"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/yinheli/lua-bridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinheli%2Flua-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinheli%2Flua-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinheli%2Flua-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinheli%2Flua-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yinheli","download_url":"https://codeload.github.com/yinheli/lua-bridge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinheli%2Flua-bridge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32593944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"online","status_checked_at":"2026-05-04T02:00:06.625Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["freelancing","lua","rust"],"created_at":"2024-12-07T06:18:37.314Z","updated_at":"2026-05-04T03:34:18.344Z","avatar_url":"https://github.com/yinheli.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua bridge\n\n## 需求\n\n- Rust tcp 代理，数据流转到 lua 脚本\n\n## 配置\n\n```env\n# 本地监听地址\nLISTEN=0.0.0.0:5000\n\n# 后端服务地址\nBACKEND=127.0.0.1:8081\n\n# MySQL 数据库\nMYSQL_URI=\n\n# Redis 数据库\nREDIS_URI=\n\n# Lua 脚本文件路径\nSCRIPT=./app.lua\n\n# Lua 脚本入口函数名\nSCRIPT_ENTRY=handle\n```\n\n\n## 函数\n\nlua 脚本\n\n全局函数， 参考 script 中的 register_xxx 函数注入到 lua 中的全局函数或者常量。\n\n入口函数, 传入参数为 `ctx`，类型为 `table`，包含的方法参考 script 中 Ctx 结构，UserData 实现的的 add_methods 方法。\n\n- read_client\n- read_backend\n- write_client\n- write_backend\n- close_client\n- close_backend\n- ......\n\n```lua\nfunction handle(ctx)\n\nend\n```\n\n## 依赖管理\n\n以 Debian 12 为为例\n\n```bash\napt-get install -y build-essential git libssl-dev lua5.1 liblua5.1-dev\napt-get install -y luarocks\n```\n\n```bash\n# 安装依赖，比如\n# 更多信息参考 https://luarocks.org/\nluarocks install lua-cjson\nluarocks install serpent\n```\n\n### 安装到非全局\n\n```bash\nluarocks install lua-cjson --tree $PWD/.rocks\nluarocks install serpent --tree $PWD/.rocks\n```\n\n安装到当前目录的 .rocks 目录下, 查看目录结构\n\n```bash\ntree $PWD/.rocks\n```\n\n```\n|-- bin\n|   |-- json2lua\n|   `-- lua2json\n|-- lib\n|   |-- lua\n|   |   `-- 5.1\n|   |       `-- cjson.so\n|   `-- luarocks\n|       `-- rocks-5.1\n|           |-- lua-cjson\n|           |   `-- 2.1.0.10-1\n|           |       |-- bin\n|           |       |   |-- json2lua\n|           |       |   `-- lua2json\n|           |       |-- lua-cjson-2.1.0.10-1.rockspec\n|           |       |-- rock_manifest\n|           |       `-- tests\n|           |           |-- README\n|           |           |-- TestLua.pm\n|           |           |-- agentzh.t\n|           |           |-- bench.lua\n|           |           |-- example1.json\n|           |           |-- example2.json\n|           |           |-- example3.json\n|           |           |-- example4.json\n|           |           |-- example5.json\n|           |           |-- genutf8.pl\n|           |           |-- numbers.json\n|           |           |-- octets-escaped.dat\n|           |           |-- rfc-example1.json\n|           |           |-- rfc-example2.json\n|           |           |-- sort_json.lua\n|           |           |-- test.lua\n|           |           `-- types.json\n|           `-- manifest\n`-- share\n    `-- lua\n        `-- 5.1\n            |-- cjson\n            |   `-- util.lua\n            |-- json2lua.lua\n            `-- lua2json.lua\n\n15 directories, 28 files\n```\n\n\n```bash\nexport LUA_PATH=\"$PWD/.rocks/share/lua/5.1/?.lua;$PWD/.rocks/share/lua/5.1/?/init.lua;;\"\nexport LUA_CPATH=\"$PWD/.rocks/lib/lua/5.1/?.so;;\"\n```\n\n\u003e 可以把上述环境变量写入到 env.sh 中，然后 source env.sh\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyinheli%2Flua-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyinheli%2Flua-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyinheli%2Flua-bridge/lists"}