Cocos2d-x3.10 增加cjson使用的配置

#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) 

 

转载于:https://my.oschina.net/u/2318830/blog/780007

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值