#include "lua_extensions.h"
#if __cplusplus
extern "C" {
#endif
// cjson
#include "lua_cjson.h"
static luaL_Reg luax_exts[] = {
{"cjson", luaopen_cjson},
{NULL, NULL}
};
#include "tolua_fix.h"
void luaopen_lua_extensions(lua_State *L)
{
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);
}
#if __cplusplus
} // extern "C"
#endif
Cocos3.10 增加cjson使用的配置,需要在工程项目里“”添加”->"现有项",把cjson加入到工程里。
环境:
win7
vs2013
测试方法:
local cjson = require("cjson")
local tab ={}
tab["hi"] = "lelenb.com"
--数据转json
local jsonData = cjson.encode(tab)
print(jsonData)