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,14 @@
1
+ #!/bin/zsh
2
+
3
+ # Compiles the wax stdlib into one file
4
+ lua "$PROJECT_DIR/wax/lib/build-scripts/luac.lua" wax wax.dat "$PROJECT_DIR/wax/lib/stdlib/" "$PROJECT_DIR/wax/lib/stdlib/init.lua" -L "$PROJECT_DIR/wax/lib/stdlib"/**/*.lua
5
+
6
+ # Dumps the compiled file into a byte array, then it places this into the source code
7
+ cat > "$PROJECT_DIR/wax/lib/wax_stdlib.h" <<EOF
8
+ // DO NOT MODIFY
9
+ // This is auto generated, it contains a compiled version of the wax stdlib
10
+ #define WAX_STDLIB {$(hexdump -v -e '1/1 "%d,"' wax.dat)}
11
+ EOF
12
+
13
+ # clean up
14
+ rm wax.dat
@@ -0,0 +1,58 @@
1
+ #!/bin/zsh
2
+
3
+ # Created by Corey Johnson
4
+
5
+ WAX_SCRIPTS_DIR="scripts"
6
+ SOURCE_SCRIPTS_DIR="$PROJECT_DIR/$WAX_SCRIPTS_DIR"
7
+ DESTINATION_SCRIPTS_DIR="$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/$WAX_SCRIPTS_DIR"
8
+
9
+ # Verify that the user isn't using an old version of Wax
10
+ if [ -d "$PROJECT_DIR/data/scripts" ]; then
11
+ echo "error: Wax 1.0 changes the Lua loadpath."
12
+ echo "error: Wax won't look for Lua scripts in '$PROJECT_DIR/data/scripts' instead, place all your scripts in '$SOURCE_SCRIPTS_DIR'"
13
+ exit 1
14
+ fi
15
+
16
+ # If the user has luac installed, preparse the lua files and make sure they are cool
17
+ if type luac &> /dev/null; then;
18
+ LUAC_OUTPUT=$(luac -p -- "$SOURCE_SCRIPTS_DIR"/**/*.lua 2>&1)
19
+ LUAC_EXIT_VALUE=$?
20
+ if [ $LUAC_EXIT_VALUE != 0 ] ; then
21
+ echo "\n\n--------------------ERROR--------------------"
22
+ echo "Lua Scripts were not compiled correctly!"
23
+ echo "error::: ${LUAC_OUTPUT}"
24
+ echo "--------------------ERROR--------------------\n\n"
25
+ exit 1
26
+ fi
27
+ fi
28
+
29
+ mkdir -p "$SOURCE_SCRIPTS_DIR"
30
+ rm -rf "$DESTINATION_SCRIPTS_DIR"
31
+ mkdir -p "$DESTINATION_SCRIPTS_DIR"
32
+
33
+ if [ $WAX_COMPILE_SCRIPTS ]; then
34
+ echo "note: Wax is using compiled Lua scripts."
35
+ # This requires that you run a special build of lua. Since snow leopard is 64-bit
36
+ # and iOS is 32-bit, luac files compiled on snow leopard won't work on iOS
37
+
38
+ lua "$PROJECT_DIR/wax/lib/build-scripts/luac.lua" wax wax.dat "$PROJECT_DIR/wax/lib/stdlib/" "$PROJECT_DIR/wax/lib/stdlib/init.lua" -L "$PROJECT_DIR/wax/lib/stdlib"/**/*.lua
39
+ lua "$PROJECT_DIR/wax/lib/build-scripts/luac.lua" "" AppDelegate.dat "$SOURCE_SCRIPTS_DIR/" "$SOURCE_SCRIPTS_DIR/AppDelegate.lua" -L "$SOURCE_SCRIPTS_DIR"/**/*.lua
40
+ mv AppDelegate.dat "$DESTINATION_SCRIPTS_DIR"
41
+ mv wax.dat "$DESTINATION_SCRIPTS_DIR"
42
+ else
43
+ # copy everything in the data dir to the app (doesn't just have to be lua files, can be images, sounds, etc...)
44
+ if [[ -d "$PROJECT_DIR/wax" ]]; then;
45
+ # If we are using the framework, there is no wax dir
46
+ cp -r "$PROJECT_DIR/wax/lib/stdlib" "$DESTINATION_SCRIPTS_DIR/wax"
47
+ fi
48
+ cp -r "$SOURCE_SCRIPTS_DIR/" "$DESTINATION_SCRIPTS_DIR"
49
+ fi
50
+
51
+ # This forces xcode to load all the Lua scripts (without having to clean
52
+ # the project first"
53
+ THE_FUTURE=$(date -v +1M -j +"%m%d%H%M")
54
+ touch -t $THE_FUTURE "$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH"/*.plist
55
+
56
+ # Note:
57
+ # It's handy to see the env of the build processes, there is some good stuff in there!
58
+ env
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env lua
2
+
3
+ -- usage: lua luac.lua module-name output.file base_dir starting-file.lua [-L [other-files.lua]*]
4
+ --
5
+ -- base_dir: The root for all the lua files. So folder modules can be used
6
+ --
7
+ -- creates a precompiled chunk that preloads all modules listed after
8
+ -- -L and then runs all programs listed before -L.
9
+ --
10
+ -- assumptions:
11
+ -- file xxx.lua contains module xxx
12
+ -- '/' is the directory separator (could have used package.config)
13
+ -- int and size_t take 4 bytes (could have read sizes from header)
14
+ -- does not honor package.path
15
+ --
16
+ -- Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
17
+ -- Tue Aug 5 22:57:33 BRT 2008
18
+ -- This code is hereby placed in the public domain.
19
+
20
+ local MARK = "////////"
21
+ local NAME = "luac"
22
+
23
+ local MODULE_NAME = table.remove(arg, 1)
24
+ local OUTPUT = table.remove(arg, 1)
25
+ local BASE_DIR = table.remove(arg, 1)
26
+ NAME = "=("..NAME..")"
27
+
28
+ local argCount = #arg
29
+ local executableIndex = n
30
+ local b
31
+
32
+ for i = 1, argCount do
33
+ if arg[i] == "-L" then executableIndex = i - 1 break end
34
+ end
35
+
36
+ if executableIndex + 2 <= argCount then b = "local t=package.preload;\n" else b = "local t;\n" end
37
+
38
+ for i = executableIndex + 2, argCount do
39
+ local requireString = string.gsub(arg[i], "^" .. string.gsub(BASE_DIR, "(%W)", "%%%1"), "")
40
+ requireString = string.gsub(requireString,"^[\./]*(.-)\.lua$", "%1")
41
+ requireString = string.gsub(requireString, "/", ".")
42
+ requireString = string.gsub(requireString, ".init$", "") -- if it is an init file within a directory... ignore it!
43
+ if MODULE_NAME and #MODULE_NAME > 0 then requireString = MODULE_NAME .. "." .. requireString end
44
+
45
+ b = b.."t['"..requireString.."']=function()end;\n"
46
+ arg[i]=string.sub(string.dump(assert(loadfile(arg[i]))), 13) -- string.sub Removes header from file
47
+ end
48
+ b = b.."t='"..MARK.."';\n"
49
+
50
+ for i = 1, executableIndex do
51
+ b = b.."(function()end)();\n"
52
+ arg[i]=string.sub(string.dump(assert(loadfile(arg[i]))), 13) -- string.sub Removes header from file
53
+ end
54
+
55
+ b = string.dump(assert(loadstring(b, NAME)))
56
+ local x, y = string.find(b, MARK)
57
+ -- 64
58
+ --b = string.sub(b, 1, x - 6 - 4).."\0"..string.sub(b, y + 2, y + 5) -- WTF does this do?
59
+
60
+ -- 32
61
+ b = string.sub(b, 1, x - 6).."\0"..string.sub(b, y + 2, y + 5) -- WTF does this do?
62
+
63
+ f = assert(io.open(OUTPUT, "wb"))
64
+
65
+ assert(f:write(b))
66
+
67
+ for i = executableIndex + 2, argCount do
68
+ assert(f:write(arg[i]))
69
+ end
70
+
71
+ for i=1,executableIndex do
72
+ assert(f:write(arg[i]))
73
+ end
74
+
75
+ -- 64
76
+ --assert(f:write(string.rep("\0", 3 * 8)))
77
+
78
+ -- 32
79
+ assert(f:write(string.rep("\0", 12)))
80
+ assert(f:close())
@@ -0,0 +1,12 @@
1
+ //
2
+ // wax_CGAffine.h
3
+ // EmpireState
4
+ //
5
+ // Created by Corey Johnson on 10/6/09.
6
+ // Copyright 2009 Probably Interactive. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import "lua.h"
11
+
12
+ int luaopen_wax_CGTransform(lua_State *L);
@@ -0,0 +1,85 @@
1
+ //
2
+ // wax_CGAffine.m
3
+ // EmpireState
4
+ //
5
+ // Created by Corey Johnson on 10/6/09.
6
+ // Copyright 2009 Probably Interactive. All rights reserved.
7
+ //
8
+
9
+ #import "wax_CGTransform.h"
10
+
11
+ #import "wax_instance.h"
12
+ #import "wax_helpers.h"
13
+
14
+ #import "lua.h"
15
+ #import "lauxlib.h"
16
+
17
+ #define METATABLE_NAME "wax.CGTransform"
18
+
19
+ static int identity(lua_State *L) {
20
+ CGAffineTransform identity = CGAffineTransformIdentity;
21
+ wax_fromObjc(L, @encode(CGAffineTransform), &identity);
22
+
23
+ return 1;
24
+ }
25
+
26
+
27
+ // wax.CGTransform.scale(transform, 2, 2) -- Returns new transform
28
+ static int scale(lua_State *L) {
29
+ void *value = wax_copyToObjc(L, @encode(CGAffineTransform), 1, nil);
30
+ CGAffineTransform transform = *(CGAffineTransform *)value;
31
+ free(value);
32
+ transform = CGAffineTransformScale(transform, luaL_checknumber(L, 2), luaL_checknumber(L, 3));
33
+ wax_fromObjc(L, @encode(CGAffineTransform), &transform);
34
+
35
+ return 1;
36
+ }
37
+
38
+ // wax.CGTransform.translate(transform, 2, 2) -- Returns new transform
39
+ static int translate(lua_State *L) {
40
+ void *value = wax_copyToObjc(L, @encode(CGAffineTransform), 1, nil);
41
+ CGAffineTransform transform = *(CGAffineTransform *)value;
42
+ free(value);
43
+ transform = CGAffineTransformTranslate(transform, luaL_checknumber(L, 2), luaL_checknumber(L, 3));
44
+ wax_fromObjc(L, @encode(CGAffineTransform), &transform);
45
+
46
+ return 1;
47
+ }
48
+
49
+ // wax.CGTransform.rotate(transform, angle) -- Returns new transform
50
+ static int rotate(lua_State *L) {
51
+ void *value = wax_copyToObjc(L, @encode(CGAffineTransform), 1, nil);
52
+ CGAffineTransform transform = *(CGAffineTransform *)value;
53
+ free(value);
54
+ transform = CGAffineTransformRotate(transform, luaL_checknumber(L, 2));
55
+ wax_fromObjc(L, @encode(CGAffineTransform), &transform);
56
+
57
+
58
+
59
+ return 1;
60
+ }
61
+
62
+ static const struct luaL_Reg metaFunctions[] = {
63
+ {NULL, NULL}
64
+ };
65
+
66
+ static const struct luaL_Reg functions[] = {
67
+ {"identity", identity},
68
+ {"scale", scale},
69
+ {"translate", translate},
70
+ {"rotate", rotate},
71
+
72
+ {NULL, NULL}
73
+ };
74
+
75
+ int luaopen_wax_CGTransform(lua_State *L) {
76
+ BEGIN_STACK_MODIFY(L);
77
+
78
+ luaL_newmetatable(L, METATABLE_NAME);
79
+ luaL_register(L, NULL, metaFunctions);
80
+ luaL_register(L, METATABLE_NAME, functions);
81
+
82
+ END_STACK_MODIFY(L, 0)
83
+
84
+ return 1;
85
+ }
@@ -0,0 +1,12 @@
1
+ //
2
+ // WaxCGContext.h
3
+ // EmpireState
4
+ //
5
+ // Created by Corey Johnson on 10/5/09.
6
+ // Copyright 2009 Probably Interactive. All rights reserved.
7
+ //
8
+
9
+ #import <Foundation/Foundation.h>
10
+ #import "lua.h"
11
+
12
+ int luaopen_wax_CGContext(lua_State *L);
@@ -0,0 +1,251 @@
1
+ //
2
+ // WaxCGContext.m
3
+ // EmpireState
4
+ //
5
+ // Created by Corey Johnson on 10/5/09.
6
+ // Copyright 2009 Probably Interactive. All rights reserved.
7
+ //
8
+
9
+ #import "wax_CGContext.h"
10
+
11
+ #import "wax_instance.h"
12
+ #import "wax_helpers.h"
13
+
14
+ #import "lua.h"
15
+ #import "lauxlib.h"
16
+
17
+ #define METATABLE_NAME "wax.CGContext"
18
+
19
+ static int currentContext(lua_State *L) {
20
+ CGContextRef context = UIGraphicsGetCurrentContext();
21
+
22
+ wax_fromObjc(L, @encode(CGContextRef), &context);
23
+ if (lua_gettop(L) > 1 && lua_isfunction(L, 1)) { // Function!
24
+ CGContextSaveGState(context);
25
+ lua_call(L, 1, 1);
26
+ CGContextRestoreGState(context);
27
+ }
28
+
29
+ return 1;
30
+ }
31
+
32
+ static int imageContext(lua_State *L) {
33
+ int startTop = lua_gettop(L);
34
+ int width = luaL_checknumber(L, 1);
35
+ int height = luaL_checknumber(L, 2);
36
+
37
+ UIGraphicsBeginImageContext(CGSizeMake(width, height));
38
+ lua_call(L, 0, LUA_MULTRET);
39
+ UIGraphicsEndImageContext();
40
+
41
+ int nresults = lua_gettop(L) - startTop + 1; // Add one because the function is popped
42
+
43
+ return nresults;
44
+ }
45
+
46
+ static int imageFromContext(lua_State *L) {
47
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
48
+ wax_instance_create(L, image, NO);
49
+
50
+ return 1;
51
+ }
52
+
53
+ static int translate(lua_State *L) {
54
+ CGContextRef c = (CGContextRef)lua_topointer(L, 1);
55
+ CGFloat x = lua_tonumber(L, 2);
56
+ CGFloat y = lua_tonumber(L, 3);
57
+
58
+ CGContextTranslateCTM(c, x, y);
59
+
60
+ return 0;
61
+ }
62
+
63
+ static int setAlpha(lua_State *L) {
64
+ CGContextRef c = (CGContextRef)lua_topointer(L, 1);
65
+ double alpha = lua_tonumber(L, 2);
66
+ CGContextSetAlpha(c, alpha);
67
+
68
+ return 0;
69
+ }
70
+
71
+ // Can take percent values (0 - 1) or a UIColor
72
+ // setFillColor(context, r, g, b [, a])
73
+ // setFillColor(context, color)
74
+ static int setFillColor(lua_State *L) {
75
+ CGContextRef c = (CGContextRef)lua_topointer(L, 1);
76
+
77
+ if (lua_gettop(L) >= 4) {
78
+ double r = luaL_checknumber(L, 2);
79
+ double g = luaL_checknumber(L, 3);
80
+ double b = luaL_checknumber(L, 4);
81
+ double a = lua_isnoneornil(L, 5) ? 1 : luaL_checknumber(L, 5);
82
+ CGContextSetRGBFillColor(c, r, g, b, a);
83
+ }
84
+ else {
85
+ UIColor **color = wax_copyToObjc(L, @encode(UIColor *), 2, nil);
86
+ CGContextSetFillColorWithColor(c, [*color CGColor]);
87
+ free(color);
88
+ }
89
+
90
+ return 0;
91
+ }
92
+
93
+ // Can take percent values (0 - 1) or a UIColor
94
+ // setStrokeColor(context, r, g, b [, a])
95
+ // setStrokeColor(context, color)
96
+ static int setStrokeColor(lua_State *L) {
97
+ CGContextRef c = (CGContextRef)lua_topointer(L, 1);
98
+
99
+ if (lua_gettop(L) >= 4) {
100
+ double r = luaL_checknumber(L, 2);
101
+ double g = luaL_checknumber(L, 3);
102
+ double b = luaL_checknumber(L, 4);
103
+ double a = lua_isnoneornil(L, 5) ? 1 : luaL_checknumber(L, 5);
104
+ CGContextSetRGBStrokeColor(c, r, g, b, a);
105
+ }
106
+ else {
107
+ UIColor **color = wax_copyToObjc(L, @encode(id), 2, nil);
108
+ CGContextSetStrokeColorWithColor(c, [*color CGColor]);
109
+ free(color);
110
+ }
111
+
112
+ return 0;
113
+ }
114
+
115
+ // fillRect(context, CGRect(0,0,10,10))
116
+ static int fillRect(lua_State *L) {
117
+ CGContextRef c = (CGContextRef)lua_topointer(L, 1);
118
+ CGRect *rect = wax_copyToObjc(L, @encode(CGRect), 2, nil);
119
+ CGContextFillRect(c, *rect);
120
+ free(rect);
121
+
122
+ return 0;
123
+ }
124
+
125
+ // fillRoundedRect(context, CGRect(0,0,10,10), 10)
126
+ static int fillRoundedRect(lua_State *L) {
127
+ CGContextRef c = (CGContextRef)lua_topointer(L, 1);
128
+ CGRect *rect = wax_copyToObjc(L, @encode(CGRect), 2, nil);
129
+ CGFloat radius = luaL_checknumber(L, 3);
130
+
131
+ CGFloat width = CGRectGetWidth(*rect);
132
+ CGFloat height = CGRectGetHeight(*rect);
133
+
134
+ // Make sure corner radius isn't larger than half the shorter side
135
+ if (radius > width/2.0) {
136
+ radius = width/2.0;
137
+ }
138
+ if (radius > height/2.0) {
139
+ radius = height/2.0;
140
+ }
141
+
142
+ CGFloat minx = CGRectGetMinX(*rect);
143
+ CGFloat midx = CGRectGetMidX(*rect);
144
+ CGFloat maxx = CGRectGetMaxX(*rect);
145
+ CGFloat miny = CGRectGetMinY(*rect);
146
+ CGFloat midy = CGRectGetMidY(*rect);
147
+ CGFloat maxy = CGRectGetMaxY(*rect);
148
+ CGContextMoveToPoint(c, minx, midy);
149
+ CGContextAddArcToPoint(c, minx, miny, midx, miny, radius);
150
+ CGContextAddArcToPoint(c, maxx, miny, maxx, midy, radius);
151
+ CGContextAddArcToPoint(c, maxx, maxy, midx, maxy, radius);
152
+ CGContextAddArcToPoint(c, minx, maxy, minx, midy, radius);
153
+ CGContextClosePath(c);
154
+ CGContextDrawPath(c, kCGPathFill);
155
+
156
+ free(rect);
157
+
158
+ return 0;
159
+ }
160
+
161
+ // fillPath(context, pointArray)
162
+ static int fillPath(lua_State *L) {
163
+ CGContextRef c = (CGContextRef)lua_topointer(L, 1);
164
+ CGContextBeginPath(c);
165
+
166
+ int indexCount = lua_objlen(L, 2);
167
+ if (indexCount % 2 != 0) luaL_error(L, "Requires an even number of indexes for points.");
168
+
169
+ int pointCount = indexCount / 2;
170
+ CGPoint *points = calloc(pointCount, sizeof(CGPoint));
171
+
172
+ for (int i = 0; i < pointCount; i++) {
173
+ int arrayIndex = (i * 2) + 1;
174
+ lua_rawgeti(L, 2, arrayIndex);
175
+ lua_rawgeti(L, 2, arrayIndex + 1);
176
+ points[i].x = luaL_checknumber(L, -2);
177
+ points[i].y = luaL_checknumber(L, -1);
178
+ lua_pop(L, 2);
179
+ }
180
+ CGContextAddLines(c, points, pointCount);
181
+ CGContextDrawPath(c, kCGPathFill);
182
+
183
+ free(points);
184
+
185
+ return 0;
186
+ }
187
+
188
+ // drawLinearGradient(context, startPoint, endPoint, colors, locations)
189
+ // FOR SOME REASON THIS DOESN'T WORK WITH GRAY/BLACK COLORS... WTF!
190
+ static int drawLinearGradient(lua_State *L) {
191
+ CGContextRef c = (CGContextRef)lua_topointer(L, 1);
192
+ CGPoint *start = wax_copyToObjc(L, @encode(CGPoint), 2, nil);
193
+ CGPoint *end = wax_copyToObjc(L, @encode(CGPoint), 3, nil);
194
+ NSArray *colors = wax_copyToObjc(L, @encode(NSArray *), 4, nil);
195
+
196
+ CGFloat *locations = malloc(lua_objlen(L, 5) * sizeof(CGFloat));
197
+
198
+ for (int i = 0; i < lua_objlen(L, 5); i++) {
199
+ lua_rawgeti(L, 5, i + 1);
200
+ locations[i] = luaL_checknumber(L, -1);
201
+ lua_pop(L, 1);
202
+ }
203
+
204
+
205
+ CGGradientRef gradient = CGGradientCreateWithColors(nil, *(CFArrayRef *)colors, nil);
206
+
207
+ CGContextDrawLinearGradient(c, gradient, *start, *end, 0);
208
+
209
+ free(start);
210
+ free(end);
211
+ free(colors);
212
+ free(locations);
213
+ CGGradientRelease(gradient);
214
+
215
+ return 0;
216
+ }
217
+
218
+ static const struct luaL_Reg metaFunctions[] = {
219
+ {NULL, NULL}
220
+ };
221
+
222
+ static const struct luaL_Reg functions[] = {
223
+ {"currentContext", currentContext},
224
+ {"imageContext", imageContext},
225
+ {"imageFromContext", imageFromContext},
226
+
227
+ {"translate", translate},
228
+
229
+ {"setFillColor", setFillColor},
230
+ {"setStrokeColor", setStrokeColor},
231
+ {"setAlpha", setAlpha},
232
+
233
+ {"fillRect", fillRect},
234
+ {"fillRoundedRect", fillRoundedRect},
235
+ {"fillPath", fillPath},
236
+ {"drawLinearGradient", drawLinearGradient},
237
+
238
+ {NULL, NULL}
239
+ };
240
+
241
+ int luaopen_wax_CGContext(lua_State *L) {
242
+ BEGIN_STACK_MODIFY(L);
243
+
244
+ luaL_newmetatable(L, METATABLE_NAME);
245
+ luaL_register(L, NULL, metaFunctions);
246
+ luaL_register(L, METATABLE_NAME, functions);
247
+
248
+ END_STACK_MODIFY(L, 0)
249
+
250
+ return 1;
251
+ }