Permalink
Browse files

Fix issue with yajl_config() getting called instead of yajl_gen_confi…

…g() and properly configure the print callback. Unit tests where also updated to deal with higher precision of doubles.
  • Loading branch information...
1 parent 8f8c10e commit ea2118ae35e432df5ab9fb191396b662505c41b2 @brimworks committed Apr 29, 2011
Showing with 7 additions and 3 deletions.
  1. +6 −2 lua_yajl.c
  2. +1 −1 test.lua
View
@@ -887,11 +887,15 @@ static int js_generator(lua_State *L) {
yajl_gen* handle = (yajl_gen*)lua_newuserdata(L, sizeof(yajl_gen));
*handle = yajl_gen_alloc(NULL);
+ if ( print ) {
+ yajl_gen_config(*handle, yajl_gen_print_callback, print, ctx);
+ }
+
// Get the indent and save so it isn't gc'ed:
lua_getfield(L, 1, "indent");
if ( ! lua_isnil(L, -1) ) {
- yajl_config(*handle, yajl_gen_beautify, 1);
- yajl_config(*handle, yajl_gen_indent_string, lua_tostring(L, -1));
+ yajl_gen_config(*handle, yajl_gen_beautify, 1);
+ yajl_gen_config(*handle, yajl_gen_indent_string, lua_tostring(L, -1));
lua_setfield(L, -2, "indent");
} else {
lua_pop(L, 1);
View
@@ -101,7 +101,7 @@ function test_generator()
generator:close()
generator:close()
- local expect = '[["float",1.5,"integer",5,"string","hello","empty",[],"false",false,"custom","custom json serializer","ostr_key",{"key":"value"},"obool_key",{"true":true},"onull_key",{"null":null}],10,10.3,10.3,"a string",null,false,true,{}]'
+ local expect = '[["float",1.5,"integer",5,"string","hello","empty",[],"false",false,"custom","custom json serializer","ostr_key",{"key":"value"},"obool_key",{"true":true},"onull_key",{"null":null}],10,10.300000000000000711,10.3,"a string",null,false,true,{}]'
local got = table.concat(strings)
ok(expect == got, expect .. " == " .. got)
end

0 comments on commit ea2118a

Please sign in to comment.