Permalink
Browse files

Implement yajl.to_value() in C, add some more tests, improve the

documentation, and fix some bugs.

 * Check for "not ok" output which now results in test failures.

 * Make yajl.null a full user data so that in string context it will
   be the string "null".

 * yajl.parser():value(value, type) type parameter was always
   "integer" for numerical values.  Instead, it is now always
   "number" to better express the type of the value.

 * coerce object keys into strings before calling js_generator_string
   so as to avoid getting an error about a non-string argument.

 * yajl.generator() simply did not work since the meta-table __index
   meta method was not set, so we now set that meta-method.

 * yajl.generator() had an off by one bug that would cause it to error
   when passed a printer argument.
  • Loading branch information...
1 parent aa96ce4 commit 28f9b649a37c3bfd7cdac463084dc474916ab0ce @brimworks committed Apr 4, 2010
Showing with 310 additions and 72 deletions.
  1. +4 −0 CMakeLists.txt
  2. +8 −8 README
  3. +244 −62 lua_yajl.c
  4. +54 −2 test.lua
View
@@ -38,6 +38,10 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
INCLUDE(CTest)
FIND_PROGRAM(LUA NAMES lua lua.bat)
ADD_TEST(basic ${LUA} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua ${CMAKE_CURRENT_SOURCE_DIR}/ ${CMAKE_CURRENT_BINARY_DIR}/)
+ SET_TESTS_PROPERTIES(basic
+ PROPERTIES
+ FAIL_REGULAR_EXPRESSION
+ "not ok")
# / test yajl.so
# Where to install stuff
View
@@ -65,14 +65,15 @@ string = yajl.to_string(lua_obj)
Translate a lua object into a JSON representation by creating a
generator and calling the 'value' method with the passed in
- lua_obj and returns the result.
+ lua_obj and returns the result. See generator:value() for more
+ information about this operation. Note that information loss
+ may happen in certain situations. For example, empty tables are
+ always translated into empty arrays.
+lua_obj = yajl.to_value(string)
-TODO: lua_obj = yajl.to_value(string)
-
- >>VAPORWARE<<
-
- Simple interface that simply executes this code:
+ Translate a string to a lua object. This is done in C by running
+ code that is essentially the same as this (but faster):
function to_value(string)
local result
@@ -146,8 +147,7 @@ parser = yajl.parser {
"string" - A JSON string was found.
"boolean" - A JSON true or false was found.
- "integer" - A JSON integer was found.
- "double" - A JSON double was found.
+ "number" - A JSON number was found.
"null" - A JSON null was found.
Note that nulls are NOT represented as a Lua nil value,
Oops, something went wrong.

0 comments on commit 28f9b64

Please sign in to comment.