cocos2dx 启用cjson

在appDelegate.cpp文件中添加

#if __cplusplusextern "C" { // 加入此代码的目的,防止污染引擎的scripting目录#include "lua/cjson/lua_cjson.h" void register_cjson(lua_State *L){ lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_pushcfunction(L, luaopen_cjson); lua_setfield(L, -2, "cjson"); lua_pop(L, 2); }}// extern "C"#endif

 

 

 

然后调用register_cjson(L);

 

 

如果有报错:

lua_cjson.c:1328:13: Static declaration of ‘luaL_setfuncs’ follows non-static declaration

解决方案:去掉static声明

 

相关文章