在appDelegate.cpp文件中添加

#if __cplusplus
extern "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

 

 cocos2dx 启用cjson

 

然后调用register_cjson(L);

 cocos2dx 启用cjson

 

如果有报错:

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

解决方案:去掉static声明

cocos2dx 启用cjson

 

相关文章:

  • 2022-12-23
  • 2022-02-13
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-12-05
  • 2021-08-10
猜你喜欢
  • 2021-08-02
  • 2021-08-13
  • 2021-09-26
  • 2022-12-23
  • 2021-06-03
相关资源
相似解决方案