{"id":21807671,"url":"https://github.com/yeshan333/calling-c-func-in-lua-demo","last_synced_at":"2026-05-17T22:32:46.989Z","repository":{"id":250851528,"uuid":"828588313","full_name":"yeshan333/calling-c-func-in-lua-demo","owner":"yeshan333","description":"For comparing the difference of the C API luaL_tolstring of two lua versions","archived":false,"fork":false,"pushed_at":"2024-07-30T09:35:02.000Z","size":794,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-21T15:04:27.103Z","etag":null,"topics":["c","lua","lua-c","makefile","xmake"],"latest_commit_sha":null,"homepage":"","language":"C","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/yeshan333.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-14T15:45:08.000Z","updated_at":"2024-07-30T09:35:06.000Z","dependencies_parsed_at":"2024-07-30T12:49:32.132Z","dependency_job_id":"ba77aa90-153a-43a4-870a-abd2497adce8","html_url":"https://github.com/yeshan333/calling-c-func-in-lua-demo","commit_stats":null,"previous_names":["yeshan333/calling-c-func-in-lua-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yeshan333/calling-c-func-in-lua-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeshan333%2Fcalling-c-func-in-lua-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeshan333%2Fcalling-c-func-in-lua-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeshan333%2Fcalling-c-func-in-lua-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeshan333%2Fcalling-c-func-in-lua-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yeshan333","download_url":"https://codeload.github.com/yeshan333/calling-c-func-in-lua-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeshan333%2Fcalling-c-func-in-lua-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33157510,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T09:28:26.183Z","status":"ssl_error","status_checked_at":"2026-05-17T09:27:52.702Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["c","lua","lua-c","makefile","xmake"],"created_at":"2024-11-27T12:46:58.737Z","updated_at":"2026-05-17T22:32:46.964Z","avatar_url":"https://github.com/yeshan333.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 在 lua 脚本中调用 C 函数\n\n[English](README_en.md)\n\n\u003e 用于对比两个 lua 版本 C API luaL_tolstring 的表现\n\n## 快速开始\n\n```shell\n# 安装两个 lua 版本\nmake install_lua\n\n# 编译自定义 C 库\nmake compile_cmp1_so\n# 测试版本 1，lua C API luaL_tolstring 的表现\nmake test_cmp1\n# 测试版本 2，lua C API luaL_tolstring 的表现\nmake compile_cmp2_so\nmake test_cmp2\n```\n\n使用 xmake 编译\n\n```shell\n# 指定 lua 版本进行编译 mylib.c\nxmake f --lua_version=5.4.6 -v\nxmake -v\n\n# 测试版本 1 lua 5.4.7，lua C API luaL_tolstring 的表现\nmake test_cmp1\n# 测试版本 2 lua 5.4.6，lua C API luaL_tolstring 的表现\nmake test_cmp2\n```\n\n---\n\n```c\nstatic int my_printer(lua_State *L)\n{\n    size_t len;\n    const int arg1 = luaL_checkinteger(L, 1);\n    printf(\"arg1: %d\\n\", arg1);\n    const uint8_t* s = (const uint8_t*)luaL_tolstring(L, 2, \u0026len);\n    printf(\"my printer's output: %s, length: %zu\\n\", s, len);\n    // lua_pushstring(L, s);\n    return 0;\n}\n```\n\nCompare Result (test my_printer func):\n\n```shell\n# lua 5.4.7\necho \"Testing lua version: lua-5.4.7\"\nTesting lua version: lua-5.4.7\n/github/calling-c-func-in-lua-demo/lua-5.4.7/install/bin/lua test_printer.lua\narg1: 1\nmy printer's output: Oh my god, length: 9\narg1: 2\nmy printer's output: Oh my god, length: 9\narg1: 3\nmy printer's output: Oh my god, length: 9\n```\n\n```shell\necho \"Testing lua version: lua-5.4.6\"\nTesting lua version: lua-5.4.6\n/github/calling-c-func-in-lua-demo/lua-5.4.6/install/bin/lua test_printer.lua\narg1: 1\nmy printer's output: Oh my god, length: 9\narg1: 2\nmy printer's output: Oh my god, length: 9\narg1: 3\nmy printer's output: Oh my god, length: 9\n```\n\n##  参考\n\nhttps://www.nosuchfield.com/2019/05/17/Call-C-function-in-Lua/\nhttp://www.troubleshooters.com/codecorn/lua/lua_lua_calls_c.htm\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeshan333%2Fcalling-c-func-in-lua-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeshan333%2Fcalling-c-func-in-lua-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeshan333%2Fcalling-c-func-in-lua-demo/lists"}