{"id":22941917,"url":"https://github.com/dot123/cocos2d-lua-sproto","last_synced_at":"2025-04-01T21:17:51.459Z","repository":{"id":144651736,"uuid":"75831365","full_name":"dot123/cocos2d-lua-sproto","owner":"dot123","description":"cocos2d-lua集成sproto协议","archived":false,"fork":false,"pushed_at":"2021-10-11T16:30:45.000Z","size":137,"stargazers_count":14,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-07T13:48:23.291Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Makefile","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/dot123.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}},"created_at":"2016-12-07T11:52:37.000Z","updated_at":"2024-06-08T13:31:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"17717882-9c0a-42a9-8304-a40a25a8542d","html_url":"https://github.com/dot123/cocos2d-lua-sproto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dot123%2Fcocos2d-lua-sproto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dot123%2Fcocos2d-lua-sproto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dot123%2Fcocos2d-lua-sproto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dot123%2Fcocos2d-lua-sproto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dot123","download_url":"https://codeload.github.com/dot123/cocos2d-lua-sproto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246709912,"owners_count":20821298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-12-14T13:45:32.268Z","updated_at":"2025-04-01T21:17:51.437Z","avatar_url":"https://github.com/dot123.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"在cocos2d-x/external/lua 目录下新建四个文件夹sproto,bitop,lpeg,lpack。然后将各自的文件放入其中，为了符合cocos2dx的规范，需要在bitop中建立一个bit.h文件，内容如下:\n``` \n#ifndef __LUA_BITOP_H_\n#define __LUA_BITOP_H_\n\n#if __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lauxlib.h\"\n\nLUALIB_API int luaopen_bit(lua_State *L);\n\n#if __cplusplus\n}\n#endif\n\n#endif\n``` \n在lpeg中建立一个lpeg.h文件，内容如下:\n``` \n#ifndef __LUA_LPEG_H_\n#define __LUA_LPEG_H_\n\n#if __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lpeg/lptypes.h\"\n#include \"lpeg/lpcap.h\"\n#include \"lpeg/lpcode.h\"\n#include \"lpeg/lpprint.h\"\n#include \"lpeg/lptree.h\"\n#include \"lpeg/lpvm.h\"\n\nint luaopen_lpeg(lua_State *L);\n  \n\n#if __cplusplus\n}\n#endif\n\n#endif\n``` \n在sproto中建立一个lsproto.h文件，内容如下:\n``` \n#ifndef __LUA_LSPROTO_H_\n#define __LUA_LSPROTO_H_\n\n#if __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lauxlib.h\"\n\nint luaopen_sproto_core(lua_State *L);\n\n#if __cplusplus\n}\n#endif\n\n#endif\n``` \n在lpack中建立一个lpack.h文件，内容如下:\n``` \n#ifndef __LUA_LPACK_H_\n#define __LUA_LPACK_H_\n#if __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lauxlib.h\"\n\nint luaopen_pack(lua_State *L);\n\n#if __cplusplus\n}\n#endif\n#endif\n``` \n\n在cocos2d-x/cocos/scripting/lua-bindings/manual/network目录下，找到 lua_extensions.c 文件。在头部包含所需文件。\n``` \n#include \"sproto/lsproto.h\"\n#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)\n#include \"bitop/bit.h\"\n#endif\n#include \"lpeg/lpeg.h\"\n#include \"lpack/lpack.h\"\n\n在luax_exts内，加入下列几行。\n\n  { \"sproto.core\", luaopen_sproto_core },\n#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)\n  { \"bit\", luaopen_bit },\n#endif\n  { \"lpeg\", luaopen_lpeg },\n  { \"string\", luaopen_pack },\n\n``` \nAndroid支持\n\n在cocos2d-x/cocos/scripting/lua-bindings/proj.android目录下，打开 Android.mk 文件，在那一长串加载c文件后面，加入我们需要的c文件\n``` \n      ../../../../external/lua/lpeg/lpcap.c \\\n      ../../../../external/lua/lpeg/lpcode.c \\\n      ../../../../external/lua/lpeg/lpprint.c \\\n      ../../../../external/lua/lpeg/lptree.c \\\n      ../../../../external/lua/lpeg/lpvm.c \\\n      ../../../../external/lua/sproto/lsproto.c \\\n      ../../../../external/lua/sproto/sproto.c \\\n      ../../../../external/lua/lpack/lpack.c \n``` \nAndroid支持luajit库，里面已经包含了bit库，所以不用加bit.c了，不然编译的时候会出现多重定义的错误。\n\n总得来说还是很简单的，只需三步：\n  文件放到cocos2d-x/external/lua目录下\n  修改lua_extensions.c，包含相关文件\n  修改Android.mk做Android支持\n \nhttps://github.com/dot123/cocos2d-lua-sproto.git\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdot123%2Fcocos2d-lua-sproto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdot123%2Fcocos2d-lua-sproto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdot123%2Fcocos2d-lua-sproto/lists"}