candle 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,377 @@
1
+ spec = {
2
+ contexts = {}, passed = 0, failed = 0, pending = 0, current = nil
3
+ }
4
+
5
+ Report = {}
6
+ Report.__index = Report
7
+
8
+ function Report:new(spec)
9
+ local report = {
10
+ num_passed = spec.passed,
11
+ num_failed = spec.failed,
12
+ num_pending = spec.pending,
13
+ total = spec.passed + spec.failed + spec.pending,
14
+ results = {}
15
+ }
16
+
17
+ report.percent = report.num_passed/report.total*100
18
+
19
+ local contexts = spec.contexts
20
+
21
+ for index = 1, #contexts do
22
+ report.results[index] = {
23
+ name = contexts[index],
24
+ spec_results = contexts[contexts[index]]
25
+ }
26
+ end
27
+
28
+ return report
29
+ end
30
+
31
+ function spec:report(verbose)
32
+ local report = Report:new(self)
33
+
34
+ if report.num_failed ~= 0 or verbose then
35
+ for i, result in pairs(report.results) do
36
+ print(("\n%s\n================================"):format(result.name))
37
+
38
+ for description, r in pairs(result.spec_results) do
39
+ local outcome = r.passed and 'pass' or "FAILED"
40
+
41
+ if verbose or not (verbose and r.passed) then
42
+ print(("%-70s [ %s ]"):format(" - " .. description, outcome))
43
+
44
+ table.foreach(r.errors, function(index, error)
45
+ print(" " .. index ..". Failed expectation : " .. error.message .. "\n "..error.trace)
46
+ end)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ local summary = [[
53
+
54
+ ========== %s =============
55
+ %s Failed
56
+ %s Passed
57
+ --------------------------------
58
+ %s Run, %.2f%% Success rate
59
+ ]]
60
+
61
+ print(summary:format(report.num_failed == 0 and "Success" or "Failure", report.num_failed, report.num_passed, report.total, report.percent))
62
+ end
63
+
64
+ function spec:add_results(success, message, trace)
65
+ if self.current.passed then
66
+ self.current.passed = success
67
+ end
68
+
69
+ if success then
70
+ self.passed = self.passed + 1
71
+ else
72
+ table.insert(self.current.errors, { message = message, trace = trace })
73
+ self.failed = self.failed + 1
74
+ end
75
+ end
76
+
77
+ function spec:add_context(name)
78
+ self.contexts[#self.contexts+1] = name
79
+ self.contexts[name] = {}
80
+ end
81
+
82
+ function spec:add_spec(context_name, spec_name)
83
+ local context = self.contexts[context_name]
84
+ context[spec_name] = { passed = true, errors = {} }
85
+ self.current = context[spec_name]
86
+ end
87
+
88
+ function spec:add_pending_spec(context_name, spec_name, pending_description)
89
+ end
90
+
91
+ -- create tables to support pending specifications
92
+ local pending = {}
93
+
94
+ function pending.__newindex() error("You can't set properties on pending") end
95
+
96
+ function pending.__index(_, key)
97
+ if key == "description" then
98
+ return nil
99
+ else
100
+ error("You can't get properties on pending")
101
+ end
102
+ end
103
+
104
+ function pending.__call(_, description)
105
+ local o = { description = description}
106
+ setmetatable(o, pending)
107
+ return o
108
+ end
109
+
110
+ setmetatable(pending, pending)
111
+
112
+ --
113
+
114
+ -- define matchers
115
+
116
+ matchers = {
117
+ should_be = function(value, expected)
118
+ if value ~= expected then
119
+ return false, "expecting "..tostring(expected)..", not ".. tostring(value)
120
+ end
121
+ return true
122
+ end;
123
+
124
+ should_not_be = function(value, expected)
125
+ if value == expected then
126
+ return false, "should not be "..tostring(value)
127
+ end
128
+ return true
129
+ end;
130
+
131
+ should_be_greater_than = function(value, expected)
132
+ if expected >= value then
133
+ return false, "got " .. tostring(value) .. " expecting value > " .. tostring(expected)
134
+ end
135
+ return true
136
+ end;
137
+
138
+ should_be_less_than = function(value, expected)
139
+ if expected <= value then
140
+ return false, "got " .. tostring(value) .. " expecting value < " .. tostring(expected)
141
+ end
142
+ return true
143
+ end;
144
+
145
+ should_error = function(f)
146
+ if pcall(f) then
147
+ return false, "expecting an error but received none"
148
+ end
149
+ return true
150
+ end;
151
+
152
+ should_match = function(value, pattern)
153
+ if type(value) ~= 'string' then
154
+ return false, "type error, should_match expecting target as string"
155
+ end
156
+
157
+ if not string.match(value, pattern) then
158
+ return false, value .. "doesn't match pattern ".. pattern
159
+ end
160
+ return true
161
+ end;
162
+
163
+ should_be_kind_of = function(value, class)
164
+ if type(value) == "userdata" then
165
+
166
+ if not value:isKindOfClass(class) then
167
+ return false, tostring(value) .. " is not a " .. tostring(class)
168
+ end
169
+ elseif type(value) ~= class then
170
+ return false, type(value) .. " is not a " .. tostring(class)
171
+ end
172
+
173
+ return true
174
+ end;
175
+
176
+ should_exist = function(value)
177
+ if not value then
178
+ return false, tostring(value) .. " evaluates to false."
179
+ else
180
+ return true
181
+ end
182
+ end;
183
+
184
+ should_not_exist = function(value)
185
+ if value then
186
+ return false, value .. " evaluates to true."
187
+ else
188
+ return true
189
+ end
190
+ end;
191
+ }
192
+
193
+ matchers.should_equal = matchers.should_be
194
+
195
+ --
196
+
197
+ -- expect returns an empty table with a 'method missing' metatable
198
+ -- which looks up the matcher. The 'method missing' function
199
+ -- runs the matcher and records the result in the current spec
200
+ local function expect(target)
201
+ return setmetatable({}, {
202
+ __index = function(_, matcher)
203
+ return function(...)
204
+ local success, message = matchers[matcher](target, ...)
205
+ spec:add_results(success, message, debug.traceback())
206
+ end
207
+ end
208
+ })
209
+ end
210
+
211
+
212
+ --
213
+
214
+ Context = {}
215
+ Context.__index = Context
216
+
217
+ function Context:new(context)
218
+ for i, child in ipairs(context.children) do
219
+ child.parent = context
220
+ end
221
+ return setmetatable(context, self)
222
+ end
223
+
224
+ function Context:run_befores(env)
225
+ if self.parent then
226
+ self.parent:run_befores(env)
227
+ end
228
+ if self.before then
229
+ setfenv(self.before, env)
230
+ self.before()
231
+ end
232
+ end
233
+
234
+ function Context:run_afters(env)
235
+ if self.after then
236
+ setfenv(self.after, env)
237
+ self.after()
238
+ end
239
+ if self.parent then
240
+ self.parent:run_afters(env)
241
+ end
242
+ end
243
+
244
+ function Context:run()
245
+ -- run all specs
246
+ for spec_name, spec_func in pairs(self.specs) do
247
+ if getmetatable(spec_func) == pending then
248
+ else
249
+ spec:add_spec(self.name, spec_name)
250
+
251
+ local mocks = {}
252
+
253
+ -- setup the environment that the spec is run in, each spec is run in a new environment
254
+ local env = {
255
+ track_error = function(f)
256
+ local status, err = pcall(f)
257
+ return err
258
+ end,
259
+
260
+ expect = expect,
261
+
262
+ mock = function(table, key, mock_value)
263
+ mocks[{ table = table, key = key }] = table[key] -- store the old value
264
+ table[key] = mock_value or Mock:new()
265
+ return table[key]
266
+ end
267
+ }
268
+ setmetatable(env, { __index = _G })
269
+
270
+ -- run each spec with proper befores and afters
271
+ self:run_befores(env)
272
+
273
+ setfenv(spec_func, env)
274
+ local message
275
+ local traceback
276
+ local success = xpcall(spec_func, function(err)
277
+ message = err
278
+ traceback = debug.traceback("", 2)
279
+ end)
280
+
281
+ self:run_afters(env)
282
+
283
+ if not success then
284
+ io.write("x")
285
+ spec:add_results(false, message, traceback)
286
+ else
287
+ io.write(".")
288
+ end
289
+ io.flush()
290
+
291
+ -- restore stored values for mocks
292
+ for key, old_value in pairs(mocks) do
293
+ key.table[key.key] = old_value
294
+ end
295
+ end
296
+ end
297
+
298
+ for i, child in pairs(self.children) do
299
+ child:run()
300
+ end
301
+ end
302
+
303
+ -- dsl for creating contexts
304
+
305
+ local function make_it_table()
306
+ -- create and set metatables for 'it'
307
+ local specs = {}
308
+ local it = {}
309
+ setmetatable(it, {
310
+ -- this is called when it is assigned a function (e.g. it["spec name"] = function() ...)
311
+ __newindex = function(_, spec_name, spec_function)
312
+ specs[spec_name] = spec_function
313
+ end
314
+ })
315
+
316
+ return it, specs
317
+ end
318
+
319
+ local make_describe_table
320
+
321
+ -- create an environment to run a context function in as well as the tables to collect
322
+ -- the subcontexts and specs
323
+ local function create_context_env()
324
+ local it, specs = make_it_table()
325
+ local describe, sub_contexts = make_describe_table()
326
+
327
+ -- create an environment to run the function in
328
+ local context_env = {
329
+ it = it,
330
+ describe = describe,
331
+ pending = pending
332
+ }
333
+
334
+ return context_env, sub_contexts, specs
335
+ end
336
+
337
+ -- Note: this is declared locally earlier so it is still local
338
+ function make_describe_table(auto_run)
339
+ local describe = {}
340
+ local contexts = {}
341
+ local describe_mt = {
342
+
343
+ -- This function is called when a function is assigned to a describe table
344
+ -- (e.g. describe["context name"] = function() ...)
345
+ __newindex = function(_, context_name, context_function)
346
+
347
+ spec:add_context(context_name)
348
+
349
+ local context_env, sub_contexts, specs = create_context_env()
350
+
351
+ -- set the environment
352
+ setfenv(context_function, context_env)
353
+
354
+ -- run the context function which collects the data into context_env and sub_contexts
355
+ context_function()
356
+
357
+ -- store the describe function in contexts
358
+ contexts[#contexts+1] = Context:new {
359
+ name = context_name,
360
+ before = context_env.before,
361
+ after = context_env.after,
362
+ specs = specs,
363
+ children = sub_contexts
364
+ }
365
+
366
+ if auto_run then
367
+ contexts[#contexts]:run()
368
+ end
369
+ end
370
+ }
371
+
372
+ setmetatable(describe, describe_mt)
373
+
374
+ return describe, contexts
375
+ end
376
+
377
+ describe = make_describe_table(true)
@@ -0,0 +1,9 @@
1
+ local input
2
+
3
+ repeat
4
+ io.write("wax> ")
5
+ input = io.read()
6
+ local success, e = wax.eval(input)
7
+
8
+ if not success then print("Error: " .. e) end
9
+ until not input
@@ -0,0 +1,11 @@
1
+ wax.struct.create("CGSize", "ff", "width", "height")
2
+ wax.struct.create("CGPoint", "ff", "x", "y")
3
+ wax.struct.create("UIEdgeInsets", "ffff", "top", "left", "bottom", "right")
4
+ wax.struct.create("CGRect", "ffff", "x", "y", "width", "height")
5
+
6
+ wax.struct.create("NSRange", "II", "location", "length")
7
+
8
+ wax.struct.create("CLLocationCoordinate2D", "dd", "latitude", "longitude")
9
+ wax.struct.create("MKCoordinateSpan", "dd", "latitudeDelta", "longitudeDelta")
10
+ wax.struct.create("MKCoordinateRegion", "dddd", "latitude", "longitude", "latitudeDelta", "longitudeDelta")
11
+ wax.struct.create("CGAffineTransform", "ffffff", "a", "b", "c", "d", "tx", "ty")
@@ -0,0 +1,42 @@
1
+ function waxClass(options)
2
+ local class = waxInlineClass(options)
3
+ setfenv(2, class._M)
4
+ return class
5
+ end
6
+
7
+ -- So you can create a class without screwing with the function environment
8
+ function waxInlineClass(options)
9
+ local className = options[1]
10
+ local superclassName = options[2]
11
+ local class = wax.class(className, superclassName)
12
+ class.className = className
13
+
14
+ if options.protocols then
15
+ if type(options.protocols) ~= "table" then options.protocols = {options.protocols} end
16
+ if #options.protocols == 0 then error("\nEmpty protocol table for class " .. className .. ".\n Make sure you are defining your protocols with a string and not a variable. \n ex. protocols = {\"UITableViewDelegate\"}\n\n") end
17
+ end
18
+
19
+ for i, protocol in ipairs(options.protocols or {}) do
20
+ wax.class.addProtocols(class, protocol)
21
+ end
22
+
23
+ class._M = setmetatable({
24
+ self = class,
25
+ },
26
+ {
27
+ __newindex = function(self, key, value)
28
+ class[key] = value
29
+ end,
30
+
31
+ __index = function(self, key)
32
+ return class[key] or _G[key]
33
+ end,
34
+
35
+ }
36
+ )
37
+
38
+ _G[className] = class
39
+ package.loaded[className] = class
40
+
41
+ return class
42
+ end
@@ -0,0 +1,16 @@
1
+ // Created by ProbablyInteractive.
2
+ // Copyright 2009 Probably Interactive. All rights reserved.
3
+
4
+ #import <Foundation/Foundation.h>
5
+ #import "lua.h"
6
+
7
+ #define WAX_VERSION 0.93
8
+
9
+ void wax_setup();
10
+ void wax_start(char *initScript, lua_CFunction extensionFunctions, ...);
11
+ void wax_startWithServer();
12
+ void wax_end();
13
+
14
+ lua_State *wax_currentLuaState();
15
+
16
+ void luaopen_wax(lua_State *L);