如题,使用cocos2dx lua自带的json效率很低,接入cjson来处理:
1、找到frameworks\cocos2d-x\cocos\scripting\lua-bindings\manual\network\lua_extensions.c,修改:
#include "lua_extensions.h" #if __cplusplus extern "C" { #endif // socket #include "luasocket/luasocket.h" #include "luasocket/luasocket_scripts.h" #include "luasocket/mime.h" #include "lua/cjson/lua_cjson.h" static luaL_Reg luax_exts[] = { {"socket.core",luaopen_socket_core},{"mime.core",luaopen_mime_core},{"cjson",luaopen_cjson },{NULL,NULL} }; void luaopen_lua_extensions(lua_State *L) { // load extensions luaL_Reg* lib = luax_exts; lua_getglobal(L,"package"); lua_getfield(L,-1,"preload"); for (; lib->func; lib++) { lua_pushcfunction(L,lib->func); lua_setfield(L,-2,lib->name); } lua_pop(L,2); luaopen_luasocket_scripts(L); } #if __cplusplus } // extern "C" #endif
2、android打包库里添加: frameworks\cocos2d-x\cocos\scripting\lua-bindings\proj.android\Android.mk
../../../../external/lua/cjson/strbuf.c \ ../../../../external/lua/cjson/fpconv.c \ ../../../../external/lua/cjson/lua_cjson.c \3、ios平台暂时未处理,待续~~~