Skip to content

Commit

Permalink
Upgrade rapidjson to 1.1.0+.
Browse files Browse the repository at this point in the history
  • Loading branch information
xpol committed Oct 19, 2016
1 parent 93ec317 commit 913dc12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion spec/json_decode_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('rapidjson.decode()', function()
r, m = rapidjson.decode('{}10')
assert.are.equal(nil, r)
assert.are.equal('string', type(m))
idx = string.find(m, "The document root must not follow by other values.", 1, true)
idx = string.find(m, "The document root must not be followed by other values.", 1, true)
assert.are_not.equal(nil, idx)

r, m = rapidjson.decode('{"a":b}')
Expand Down
25 changes: 16 additions & 9 deletions src/rapidjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ static int json_array(lua_State* L)


struct Ctx {
Ctx() : fn_(&topFn){}
Ctx(const Ctx& rhs) : table_(rhs.table_), index(rhs.index), fn_(rhs.fn_)
Ctx() : table_(null), index_(1), fn_(&topFn){}
Ctx(const Ctx& rhs) : table_(rhs.table_), index_(rhs.index_), fn_(rhs.fn_)
{
}
const Ctx& operator=(const Ctx& rhs){
if (this != &rhs) {
table_ = rhs.table_;
index = rhs.index;
index_ = rhs.index_;
fn_ = rhs.fn_;
}
return *this;
Expand All @@ -171,10 +171,10 @@ struct Ctx {
fn_(L, this);
}
private:
Ctx(int table, void(*f)(lua_State* L, Ctx* ctx)) : table_(table), index(1), fn_(f) {}
Ctx(int table, void(*f)(lua_State* L, Ctx* ctx)) : table_(table), index_(1), fn_(f) {}

int table_;
int index;
int index_;
void(*fn_)(lua_State* L, Ctx* ctx);

static void objectFn(lua_State* L, Ctx* ctx)
Expand All @@ -184,7 +184,7 @@ struct Ctx {

static void arrayFn(lua_State* L, Ctx* ctx)
{
lua_rawseti(L, ctx->table_, ctx->index++);
lua_rawseti(L, ctx->table_, ctx->index_++);
}
static void topFn(lua_State* L, Ctx* ctx)
{
Expand Down Expand Up @@ -238,6 +238,13 @@ struct ToLuaHandler {
current_.submit(L);
return true;
}
bool RawNumber(const char* str, SizeType length, bool copy) {
lua_getfield(L, LUA_GLOBALSINDEX, "tonumber");
lua_pushlstring(L, str, length);
lua_call(L, 1, 1);
current_.submit(L);
return true;
}
bool String(const char* str, SizeType length, bool copy) {
lua_pushlstring(L, str, length);
current_.submit(L);
Expand Down Expand Up @@ -378,7 +385,7 @@ class Encoder {
int v = def;
lua_getfield(L, idx, name); // [field]
if (lua_isnumber(L, -1))
v = lua_tointeger(L, -1);
v = static_cast<int>(lua_tointeger(L, -1));
lua_pop(L, 1);
return v;
}
Expand Down Expand Up @@ -657,11 +664,11 @@ static int json_dump(lua_State* L)


static const luaL_Reg methods[] = {
// string <--> json
// string <--> lua table
{ "decode", json_decode },
{ "encode", json_encode },

// file <--> json
// file <--> lua table
{ "load", json_load },
{ "dump", json_dump },

Expand Down

0 comments on commit 913dc12

Please sign in to comment.