candle 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.md +4 -0
  3. data/VERSION +1 -0
  4. data/bin/candle +21 -0
  5. data/lib/candle.rb +68 -0
  6. data/lib/candle/command.rb +27 -0
  7. data/lib/candle/generators/actions.rb +183 -0
  8. data/lib/candle/generators/blank.rb +127 -0
  9. data/lib/candle/generators/cli.rb +55 -0
  10. data/lib/candle/generators/help.rb +47 -0
  11. data/lib/candle/generators/jam.rb +80 -0
  12. data/lib/candle/generators/lua/scripts/AppDelegate.lua +36 -0
  13. data/lib/candle/generators/lua/scripts/tests/init.lua +6 -0
  14. data/lib/candle/generators/lua/scripts/tests/someTest.lua +12 -0
  15. data/lib/candle/generators/lua/wax/ProtocolLoader.h +12 -0
  16. data/lib/candle/generators/lua/wax/bin/hammer +157 -0
  17. data/lib/candle/generators/lua/wax/bin/update-xibs +131 -0
  18. data/lib/candle/generators/lua/wax/bin/waxsim +0 -0
  19. data/lib/candle/generators/lua/wax/lib/build-scripts/compile-stdlib.sh +14 -0
  20. data/lib/candle/generators/lua/wax/lib/build-scripts/copy-scripts.sh +58 -0
  21. data/lib/candle/generators/lua/wax/lib/build-scripts/luac.lua +80 -0
  22. data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.h +12 -0
  23. data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.m +85 -0
  24. data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.h +12 -0
  25. data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.m +251 -0
  26. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.h +14 -0
  27. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.m +240 -0
  28. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.h +54 -0
  29. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.m +304 -0
  30. data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.h +9 -0
  31. data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.m +273 -0
  32. data/lib/candle/generators/lua/wax/lib/extensions/json/Rakefile +10 -0
  33. data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.c +304 -0
  34. data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.h +11 -0
  35. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl-1.0.9.tar.gz +0 -0
  36. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_common.h +85 -0
  37. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_gen.h +159 -0
  38. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_parse.h +193 -0
  39. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl.c +159 -0
  40. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.c +65 -0
  41. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.h +50 -0
  42. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.c +119 -0
  43. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.h +73 -0
  44. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_bytestack.h +85 -0
  45. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_common.h +85 -0
  46. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.c +188 -0
  47. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.h +50 -0
  48. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.c +322 -0
  49. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.h +159 -0
  50. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.c +737 -0
  51. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.h +133 -0
  52. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parse.h +193 -0
  53. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.c +448 -0
  54. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.h +82 -0
  55. data/lib/candle/generators/lua/wax/lib/lua/lapi.c +1087 -0
  56. data/lib/candle/generators/lua/wax/lib/lua/lapi.h +16 -0
  57. data/lib/candle/generators/lua/wax/lib/lua/lauxlib.c +652 -0
  58. data/lib/candle/generators/lua/wax/lib/lua/lauxlib.h +174 -0
  59. data/lib/candle/generators/lua/wax/lib/lua/lbaselib.c +653 -0
  60. data/lib/candle/generators/lua/wax/lib/lua/lcode.c +839 -0
  61. data/lib/candle/generators/lua/wax/lib/lua/lcode.h +76 -0
  62. data/lib/candle/generators/lua/wax/lib/lua/ldblib.c +397 -0
  63. data/lib/candle/generators/lua/wax/lib/lua/ldebug.c +638 -0
  64. data/lib/candle/generators/lua/wax/lib/lua/ldebug.h +33 -0
  65. data/lib/candle/generators/lua/wax/lib/lua/ldo.c +518 -0
  66. data/lib/candle/generators/lua/wax/lib/lua/ldo.h +57 -0
  67. data/lib/candle/generators/lua/wax/lib/lua/ldump.c +164 -0
  68. data/lib/candle/generators/lua/wax/lib/lua/lfunc.c +174 -0
  69. data/lib/candle/generators/lua/wax/lib/lua/lfunc.h +34 -0
  70. data/lib/candle/generators/lua/wax/lib/lua/lgc.c +711 -0
  71. data/lib/candle/generators/lua/wax/lib/lua/lgc.h +110 -0
  72. data/lib/candle/generators/lua/wax/lib/lua/linit.c +38 -0
  73. data/lib/candle/generators/lua/wax/lib/lua/liolib.c +553 -0
  74. data/lib/candle/generators/lua/wax/lib/lua/llex.c +461 -0
  75. data/lib/candle/generators/lua/wax/lib/lua/llex.h +81 -0
  76. data/lib/candle/generators/lua/wax/lib/lua/llimits.h +128 -0
  77. data/lib/candle/generators/lua/wax/lib/lua/lmathlib.c +263 -0
  78. data/lib/candle/generators/lua/wax/lib/lua/lmem.c +86 -0
  79. data/lib/candle/generators/lua/wax/lib/lua/lmem.h +49 -0
  80. data/lib/candle/generators/lua/wax/lib/lua/loadlib.c +666 -0
  81. data/lib/candle/generators/lua/wax/lib/lua/lobject.c +214 -0
  82. data/lib/candle/generators/lua/wax/lib/lua/lobject.h +381 -0
  83. data/lib/candle/generators/lua/wax/lib/lua/lopcodes.c +102 -0
  84. data/lib/candle/generators/lua/wax/lib/lua/lopcodes.h +268 -0
  85. data/lib/candle/generators/lua/wax/lib/lua/loslib.c +243 -0
  86. data/lib/candle/generators/lua/wax/lib/lua/lparser.c +1339 -0
  87. data/lib/candle/generators/lua/wax/lib/lua/lparser.h +82 -0
  88. data/lib/candle/generators/lua/wax/lib/lua/lstate.c +214 -0
  89. data/lib/candle/generators/lua/wax/lib/lua/lstate.h +169 -0
  90. data/lib/candle/generators/lua/wax/lib/lua/lstring.c +111 -0
  91. data/lib/candle/generators/lua/wax/lib/lua/lstring.h +31 -0
  92. data/lib/candle/generators/lua/wax/lib/lua/lstrlib.c +869 -0
  93. data/lib/candle/generators/lua/wax/lib/lua/ltable.c +588 -0
  94. data/lib/candle/generators/lua/wax/lib/lua/ltable.h +40 -0
  95. data/lib/candle/generators/lua/wax/lib/lua/ltablib.c +287 -0
  96. data/lib/candle/generators/lua/wax/lib/lua/ltm.c +75 -0
  97. data/lib/candle/generators/lua/wax/lib/lua/ltm.h +54 -0
  98. data/lib/candle/generators/lua/wax/lib/lua/lua.h +388 -0
  99. data/lib/candle/generators/lua/wax/lib/lua/luaconf.h +753 -0
  100. data/lib/candle/generators/lua/wax/lib/lua/lualib.h +53 -0
  101. data/lib/candle/generators/lua/wax/lib/lua/lundump.c +227 -0
  102. data/lib/candle/generators/lua/wax/lib/lua/lundump.h +36 -0
  103. data/lib/candle/generators/lua/wax/lib/lua/lvm.c +763 -0
  104. data/lib/candle/generators/lua/wax/lib/lua/lvm.h +36 -0
  105. data/lib/candle/generators/lua/wax/lib/lua/lzio.c +82 -0
  106. data/lib/candle/generators/lua/wax/lib/lua/lzio.h +67 -0
  107. data/lib/candle/generators/lua/wax/lib/lua/print.c +227 -0
  108. data/lib/candle/generators/lua/wax/lib/project.rake +159 -0
  109. data/lib/candle/generators/lua/wax/lib/stdlib/enums.lua +396 -0
  110. data/lib/candle/generators/lua/wax/lib/stdlib/ext/http.lua +43 -0
  111. data/lib/candle/generators/lua/wax/lib/stdlib/ext/init.lua +4 -0
  112. data/lib/candle/generators/lua/wax/lib/stdlib/ext/number.lua +21 -0
  113. data/lib/candle/generators/lua/wax/lib/stdlib/ext/string.lua +97 -0
  114. data/lib/candle/generators/lua/wax/lib/stdlib/ext/table.lua +165 -0
  115. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/WaxServer.lua +49 -0
  116. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/autoload.lua +10 -0
  117. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/base64.lua +64 -0
  118. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/bit.lua +274 -0
  119. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/cache.lua +73 -0
  120. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/callback.lua +22 -0
  121. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/frame.lua +76 -0
  122. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/init.lua +78 -0
  123. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/pickView.lua +54 -0
  124. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/time.lua +102 -0
  125. data/lib/candle/generators/lua/wax/lib/stdlib/init.lua +18 -0
  126. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/init.lua +2 -0
  127. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luamock.lua +84 -0
  128. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luaspec.lua +377 -0
  129. data/lib/candle/generators/lua/wax/lib/stdlib/repl.lua +9 -0
  130. data/lib/candle/generators/lua/wax/lib/stdlib/structs.lua +11 -0
  131. data/lib/candle/generators/lua/wax/lib/stdlib/waxClass.lua +42 -0
  132. data/lib/candle/generators/lua/wax/lib/wax.h +16 -0
  133. data/lib/candle/generators/lua/wax/lib/wax.m +260 -0
  134. data/lib/candle/generators/lua/wax/lib/wax_class.h +18 -0
  135. data/lib/candle/generators/lua/wax/lib/wax_class.m +190 -0
  136. data/lib/candle/generators/lua/wax/lib/wax_gc.h +20 -0
  137. data/lib/candle/generators/lua/wax/lib/wax_gc.m +56 -0
  138. data/lib/candle/generators/lua/wax/lib/wax_helpers.h +102 -0
  139. data/lib/candle/generators/lua/wax/lib/wax_helpers.m +870 -0
  140. data/lib/candle/generators/lua/wax/lib/wax_instance.h +34 -0
  141. data/lib/candle/generators/lua/wax/lib/wax_instance.m +810 -0
  142. data/lib/candle/generators/lua/wax/lib/wax_server.h +47 -0
  143. data/lib/candle/generators/lua/wax/lib/wax_server.m +252 -0
  144. data/lib/candle/generators/lua/wax/lib/wax_stdlib.h +3 -0
  145. data/lib/candle/generators/lua/wax/lib/wax_struct.h +26 -0
  146. data/lib/candle/generators/lua/wax/lib/wax_struct.m +335 -0
  147. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.pbxproj +836 -0
  148. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  149. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  150. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/WaxApplication.xcscheme +86 -0
  151. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
  152. data/lib/candle/generators/templates/blank/WaxApplication/Default-568h@2x.png +0 -0
  153. data/lib/candle/generators/templates/blank/WaxApplication/Default.png +0 -0
  154. data/lib/candle/generators/templates/blank/WaxApplication/Default@2x.png +0 -0
  155. data/lib/candle/generators/templates/blank/WaxApplication/ProtocolLoader.h +12 -0
  156. data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Info.plist.tt +38 -0
  157. data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt +14 -0
  158. data/lib/candle/generators/templates/blank/WaxApplication/en.lproj/InfoPlist.strings +2 -0
  159. data/lib/candle/generators/templates/blank/WaxApplication/main.m.tt +20 -0
  160. data/lib/candle/tasks.rb +22 -0
  161. data/lib/candle/utility.rb +30 -0
  162. data/lib/candle/version.rb +9 -0
  163. data/lib/candle/view.rb +48 -0
  164. metadata +582 -0
@@ -0,0 +1,11 @@
1
+ #ifndef json_h
2
+ #define json_h
3
+
4
+ #import "lua.h"
5
+
6
+ #define JSON_METATABLE_NAME "wax.json"
7
+
8
+ int luaopen_wax_json(lua_State *L);
9
+ void json_parseString(lua_State *L, const char *input);
10
+
11
+ #endif
@@ -0,0 +1,85 @@
1
+ /*
2
+ * Copyright 2007-2009, Lloyd Hilaiel.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are
6
+ * met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
17
+ * contributors may be used to endorse or promote products derived
18
+ * from this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ * POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ #ifndef __YAJL_COMMON_H__
34
+ #define __YAJL_COMMON_H__
35
+
36
+ #ifdef __cplusplus
37
+ extern "C" {
38
+ #endif
39
+
40
+ #define YAJL_MAX_DEPTH 128
41
+
42
+ /* msft dll export gunk. To build a DLL on windows, you
43
+ * must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared
44
+ * DLL, you must define YAJL_SHARED and WIN32 */
45
+ #if defined(WIN32) && defined(YAJL_SHARED)
46
+ # ifdef YAJL_BUILD
47
+ # define YAJL_API __declspec(dllexport)
48
+ # else
49
+ # define YAJL_API __declspec(dllimport)
50
+ # endif
51
+ #else
52
+ # define YAJL_API
53
+ #endif
54
+
55
+ /** pointer to a malloc function, supporting client overriding memory
56
+ * allocation routines */
57
+ typedef void * (*yajl_malloc_func)(void *ctx, unsigned int sz);
58
+
59
+ /** pointer to a free function, supporting client overriding memory
60
+ * allocation routines */
61
+ typedef void (*yajl_free_func)(void *ctx, void * ptr);
62
+
63
+ /** pointer to a realloc function which can resize an allocation. */
64
+ typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, unsigned int sz);
65
+
66
+ /** A structure which can be passed to yajl_*_alloc routines to allow the
67
+ * client to specify memory allocation functions to be used. */
68
+ typedef struct
69
+ {
70
+ /** pointer to a function that can allocate uninitialized memory */
71
+ yajl_malloc_func malloc;
72
+ /** pointer to a function that can resize memory allocations */
73
+ yajl_realloc_func realloc;
74
+ /** pointer to a function that can free memory allocated using
75
+ * reallocFunction or mallocFunction */
76
+ yajl_free_func free;
77
+ /** a context pointer that will be passed to above allocation routines */
78
+ void * ctx;
79
+ } yajl_alloc_funcs;
80
+
81
+ #ifdef __cplusplus
82
+ }
83
+ #endif
84
+
85
+ #endif
@@ -0,0 +1,159 @@
1
+ /*
2
+ * Copyright 2007-2009, Lloyd Hilaiel.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are
6
+ * met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
17
+ * contributors may be used to endorse or promote products derived
18
+ * from this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ * POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ /**
34
+ * \file yajl_gen.h
35
+ * Interface to YAJL's JSON generation facilities.
36
+ */
37
+
38
+ #include "yajl_common.h"
39
+
40
+ #ifndef __YAJL_GEN_H__
41
+ #define __YAJL_GEN_H__
42
+
43
+ #ifdef __cplusplus
44
+ extern "C" {
45
+ #endif
46
+ /** generator status codes */
47
+ typedef enum {
48
+ /** no error */
49
+ yajl_gen_status_ok = 0,
50
+ /** at a point where a map key is generated, a function other than
51
+ * yajl_gen_string was called */
52
+ yajl_gen_keys_must_be_strings,
53
+ /** YAJL's maximum generation depth was exceeded. see
54
+ * YAJL_MAX_DEPTH */
55
+ yajl_max_depth_exceeded,
56
+ /** A generator function (yajl_gen_XXX) was called while in an error
57
+ * state */
58
+ yajl_gen_in_error_state,
59
+ /** A complete JSON document has been generated */
60
+ yajl_gen_generation_complete,
61
+ /** yajl_gen_double was passed an invalid floating point value
62
+ * (infinity or NaN). */
63
+ yajl_gen_invalid_number,
64
+ /** A print callback was passed in, so there is no internal
65
+ * buffer to get from */
66
+ yajl_gen_no_buf
67
+ } yajl_gen_status;
68
+
69
+ /** an opaque handle to a generator */
70
+ typedef struct yajl_gen_t * yajl_gen;
71
+
72
+ /** a callback used for "printing" the results. */
73
+ typedef void (*yajl_print_t)(void * ctx,
74
+ const char * str,
75
+ unsigned int len);
76
+
77
+ /** configuration structure for the generator */
78
+ typedef struct {
79
+ /** generate indented (beautiful) output */
80
+ unsigned int beautify;
81
+ /** an opportunity to define an indent string. such as \\t or
82
+ * some number of spaces. default is four spaces ' '. This
83
+ * member is only relevant when beautify is true */
84
+ const char * indentString;
85
+ } yajl_gen_config;
86
+
87
+ /** allocate a generator handle
88
+ * \param config a pointer to a structure containing parameters which
89
+ * configure the behavior of the json generator
90
+ * \param allocFuncs an optional pointer to a structure which allows
91
+ * the client to overide the memory allocation
92
+ * used by yajl. May be NULL, in which case
93
+ * malloc/free/realloc will be used.
94
+ *
95
+ * \returns an allocated handle on success, NULL on failure (bad params)
96
+ */
97
+ YAJL_API yajl_gen yajl_gen_alloc(const yajl_gen_config * config,
98
+ const yajl_alloc_funcs * allocFuncs);
99
+
100
+ /** allocate a generator handle that will print to the specified
101
+ * callback rather than storing the results in an internal buffer.
102
+ * \param callback a pointer to a printer function. May be NULL
103
+ * in which case, the results will be store in an
104
+ * internal buffer.
105
+ * \param config a pointer to a structure containing parameters
106
+ * which configure the behavior of the json
107
+ * generator.
108
+ * \param allocFuncs an optional pointer to a structure which allows
109
+ * the client to overide the memory allocation
110
+ * used by yajl. May be NULL, in which case
111
+ * malloc/free/realloc will be used.
112
+ * \param ctx a context pointer that will be passed to the
113
+ * printer callback.
114
+ *
115
+ * \returns an allocated handle on success, NULL on failure (bad params)
116
+ */
117
+ YAJL_API yajl_gen yajl_gen_alloc2(const yajl_print_t callback,
118
+ const yajl_gen_config * config,
119
+ const yajl_alloc_funcs * allocFuncs,
120
+ void * ctx);
121
+
122
+ /** free a generator handle */
123
+ YAJL_API void yajl_gen_free(yajl_gen handle);
124
+
125
+ YAJL_API yajl_gen_status yajl_gen_integer(yajl_gen hand, long int number);
126
+ /** generate a floating point number. number may not be infinity or
127
+ * NaN, as these have no representation in JSON. In these cases the
128
+ * generator will return 'yajl_gen_invalid_number' */
129
+ YAJL_API yajl_gen_status yajl_gen_double(yajl_gen hand, double number);
130
+ YAJL_API yajl_gen_status yajl_gen_number(yajl_gen hand,
131
+ const char * num,
132
+ unsigned int len);
133
+ YAJL_API yajl_gen_status yajl_gen_string(yajl_gen hand,
134
+ const unsigned char * str,
135
+ unsigned int len);
136
+ YAJL_API yajl_gen_status yajl_gen_null(yajl_gen hand);
137
+ YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean);
138
+ YAJL_API yajl_gen_status yajl_gen_map_open(yajl_gen hand);
139
+ YAJL_API yajl_gen_status yajl_gen_map_close(yajl_gen hand);
140
+ YAJL_API yajl_gen_status yajl_gen_array_open(yajl_gen hand);
141
+ YAJL_API yajl_gen_status yajl_gen_array_close(yajl_gen hand);
142
+
143
+ /** access the null terminated generator buffer. If incrementally
144
+ * outputing JSON, one should call yajl_gen_clear to clear the
145
+ * buffer. This allows stream generation. */
146
+ YAJL_API yajl_gen_status yajl_gen_get_buf(yajl_gen hand,
147
+ const unsigned char ** buf,
148
+ unsigned int * len);
149
+
150
+ /** clear yajl's output buffer, but maintain all internal generation
151
+ * state. This function will not "reset" the generator state, and is
152
+ * intended to enable incremental JSON outputing. */
153
+ YAJL_API void yajl_gen_clear(yajl_gen hand);
154
+
155
+ #ifdef __cplusplus
156
+ }
157
+ #endif
158
+
159
+ #endif
@@ -0,0 +1,193 @@
1
+ /*
2
+ * Copyright 2007-2009, Lloyd Hilaiel.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions are
6
+ * met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
17
+ * contributors may be used to endorse or promote products derived
18
+ * from this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ * POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ /**
34
+ * \file yajl_parse.h
35
+ * Interface to YAJL's JSON parsing facilities.
36
+ */
37
+
38
+ #include "yajl_common.h"
39
+
40
+ #ifndef __YAJL_PARSE_H__
41
+ #define __YAJL_PARSE_H__
42
+
43
+ #ifdef __cplusplus
44
+ extern "C" {
45
+ #endif
46
+ /** error codes returned from this interface */
47
+ typedef enum {
48
+ /** no error was encountered */
49
+ yajl_status_ok,
50
+ /** a client callback returned zero, stopping the parse */
51
+ yajl_status_client_canceled,
52
+ /** The parse cannot yet complete because more json input text
53
+ * is required, call yajl_parse with the next buffer of input text.
54
+ * (pertinent only when stream parsing) */
55
+ yajl_status_insufficient_data,
56
+ /** An error occured during the parse. Call yajl_get_error for
57
+ * more information about the encountered error */
58
+ yajl_status_error
59
+ } yajl_status;
60
+
61
+ /** attain a human readable, english, string for an error */
62
+ YAJL_API const char * yajl_status_to_string(yajl_status code);
63
+
64
+ /** an opaque handle to a parser */
65
+ typedef struct yajl_handle_t * yajl_handle;
66
+
67
+ /** yajl is an event driven parser. this means as json elements are
68
+ * parsed, you are called back to do something with the data. The
69
+ * functions in this table indicate the various events for which
70
+ * you will be called back. Each callback accepts a "context"
71
+ * pointer, this is a void * that is passed into the yajl_parse
72
+ * function which the client code may use to pass around context.
73
+ *
74
+ * All callbacks return an integer. If non-zero, the parse will
75
+ * continue. If zero, the parse will be canceled and
76
+ * yajl_status_client_canceled will be returned from the parse.
77
+ *
78
+ * Note about handling of numbers:
79
+ * yajl will only convert numbers that can be represented in a double
80
+ * or a long int. All other numbers will be passed to the client
81
+ * in string form using the yajl_number callback. Furthermore, if
82
+ * yajl_number is not NULL, it will always be used to return numbers,
83
+ * that is yajl_integer and yajl_double will be ignored. If
84
+ * yajl_number is NULL but one of yajl_integer or yajl_double are
85
+ * defined, parsing of a number larger than is representable
86
+ * in a double or long int will result in a parse error.
87
+ */
88
+ typedef struct {
89
+ int (* yajl_null)(void * ctx);
90
+ int (* yajl_boolean)(void * ctx, int boolVal);
91
+ int (* yajl_integer)(void * ctx, long integerVal);
92
+ int (* yajl_double)(void * ctx, double doubleVal);
93
+ /** A callback which passes the string representation of the number
94
+ * back to the client. Will be used for all numbers when present */
95
+ int (* yajl_number)(void * ctx, const char * numberVal,
96
+ unsigned int numberLen);
97
+
98
+ /** strings are returned as pointers into the JSON text when,
99
+ * possible, as a result, they are _not_ null padded */
100
+ int (* yajl_string)(void * ctx, const unsigned char * stringVal,
101
+ unsigned int stringLen);
102
+
103
+ int (* yajl_start_map)(void * ctx);
104
+ int (* yajl_map_key)(void * ctx, const unsigned char * key,
105
+ unsigned int stringLen);
106
+ int (* yajl_end_map)(void * ctx);
107
+
108
+ int (* yajl_start_array)(void * ctx);
109
+ int (* yajl_end_array)(void * ctx);
110
+ } yajl_callbacks;
111
+
112
+ /** configuration structure for the generator */
113
+ typedef struct {
114
+ /** if nonzero, javascript style comments will be allowed in
115
+ * the json input, both slash star and slash slash */
116
+ unsigned int allowComments;
117
+ /** if nonzero, invalid UTF8 strings will cause a parse
118
+ * error */
119
+ unsigned int checkUTF8;
120
+ } yajl_parser_config;
121
+
122
+ /** allocate a parser handle
123
+ * \param callbacks a yajl callbacks structure specifying the
124
+ * functions to call when different JSON entities
125
+ * are encountered in the input text. May be NULL,
126
+ * which is only useful for validation.
127
+ * \param config configuration parameters for the parse.
128
+ * \param ctx a context pointer that will be passed to callbacks.
129
+ */
130
+ YAJL_API yajl_handle yajl_alloc(const yajl_callbacks * callbacks,
131
+ const yajl_parser_config * config,
132
+ const yajl_alloc_funcs * allocFuncs,
133
+ void * ctx);
134
+
135
+ /** free a parser handle */
136
+ YAJL_API void yajl_free(yajl_handle handle);
137
+
138
+ /** Parse some json!
139
+ * \param hand - a handle to the json parser allocated with yajl_alloc
140
+ * \param jsonText - a pointer to the UTF8 json text to be parsed
141
+ * \param jsonTextLength - the length, in bytes, of input text
142
+ */
143
+ YAJL_API yajl_status yajl_parse(yajl_handle hand,
144
+ const unsigned char * jsonText,
145
+ unsigned int jsonTextLength);
146
+
147
+ /** Parse any remaining buffered json.
148
+ * Since yajl is a stream-based parser, without an explicit end of
149
+ * input, yajl sometimes can't decide if content at the end of the
150
+ * stream is valid or not. For example, if "1" has been fed in,
151
+ * yajl can't know whether another digit is next or some character
152
+ * that would terminate the integer token.
153
+ *
154
+ * \param hand - a handle to the json parser allocated with yajl_alloc
155
+ */
156
+ YAJL_API yajl_status yajl_parse_complete(yajl_handle hand);
157
+
158
+ /** get an error string describing the state of the
159
+ * parse.
160
+ *
161
+ * If verbose is non-zero, the message will include the JSON
162
+ * text where the error occured, along with an arrow pointing to
163
+ * the specific char.
164
+ *
165
+ * \returns A dynamically allocated string will be returned which should
166
+ * be freed with yajl_free_error
167
+ */
168
+ YAJL_API unsigned char * yajl_get_error(yajl_handle hand, int verbose,
169
+ const unsigned char * jsonText,
170
+ unsigned int jsonTextLength);
171
+
172
+ /**
173
+ * get the amount of data consumed from the last chunk passed to YAJL.
174
+ *
175
+ * In the case of a successful parse this can help you understand if
176
+ * the entire buffer was consumed (which will allow you to handle
177
+ * "junk at end of input".
178
+ *
179
+ * In the event an error is encountered during parsing, this function
180
+ * affords the client a way to get the offset into the most recent
181
+ * chunk where the error occured. 0 will be returned if no error
182
+ * was encountered.
183
+ */
184
+ YAJL_API unsigned int yajl_get_bytes_consumed(yajl_handle hand);
185
+
186
+ /** free an error returned from yajl_get_error */
187
+ YAJL_API void yajl_free_error(yajl_handle hand, unsigned char * str);
188
+
189
+ #ifdef __cplusplus
190
+ }
191
+ #endif
192
+
193
+ #endif