The default directory of cocos2dx lua 3.10 contains the cjson file (directory: /frameworks/cocos2d-x/external/lua), but it is not used. Instead, json.lua is used to parse json. The efficiency is low, the json string is slightly larger, and it is very stuck when decoding.
1. First add cjson to the project
< span style="font-size:16px;">
p>
2. Modify the lua_extensions.h file
< span style="font-size:16px;">Add cjson to the package.preload table, use it on the lua layer:
---json is a level of global variables and strings, you can see it by printing package.loaded
---no need to require("json" ), require("json") is redundant, require("json") and json address are the same
---When the global variable json is assigned, it can be retrieved by require("json")
function m.requireJson()
if package.preload["cjson"] then
json = require("cjson")
end
end
m.requireJson()
3.Android needs to modify the mk file, modify the target The android.mk file recorded in the jni folder of your own project proj.android
To compile the source files into the library, you need to include all the source files under cjson
Reference: cocos2dx3.1 lua binding C++ classes< /p>
Lua CJSON is a high-performance JSON parser and encoder provided by Lua language, its performance is better than pure Lua library 10 to 20 times higher.
The default directory of cocos2dx lua 3.10 contains the cjson file (directory: /frameworks/cocos2d-x/external/lua), but it is not used. Instead, json.lua is used to parse json. The efficiency is low, the json string is slightly larger, and it is very stuck when decoding.
1. First add cjson to the project
< span style="font-size:16px;">
p>
2. Modify the lua_extensions.h file
< span style="font-size:16px;">Add cjson to the package.preload table, use it on the lua layer:
---json is a level of global variables and strings, you can see it by printing package.loaded
---no need to require("json" ), require("json") is redundant, require("json") and json address are the same
---When the global variable json is assigned, it can be retrieved by require("json")
function m.requireJson()
if package.preload["cjson"] then
json = require("cjson")
end
end
m.requireJson()
3.Android needs to modify the mk file, modify the directory in your own project pr The android.mk file in the jni folder under oj.android
To compile the source files into the library, you need to include all the source files under cjson
Reference: cocos2dx3.1 lua binding C++ classes
< /p>