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.
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/VERSION +1 -0
- data/bin/candle +21 -0
- data/lib/candle.rb +68 -0
- data/lib/candle/command.rb +27 -0
- data/lib/candle/generators/actions.rb +183 -0
- data/lib/candle/generators/blank.rb +127 -0
- data/lib/candle/generators/cli.rb +55 -0
- data/lib/candle/generators/help.rb +47 -0
- data/lib/candle/generators/jam.rb +80 -0
- data/lib/candle/generators/lua/scripts/AppDelegate.lua +36 -0
- data/lib/candle/generators/lua/scripts/tests/init.lua +6 -0
- data/lib/candle/generators/lua/scripts/tests/someTest.lua +12 -0
- data/lib/candle/generators/lua/wax/ProtocolLoader.h +12 -0
- data/lib/candle/generators/lua/wax/bin/hammer +157 -0
- data/lib/candle/generators/lua/wax/bin/update-xibs +131 -0
- data/lib/candle/generators/lua/wax/bin/waxsim +0 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/compile-stdlib.sh +14 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/copy-scripts.sh +58 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/luac.lua +80 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.m +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.m +251 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.h +14 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.m +240 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.h +54 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.m +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.h +9 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.m +273 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/Rakefile +10 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.c +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.h +11 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl-1.0.9.tar.gz +0 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl.c +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.c +65 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.c +119 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.h +73 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_bytestack.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.c +188 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.c +322 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.c +737 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.h +133 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.c +448 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.c +1087 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.h +16 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.c +652 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.h +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lbaselib.c +653 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.c +839 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.h +76 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldblib.c +397 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.c +638 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.h +33 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.c +518 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.h +57 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldump.c +164 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.c +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.h +34 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.c +711 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.h +110 -0
- data/lib/candle/generators/lua/wax/lib/lua/linit.c +38 -0
- data/lib/candle/generators/lua/wax/lib/lua/liolib.c +553 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.c +461 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.h +81 -0
- data/lib/candle/generators/lua/wax/lib/lua/llimits.h +128 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmathlib.c +263 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.c +86 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.h +49 -0
- data/lib/candle/generators/lua/wax/lib/lua/loadlib.c +666 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.h +381 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.c +102 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.h +268 -0
- data/lib/candle/generators/lua/wax/lib/lua/loslib.c +243 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.c +1339 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.h +169 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.c +111 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.h +31 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstrlib.c +869 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.c +588 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.h +40 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltablib.c +287 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.c +75 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.h +54 -0
- data/lib/candle/generators/lua/wax/lib/lua/lua.h +388 -0
- data/lib/candle/generators/lua/wax/lib/lua/luaconf.h +753 -0
- data/lib/candle/generators/lua/wax/lib/lua/lualib.h +53 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.c +227 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.c +763 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.c +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.h +67 -0
- data/lib/candle/generators/lua/wax/lib/lua/print.c +227 -0
- data/lib/candle/generators/lua/wax/lib/project.rake +159 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/enums.lua +396 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/http.lua +43 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/init.lua +4 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/number.lua +21 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/string.lua +97 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/table.lua +165 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/WaxServer.lua +49 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/autoload.lua +10 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/base64.lua +64 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/bit.lua +274 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/cache.lua +73 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/callback.lua +22 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/frame.lua +76 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/init.lua +78 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/pickView.lua +54 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/time.lua +102 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/init.lua +18 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/init.lua +2 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luamock.lua +84 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luaspec.lua +377 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/repl.lua +9 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/structs.lua +11 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/waxClass.lua +42 -0
- data/lib/candle/generators/lua/wax/lib/wax.h +16 -0
- data/lib/candle/generators/lua/wax/lib/wax.m +260 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.h +18 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.m +190 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.h +20 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.m +56 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.h +102 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.m +870 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.h +34 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.m +810 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.h +47 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.m +252 -0
- data/lib/candle/generators/lua/wax/lib/wax_stdlib.h +3 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.h +26 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.m +335 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.pbxproj +836 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/WaxApplication.xcscheme +86 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default-568h@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/ProtocolLoader.h +12 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Info.plist.tt +38 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt +14 -0
- data/lib/candle/generators/templates/blank/WaxApplication/en.lproj/InfoPlist.strings +2 -0
- data/lib/candle/generators/templates/blank/WaxApplication/main.m.tt +20 -0
- data/lib/candle/tasks.rb +22 -0
- data/lib/candle/utility.rb +30 -0
- data/lib/candle/version.rb +9 -0
- data/lib/candle/view.rb +48 -0
- metadata +582 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
wax.cache = {}
|
|
2
|
+
setmetatable(wax.cache, wax.cache)
|
|
3
|
+
|
|
4
|
+
-- Returns contents of cache keys
|
|
5
|
+
-- key: string # value for cache
|
|
6
|
+
-- maxAge: number (optional) # max age of file in seconds
|
|
7
|
+
function wax.cache.get(key, maxAge)
|
|
8
|
+
local path = wax.cache.pathFor(key)
|
|
9
|
+
|
|
10
|
+
if not wax.filesystem.isFile(path) then return nil end
|
|
11
|
+
|
|
12
|
+
if maxAge then
|
|
13
|
+
local fileAge = os.time() - wax.filesystem.attributes(path).modifiedAt
|
|
14
|
+
if fileAge > maxAge then
|
|
15
|
+
return nil
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
local success, result = pcall(function()
|
|
20
|
+
return NSKeyedUnarchiver:unarchiveObjectWithFile(path)
|
|
21
|
+
end)
|
|
22
|
+
|
|
23
|
+
if not success then -- Bad cache
|
|
24
|
+
puts("Error: Couldn't read cache with key %s", key)
|
|
25
|
+
wax.cache.clear(key)
|
|
26
|
+
return nil
|
|
27
|
+
else
|
|
28
|
+
return result
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
-- Creates a cache for the key with contents
|
|
33
|
+
-- key: string # value for the cache
|
|
34
|
+
-- contents: object # whatever is NSKeyedArchive compatible
|
|
35
|
+
function wax.cache.set(key, contents)
|
|
36
|
+
local path = wax.cache.pathFor(key)
|
|
37
|
+
|
|
38
|
+
if not contents then -- delete the value from the cache
|
|
39
|
+
wax.cache.clear(key)
|
|
40
|
+
else
|
|
41
|
+
local success = NSKeyedArchiver:archiveRootObject_toFile(contents, path)
|
|
42
|
+
if not success then puts("Couldn't archive cache '%s' to '%s'", key, path) end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
function wax.cache.age(key)
|
|
47
|
+
local path = wax.cache.pathFor(key)
|
|
48
|
+
|
|
49
|
+
-- If there is no file, just send them back a really big age. Cleaner than
|
|
50
|
+
-- dealing with nils
|
|
51
|
+
if not wax.filesystem.isFile(path) then return wax.time.days(1000) end
|
|
52
|
+
|
|
53
|
+
local fileAge = os.time() - wax.filesystem.attributes(path).modifiedAt
|
|
54
|
+
return fileAge
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
-- Removes specific keys from cache
|
|
58
|
+
function wax.cache.clear(...)
|
|
59
|
+
for i, key in ipairs({...}) do
|
|
60
|
+
local path = wax.cache.pathFor(key)
|
|
61
|
+
wax.filesystem.delete(path)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
-- Removes entire cache dir
|
|
66
|
+
function wax.cache.clearAll()
|
|
67
|
+
wax.filesystem.delete(NSCacheDirectory)
|
|
68
|
+
wax.filesystem.createDir(NSCacheDirectory)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
function wax.cache.pathFor(key)
|
|
72
|
+
return NSCacheDirectory .. "/" .. wax.base64.encode(key)
|
|
73
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-- Let's us cancel a callback
|
|
2
|
+
|
|
3
|
+
wax.callback = function(callback)
|
|
4
|
+
local object = {callback = callback}
|
|
5
|
+
|
|
6
|
+
function object.cancel(self)
|
|
7
|
+
self.canceled = true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
function object.__call(self, ...)
|
|
11
|
+
if self.canceled then
|
|
12
|
+
return
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
local args = self.scope and {self.scope, ...} or {...}
|
|
16
|
+
self.callback(unpack(args))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
setmetatable(object, object)
|
|
20
|
+
|
|
21
|
+
return object
|
|
22
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
-- This is weird code... I'm just playing with an idea
|
|
2
|
+
function wax.frame(object)
|
|
3
|
+
return wax.dimensions(object, "frame")
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
function wax.bounds(object)
|
|
7
|
+
return wax.dimensions(object, "bounds")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
function wax.dimensions(object, varName)
|
|
11
|
+
return setmetatable({
|
|
12
|
+
object = object,
|
|
13
|
+
center = function(self)
|
|
14
|
+
local offset = (wax.dimensions(self.object:superview(), varName).width - self.width) / 2
|
|
15
|
+
self.x = offset
|
|
16
|
+
return self
|
|
17
|
+
end,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
__index = function(self, key)
|
|
21
|
+
if key == "y" then key = "top"
|
|
22
|
+
elseif key == "x" then key = "left"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
local dimensions = (varName == "frame") and object:frame() or object:bounds()
|
|
26
|
+
if key == "left" then return dimensions.x
|
|
27
|
+
elseif key == "right" then return dimensions.x + dimensions.width
|
|
28
|
+
elseif key == "top" then return dimensions.y
|
|
29
|
+
elseif key == "bottom" then return dimensions.y + dimensions.height
|
|
30
|
+
elseif key == "height" then return dimensions.height
|
|
31
|
+
elseif key == "width" then return dimensions.width
|
|
32
|
+
|
|
33
|
+
elseif key == "size" then return CGSize(dimensions.width, dimensions.height)
|
|
34
|
+
elseif key == "origin" then return CGPoint(dimensions.x, dimensions.y)
|
|
35
|
+
|
|
36
|
+
else
|
|
37
|
+
error("Unknown frame key: " .. key)
|
|
38
|
+
end
|
|
39
|
+
end,
|
|
40
|
+
|
|
41
|
+
__newindex = function(self, key, value)
|
|
42
|
+
if key == "y" then key = "top"
|
|
43
|
+
elseif key == "x" then key = "left"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
local dimensions = (varName == "frame") and object:frame() or object:bounds()
|
|
47
|
+
if key == "left" then dimensions.x = value
|
|
48
|
+
elseif key == "right" then dimensions.x = value - dimensions.width
|
|
49
|
+
elseif key == "top" then dimensions.y = value
|
|
50
|
+
elseif key == "bottom" then dimensions.y = value - dimensions.height
|
|
51
|
+
elseif key == "height" then dimensions.height = value
|
|
52
|
+
elseif key == "width" then dimensions.width = value
|
|
53
|
+
|
|
54
|
+
elseif key == "size" then dimensions.width = value.width dimensions.height = value.height
|
|
55
|
+
elseif key == "origin" then dimensions.x = value.x dimensions.y = value.y
|
|
56
|
+
elseif key == "stretchTop" then
|
|
57
|
+
dimensions.height = dimensions.height - (value - dimensions.y)
|
|
58
|
+
dimensions.y = value
|
|
59
|
+
elseif key == "stretchBottom" then
|
|
60
|
+
dimensions.height = dimensions.height + (value - (dimensions.height + dimensions.y))
|
|
61
|
+
elseif key == "stretchRight" then
|
|
62
|
+
dimensions.width = dimensions.width + (value - (dimensions.width + dimensions.x))
|
|
63
|
+
else
|
|
64
|
+
error("Unknown frame key: " .. key)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
if (varName == "frame") then
|
|
68
|
+
object:setFrame(dimensions)
|
|
69
|
+
else
|
|
70
|
+
object:setBounds(dimensions)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
return self
|
|
74
|
+
end
|
|
75
|
+
})
|
|
76
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require "wax.helpers.bit"
|
|
2
|
+
require "wax.helpers.callback"
|
|
3
|
+
require "wax.helpers.frame"
|
|
4
|
+
require "wax.helpers.base64"
|
|
5
|
+
require "wax.helpers.time"
|
|
6
|
+
require "wax.helpers.cache"
|
|
7
|
+
require "wax.helpers.autoload"
|
|
8
|
+
require "wax.helpers.WaxServer"
|
|
9
|
+
require "wax.helpers.pickView"
|
|
10
|
+
|
|
11
|
+
-- Just a bunch of global helper functions
|
|
12
|
+
|
|
13
|
+
function IBOutlet(...)
|
|
14
|
+
-- does nothing... just used so we can parse it
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
function wax.alert(title, message, ...)
|
|
18
|
+
local alert = UIAlertView:init()
|
|
19
|
+
alert:setTitle(title)
|
|
20
|
+
alert:setMessage(message)
|
|
21
|
+
|
|
22
|
+
if not ... then
|
|
23
|
+
alert:addButtonWithTitle("OK")
|
|
24
|
+
else
|
|
25
|
+
for i, name in ipairs{...} do
|
|
26
|
+
alert:addButtonWithTitle(name)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
alert:show()
|
|
31
|
+
|
|
32
|
+
return alert
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
-- Forces print to use NSLog
|
|
36
|
+
if not UIDevice:currentDevice():model():match("iPhone Simulator") then
|
|
37
|
+
function print(obj)
|
|
38
|
+
-- if there is an error, ignore it
|
|
39
|
+
pcall(function() wax.print(tostring(obj)) end)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
function wax.tostring(obj, ...)
|
|
44
|
+
if type(obj) == "table" then
|
|
45
|
+
return table.tostring(obj)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if ... then
|
|
49
|
+
obj = string.format(tostring(obj), ...)
|
|
50
|
+
else
|
|
51
|
+
obj = tostring(obj)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
return obj
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
function puts(obj, ...)
|
|
58
|
+
print(wax.tostring(obj, ...))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
function wax.guid()
|
|
62
|
+
return NSProcessInfo:processInfo():globallyUniqueString()
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
function wax.eval(input)
|
|
66
|
+
return pcall(function()
|
|
67
|
+
if not input:match("=") then
|
|
68
|
+
input = "do return (" .. input .. ") end"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
local code, err = loadstring(input, "REPL")
|
|
72
|
+
if err then
|
|
73
|
+
error("Syntax Error: " .. err)
|
|
74
|
+
else
|
|
75
|
+
puts(code())
|
|
76
|
+
end
|
|
77
|
+
end)
|
|
78
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
function startPick()
|
|
3
|
+
local w = UIApplication:sharedApplication():keyWindow()
|
|
4
|
+
_interceptor = InterceptorView:alloc():initWithFrame(w:bounds())
|
|
5
|
+
w:addSubview(_interceptor)
|
|
6
|
+
return "Go on, touch something. Get the view by calling endPick() when you're done."
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
function endPick()
|
|
10
|
+
local v = _interceptor:pickedView()
|
|
11
|
+
_interceptor:removeFromSuperview()
|
|
12
|
+
return v
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
-- wax doesn't automagically bridge C functions
|
|
16
|
+
function CGRectContainsPoint(rect, point)
|
|
17
|
+
return rect.x <= point.x
|
|
18
|
+
and point.x <= rect.x + rect.width
|
|
19
|
+
and rect.y <= point.y
|
|
20
|
+
and point.y <= rect.y + rect.height
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
waxClass{"InterceptorView", UIView}
|
|
24
|
+
|
|
25
|
+
function touchesEnded_withEvent(self, touches, event)
|
|
26
|
+
local point = touches:anyObject():locationInView(self)
|
|
27
|
+
local w = UIApplication:sharedApplication():keyWindow()
|
|
28
|
+
local pointInWindow = w:convertPoint_fromView(point, self)
|
|
29
|
+
self.pickedView_ = self:findOwnerOfPoint_startingWith(pointInWindow, w)
|
|
30
|
+
print(self.pickedView_:class())
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
function pickedView(self)
|
|
34
|
+
return self.pickedView_
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
function findOwnerOfPoint_startingWith(self, point, view)
|
|
38
|
+
if view == self then
|
|
39
|
+
return nil
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
if not CGRectContainsPoint(view:bounds(), point) then
|
|
43
|
+
return nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
local betterResult = nil
|
|
47
|
+
|
|
48
|
+
for i, subview in ipairs(view:subviews()) do
|
|
49
|
+
pointInSubview = subview:convertPoint_fromView(point, view)
|
|
50
|
+
betterResult = self:findOwnerOfPoint_startingWith(pointInSubview, subview) or betterResult
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
return betterResult or view
|
|
54
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
wax.time = {}
|
|
2
|
+
|
|
3
|
+
function wax.time.minutes(number)
|
|
4
|
+
return number * 60
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
function wax.time.hours(number)
|
|
8
|
+
return number * wax.time.minutes(60)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
function wax.time.days(number)
|
|
12
|
+
return number * wax.time.hours(24)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
-- Pattern match formats found here http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
|
16
|
+
function wax.time.formatDate(date, pattern)
|
|
17
|
+
if not wax.time._outputFormatter then
|
|
18
|
+
wax.time._outputFormatter = NSDateFormatter:init()
|
|
19
|
+
local locale = NSLocale:initWithLocaleIdentifier("en_US_POSIX")
|
|
20
|
+
wax.time._outputFormatter:setLocale(locale)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
wax.time._outputFormatter:setDateFormat(pattern or "MMMM d")
|
|
24
|
+
return wax.time._outputFormatter:stringFromDate(date)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
-- Pattern match formats found here http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
|
28
|
+
function wax.time.parseDate(dateString, pattern)
|
|
29
|
+
-- I don't think NSDateFormatter can handle times with Z at the end. Someone
|
|
30
|
+
-- prove me wrong!
|
|
31
|
+
dateString = dateString:gsub("Z$", " GMT")
|
|
32
|
+
|
|
33
|
+
if not wax.time._inputFormatter then
|
|
34
|
+
wax.time._inputFormatter = NSDateFormatter:init()
|
|
35
|
+
locale = NSLocale:initWithLocaleIdentifier("en_US_POSIX")
|
|
36
|
+
wax.time._inputFormatter:setLocale(locale)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
wax.time._inputFormatter:setDateFormat(pattern or "yyyy-MM-dd'T'HH:mm:ss ZZZ")
|
|
40
|
+
return wax.time._inputFormatter:dateFromString(dateString)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
function wax.time.beginingOfDay(date)
|
|
44
|
+
local calendar = NSCalendar:currentCalendar()
|
|
45
|
+
local dateComponents = calendar:components_fromDate(-1, date or NSDate:date())
|
|
46
|
+
local newComponents = NSDateComponents:init()
|
|
47
|
+
newComponents:setYear(dateComponents:year())
|
|
48
|
+
newComponents:setMonth(dateComponents:month())
|
|
49
|
+
newComponents:setDay(dateComponents:day())
|
|
50
|
+
|
|
51
|
+
return calendar:dateFromComponents(newComponents)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
function wax.time.endOfDay(date)
|
|
55
|
+
local calendar = NSCalendar:currentCalendar()
|
|
56
|
+
local dateComponents = calendar:components_fromDate(-1, date)
|
|
57
|
+
local newComponents = NSDateComponents:init()
|
|
58
|
+
newComponents:setYear(dateComponents:year())
|
|
59
|
+
newComponents:setMonth(dateComponents:month())
|
|
60
|
+
newComponents:setDay(dateComponents:day())
|
|
61
|
+
newComponents:setHour(24)
|
|
62
|
+
newComponents:setMinute(59)
|
|
63
|
+
newComponents:setSecond(59)
|
|
64
|
+
|
|
65
|
+
return calendar:dateFromComponents(newComponents)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
function wax.time.timeAgoInWords(firstDate, secondDate)
|
|
69
|
+
local difference = (secondDate or NSDate:date()):timeIntervalSince1970() - firstDate:timeIntervalSince1970()
|
|
70
|
+
local seconds = math.abs(difference)
|
|
71
|
+
local minutes = math.floor(seconds / 60)
|
|
72
|
+
local hours = math.floor(minutes / 60)
|
|
73
|
+
local days = math.floor(hours / 24)
|
|
74
|
+
local months = math.floor(days / 30)
|
|
75
|
+
|
|
76
|
+
if minutes <= 1 then return "less than a minute"
|
|
77
|
+
elseif minutes <= 44 then return ("%d minutes"):format(minutes)
|
|
78
|
+
elseif minutes <= 89 then return "about 1 hour"
|
|
79
|
+
elseif hours <= 24 then return ("about %d hours"):format(hours)
|
|
80
|
+
elseif hours <= 47 then return "1 day"
|
|
81
|
+
elseif days <= 29 then return ("%d days"):format(days)
|
|
82
|
+
elseif days <= 59 then return "about 1 month"
|
|
83
|
+
elseif months <= 15 then return "about 1 year"
|
|
84
|
+
elseif months <= 22 then return "over 1 year"
|
|
85
|
+
elseif years < 2 then return "almost 2 years"
|
|
86
|
+
elseif minutes <= 1051199 then return "about 1 year"
|
|
87
|
+
else return ("over %d years"):format(years)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
function wax.time.since(date, referenceDate)
|
|
92
|
+
referenceDate = referenceDate or NSDate:date()
|
|
93
|
+
local difference = referenceDate:timeIntervalSince1970() - date:timeIntervalSince1970()
|
|
94
|
+
local timeSinceMidnight = date:timeIntervalSince1970() - wax.time.beginingOfDay():timeIntervalSince1970()
|
|
95
|
+
|
|
96
|
+
-- Also returns the preposition as second arg
|
|
97
|
+
if difference < wax.time.days(1) and timeSinceMidnight > 0 then return wax.time.formatDate(date, "h:mm a"), "at"
|
|
98
|
+
elseif difference < wax.time.days(2) then return "Yesterday", ""
|
|
99
|
+
elseif difference < wax.time.days(7) then return wax.time.formatDate(date, "EEEE"), "on"
|
|
100
|
+
else return wax.time.formatDate(date, "MM/dd/yy"), "on"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
setmetatable(_G, {
|
|
2
|
+
__index = function(self, key)
|
|
3
|
+
local class = wax.class[key]
|
|
4
|
+
if class then self[key] = class end -- cache it for future use
|
|
5
|
+
|
|
6
|
+
if not class and key:match("^[A-Z][A-Z][A-Z][^A-Z]") then -- looks like they were trying to use an objective-c obj
|
|
7
|
+
print("WARNING: No object named '" .. key .. "' found.")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
return class
|
|
11
|
+
end
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
require "wax.ext"
|
|
15
|
+
require "wax.enums"
|
|
16
|
+
require "wax.structs"
|
|
17
|
+
require "wax.waxClass"
|
|
18
|
+
require "wax.helpers"
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Mock = { calls = {}, return_values = {} }
|
|
2
|
+
|
|
3
|
+
-- we store all calls and requested return values indexed
|
|
4
|
+
-- by the mock object, we don't want to hold onto references
|
|
5
|
+
-- when they should be garbage collected to make the tables
|
|
6
|
+
-- be weak
|
|
7
|
+
setmetatable(Mock.calls, { __mode="k" })
|
|
8
|
+
setmetatable(Mock.return_values, { __mode="k" })
|
|
9
|
+
|
|
10
|
+
function Mock.__call(mock, ...)
|
|
11
|
+
Mock.calls[mock] = Mock.calls[mock] or {}
|
|
12
|
+
local calls = Mock.calls[mock]
|
|
13
|
+
calls[#calls+1] = {...}
|
|
14
|
+
|
|
15
|
+
local return_values = Mock.return_values[mock]
|
|
16
|
+
|
|
17
|
+
if return_values and return_values[#calls] then
|
|
18
|
+
return unpack(return_values[#calls])
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
function Mock.__index(mock, key)
|
|
23
|
+
local new_mock = Mock:new()
|
|
24
|
+
rawset(mock, key, new_mock)
|
|
25
|
+
return new_mock
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
function Mock:new()
|
|
29
|
+
local mock = { returns = self.returns, then_returns = self.returns }
|
|
30
|
+
setmetatable(mock, self)
|
|
31
|
+
return mock
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
function Mock:returns(...)
|
|
35
|
+
if getmetatable(self) ~= Mock then
|
|
36
|
+
error("returns must be called with : operator", 2)
|
|
37
|
+
end
|
|
38
|
+
local return_values = Mock.return_values[self] or {}
|
|
39
|
+
return_values[#return_values+1] = {...}
|
|
40
|
+
Mock.return_values[self] = return_values
|
|
41
|
+
return self
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
matchers = matchers or {}
|
|
45
|
+
|
|
46
|
+
function matchers.was_called(target, value)
|
|
47
|
+
if getmetatable(target) ~= Mock then
|
|
48
|
+
return false, "target must be a Mock"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
local calls = Mock.calls[target] or {}
|
|
52
|
+
|
|
53
|
+
if #calls ~= value then
|
|
54
|
+
return false, "expecting "..tostring(value).." calls, actually "..#calls
|
|
55
|
+
end
|
|
56
|
+
return true
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
function matchers.was_called_with(target, ...)
|
|
60
|
+
if getmetatable(target) ~= Mock then
|
|
61
|
+
return false, "target must be a Mock"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
local calls = Mock.calls[target] or {}
|
|
65
|
+
|
|
66
|
+
if #calls ~= 1 then
|
|
67
|
+
return false, "expecting "..tostring(1).." call, actually "..#calls
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
local params = calls[1] or {}
|
|
71
|
+
|
|
72
|
+
local args = {...}
|
|
73
|
+
|
|
74
|
+
if #args ~= #params then
|
|
75
|
+
return false, "expecting "..#args.." parameters, actually "..#params
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
for i=1,#args do
|
|
79
|
+
if args[i] ~= params[i] then
|
|
80
|
+
return false, "expecting parameter #"..tostring(i).." to be "..tostring(args[i]).." actually "..tostring(params[i])
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
return true
|
|
84
|
+
end
|