求 cocos2dx 3.2 lua -cjson 安装详细

Lua CJSON、2.1.0版本、MIT协议
支持UTF-8,不支持UTF-16和UTF-32。 #没有任何影响。
支持Lua-5.1、Lua-5.2、LuaJIT。

【安装】
方法一:修改Makefile设置PREFIX变量为/usr/local/lua,然后执行make install即可。
方法二:执行make,然后cp cjson.so $LUA_MODULE_DIRECTORY即可。

上面是网上找到的安装方法,地址http://valleu87.blog.163.com/blog/static/19670343220121111045390/

以及官方文档上面说的如下(http://www.kyne.com.au/~mark/software/lua-cjson-manual.html):

2.1. Make

The included Makefile has generic settings.

First, review and update the included makefile to suit your platform (if required).

Next, build and install the module:

make install

Or install manually into your Lua module directory:

makecp cjson.so $LUA_MODULE_DIRECTORY菜鸟呀,完全不懂在哪儿执行make和make install;而且,执行了还不知道ok了没

如果是windows下,需要在fpconv.h头文件中添加
#ifdef _WIN32
#define snprintf sprintf_s
#define strncasecmp _strnicmp
#endif

然后将lua_cjson.c fpconv.c strbuf.c加入工程一起编译,然后再AppDelegate中
加入如下代码即可:
extern “C” int luaopen_cjson(lua_State *l);
然后在applicationDidFinishLaunching中调用
luaopen_cjson(LuaEngine::getInstance()->getLuaState());

你好,我把fpconv.h fpconv.c lua_cjson.c lua_cjson.h strbuf.c strbuf.h 六个文件加入到一个cjson的文件夹,
cjson文件夹和AppDelegate.cpp同目录,编译不通过,报了一堆错误(截取部分,用的vs2012):
1>d:\program files\microsoft visual studio 11.0\vc\include\cstdlib(36): error C2059: syntax error : ‘;’ (…\Classes\cjson\fpconv.c)
1>d:\program files\microsoft visual studio 11.0\vc\include\cstdlib(37): error C2061: syntax error : identifier ‘system’ (…\Classes\cjson\fpconv.c)
1>d:\program files\microsoft visual studio 11.0\vc\include\cstdlib(37): error C2059: syntax error : ‘;’ (…\Classes\cjson\fpconv.c)
1>d:\program files\microsoft visual studio 11.0\vc\include\xtgmath.h(111): warning C4602: #pragma pop_macro : ‘new’ no previous #pragma push_macro for this identifier (…\Classes\cjson\lua_cjson.c)
1>d:\program files\microsoft visual studio 11.0\vc\include\xtgmath.h(112): warning C4193: #pragma warning(pop) : no matching ‘#pragma warning(push)’ (…\Classes\cjson\lua_cjson.c)
1>d:\program files\microsoft visual studio 11.0\vc\include\xtgmath.h(113): warning C4161: #pragma pack(pop…) : more pops than pushes (…\Classes\cjson\lua_cjson.c)
1>d:\program files\microsoft visual studio 11.0\vc\include\cmath(28): error C2061: syntax error : identifier ‘acosf’ (…\Classes\cjson\lua_cjson.c)
1>d:\program files\microsoft visual studio 11.0\vc\include\cmath(28): error C2059: syntax error : ‘;’ (…\Classes\cjson\lua_cjson.c)
1>d:\program files\microsoft visual studio 11.0\vc\include\cmath(28): error C2061: syntax error : identifier ‘asinf’ (…\Classes\cjson\lua_cjson.c)

applicationDidFinishLaunching()里面,和你的有点区别,代码是这样的:

// set FPS. the default value is 1.0/60 if you don’t call this
director->setAnimationInterval(1.0 / 60);

auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine);

LuaStack* stack = engine->getLuaStack();
stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA"));

//添加cjson
//luaopen_cjson(LuaEngine::getInstance()->getLuaState());
luaopen_cjson(stack->getLuaState());

我用的是VS2013,没问题,vs2012没试过

你加入工程的位置是和我一样的吗?
代码调用是这样的吧:
local cjson = require “cjson”
local ret = cjson.decode("")

解决方法:

右击.c文件,c/c++/高级,强制包含文件,如果有algorithm或者其他的,去掉,重新编译

右击.c -> Properties -> c/c++ -> Advanced -> Forced Include File ->,如果有algorithm或者其他的,去掉,重新编译

不是这样调用的,是直接cjson.decode即可

请教,如何在 mac 下的 cocos2dx_lua 中安装或者使用cjson?

没必要安装,直接把lua-cjson的才加到你的工程编译,然后导出给lua用就行了, 也就是你手动在AppDelegate register_all_module中调用lua_cjson_open即可