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,97 @@
|
|
1
|
+
function string.unescape(url)
|
2
|
+
url = string.gsub(url, "+", " ")
|
3
|
+
url = string.gsub(url, "%%(%x%x)", function(hex)
|
4
|
+
return string.char(tonumber(hex, 16))
|
5
|
+
end)
|
6
|
+
|
7
|
+
return url
|
8
|
+
end
|
9
|
+
|
10
|
+
function string.split(s, sep)
|
11
|
+
local t = {}
|
12
|
+
for o in string.gmatch(s, "([^" .. (sep or " ") .. "]+)") do
|
13
|
+
table.insert(t, o)
|
14
|
+
end
|
15
|
+
|
16
|
+
return t
|
17
|
+
end
|
18
|
+
|
19
|
+
function string.strip(s, pattern)
|
20
|
+
pattern = pattern or "%s+"
|
21
|
+
s = s:gsub("^" .. pattern, "")
|
22
|
+
s = s:gsub(pattern .. "$", "")
|
23
|
+
return s
|
24
|
+
end
|
25
|
+
|
26
|
+
function string.camelCase(s)
|
27
|
+
local splitTable = s:split("_-")
|
28
|
+
local result = table.remove(splitTable, 1)
|
29
|
+
for i, chunk in ipairs(splitTable) do
|
30
|
+
result = result .. chunk:sub(1,1):upper() .. chunk:sub(2)
|
31
|
+
end
|
32
|
+
|
33
|
+
return result
|
34
|
+
end
|
35
|
+
|
36
|
+
function string.escape(s)
|
37
|
+
s = string.gsub(s, "([!%*'%(%);:@&=%+%$,/%?#%[%]<>~%.\"{}|\\%-`_%^%%%c])",
|
38
|
+
function (c)
|
39
|
+
return string.format("%%%02X", string.byte(c))
|
40
|
+
end)
|
41
|
+
s = string.gsub(s, " ", "+")
|
42
|
+
|
43
|
+
return s
|
44
|
+
end
|
45
|
+
|
46
|
+
function string.decodeEntities(s)
|
47
|
+
local entities = {
|
48
|
+
amp = "&",
|
49
|
+
lt = "<",
|
50
|
+
gt = ">",
|
51
|
+
quot = "\"",
|
52
|
+
apos = "'",
|
53
|
+
nbsp = " ",
|
54
|
+
iexcl = "¡",
|
55
|
+
cent = "¢",
|
56
|
+
pound = "£",
|
57
|
+
curren = "¤",
|
58
|
+
yen = "¥",
|
59
|
+
brvbar = "¦",
|
60
|
+
sect = "§",
|
61
|
+
uml = "¨",
|
62
|
+
copy = "©",
|
63
|
+
ordf = "ª",
|
64
|
+
laquo = "«",
|
65
|
+
-- not = "¬",
|
66
|
+
shy = "",
|
67
|
+
reg = "®",
|
68
|
+
macr = "¯",
|
69
|
+
deg = "°",
|
70
|
+
plusmn = "±",
|
71
|
+
sup2 = "²",
|
72
|
+
sup3 = "³",
|
73
|
+
acute = "´",
|
74
|
+
micro = "µ",
|
75
|
+
para = "¶",
|
76
|
+
middot = "·",
|
77
|
+
cedil = "¸",
|
78
|
+
sup1 = "¹",
|
79
|
+
ordm = "º",
|
80
|
+
raquo = "»",
|
81
|
+
frac14 = "¼",
|
82
|
+
frac12 = "½",
|
83
|
+
frac34 = "¾",
|
84
|
+
iquest = "¿",
|
85
|
+
times = "×",
|
86
|
+
divide = "÷",
|
87
|
+
}
|
88
|
+
|
89
|
+
return string.gsub(s, "&(%w+);", entities)
|
90
|
+
end
|
91
|
+
|
92
|
+
function string.caseInsensitive(s)
|
93
|
+
s = string.gsub(s, "%a", function (c)
|
94
|
+
return string.format("[%s%s]", string.lower(c), string.upper(c))
|
95
|
+
end)
|
96
|
+
return s
|
97
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
function table.clone(t, nometa)
|
2
|
+
local u = {}
|
3
|
+
|
4
|
+
if not nometa then
|
5
|
+
setmetatable(u, getmetatable(t))
|
6
|
+
end
|
7
|
+
|
8
|
+
for i, v in pairs(t) do
|
9
|
+
if type(v) == "table" then
|
10
|
+
u[i] = table.clone(v)
|
11
|
+
else
|
12
|
+
u[i] = v
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
return u
|
17
|
+
end
|
18
|
+
|
19
|
+
function table.merge(t, u)
|
20
|
+
local r = table.clone(t)
|
21
|
+
|
22
|
+
for i, v in pairs(u) do
|
23
|
+
r[i] = v
|
24
|
+
end
|
25
|
+
|
26
|
+
return r
|
27
|
+
end
|
28
|
+
|
29
|
+
function table.keys(t)
|
30
|
+
local keys = {}
|
31
|
+
for k, v in pairs(t) do table.insert(keys, k) end
|
32
|
+
return keys
|
33
|
+
end
|
34
|
+
|
35
|
+
function table.unique(t)
|
36
|
+
local seen = {}
|
37
|
+
for i, v in ipairs(t) do
|
38
|
+
if not table.includes(seen, v) then table.insert(seen, v) end
|
39
|
+
end
|
40
|
+
|
41
|
+
return seen
|
42
|
+
end
|
43
|
+
|
44
|
+
function table.values(t)
|
45
|
+
local values = {}
|
46
|
+
for k, v in pairs(t) do table.insert(values, v) end
|
47
|
+
return values
|
48
|
+
end
|
49
|
+
|
50
|
+
function table.last(t)
|
51
|
+
return t[#t]
|
52
|
+
end
|
53
|
+
|
54
|
+
function table.append(t, moreValues)
|
55
|
+
for i, v in ipairs(moreValues) do
|
56
|
+
table.insert(t, v)
|
57
|
+
end
|
58
|
+
|
59
|
+
return t
|
60
|
+
end
|
61
|
+
|
62
|
+
function table.indexOf(t, value)
|
63
|
+
for k, v in pairs(t) do
|
64
|
+
if type(value) == "function" then
|
65
|
+
if value(v) then return k end
|
66
|
+
else
|
67
|
+
if v == value then return k end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
return nil
|
72
|
+
end
|
73
|
+
|
74
|
+
function table.includes(t, value)
|
75
|
+
return table.indexOf(t, value)
|
76
|
+
end
|
77
|
+
|
78
|
+
function table.removeValue(t, value)
|
79
|
+
local index = table.indexOf(t, value)
|
80
|
+
if index then table.remove(t, index) end
|
81
|
+
return t
|
82
|
+
end
|
83
|
+
|
84
|
+
function table.each(t, func)
|
85
|
+
for k, v in pairs(t) do
|
86
|
+
func(v, k)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
function table.find(t, func)
|
91
|
+
for k, v in pairs(t) do
|
92
|
+
if func(v) then return v, k end
|
93
|
+
end
|
94
|
+
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
|
98
|
+
function table.filter(t, func)
|
99
|
+
local matches = {}
|
100
|
+
for k, v in pairs(t) do
|
101
|
+
if func(v) then table.insert(matches, v) end
|
102
|
+
end
|
103
|
+
|
104
|
+
return matches
|
105
|
+
end
|
106
|
+
|
107
|
+
function table.map(t, func)
|
108
|
+
local mapped = {}
|
109
|
+
for k, v in pairs(t) do
|
110
|
+
table.insert(mapped, func(v, k))
|
111
|
+
end
|
112
|
+
|
113
|
+
return mapped
|
114
|
+
end
|
115
|
+
|
116
|
+
function table.groupBy(t, func)
|
117
|
+
local grouped = {}
|
118
|
+
for k, v in pairs(t) do
|
119
|
+
local groupKey = func(v)
|
120
|
+
if not grouped[groupKey] then grouped[groupKey] = {} end
|
121
|
+
table.insert(grouped[groupKey], v)
|
122
|
+
end
|
123
|
+
|
124
|
+
return grouped
|
125
|
+
end
|
126
|
+
|
127
|
+
function table.tostring(tbl, indent, limit, depth, jstack)
|
128
|
+
limit = limit or 1000
|
129
|
+
depth = depth or 7
|
130
|
+
jstack = jstack or {}
|
131
|
+
local i = 0
|
132
|
+
|
133
|
+
local output = {}
|
134
|
+
if type(tbl) == "table" then
|
135
|
+
-- very important to avoid disgracing ourselves with circular referencs...
|
136
|
+
for i,t in ipairs(jstack) do
|
137
|
+
if tbl == t then
|
138
|
+
return "<self>,\n"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
table.insert(jstack, tbl)
|
142
|
+
|
143
|
+
table.insert(output, "{\n")
|
144
|
+
for key, value in pairs(tbl) do
|
145
|
+
local innerIndent = (indent or " ") .. (indent or " ")
|
146
|
+
table.insert(output, innerIndent .. tostring(key) .. " = ")
|
147
|
+
table.insert(output,
|
148
|
+
value == tbl and "<self>," or table.tostring(value, innerIndent, limit, depth, jstack)
|
149
|
+
)
|
150
|
+
|
151
|
+
i = i + 1
|
152
|
+
if i > limit then
|
153
|
+
table.insert(output, (innerIndent or "") .. "...\n")
|
154
|
+
break
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
table.insert(output, indent and (indent or "") .. "},\n" or "}")
|
159
|
+
else
|
160
|
+
if type(tbl) == "string" then tbl = string.format("%q", tbl) end -- quote strings
|
161
|
+
table.insert(output, tostring(tbl) .. ",\n")
|
162
|
+
end
|
163
|
+
|
164
|
+
return table.concat(output)
|
165
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
-- I don't know where the proper place for this file is. It's not really a helper
|
2
|
+
waxClass{"WaxServer"}
|
3
|
+
|
4
|
+
-- Class Method
|
5
|
+
---------------
|
6
|
+
function start(self)
|
7
|
+
self.server = wax.class['wax_server']:init()
|
8
|
+
|
9
|
+
local err = self.server and self.server:startOnPort(9000)
|
10
|
+
if err then
|
11
|
+
puts("Failed creating server: %s", err and err:description() or "Server Not Created")
|
12
|
+
return err
|
13
|
+
end
|
14
|
+
|
15
|
+
self.server:setDelegate(self)
|
16
|
+
|
17
|
+
-- redirect print
|
18
|
+
local formerPrint = print
|
19
|
+
_G.print = function(...)
|
20
|
+
formerPrint(...)
|
21
|
+
local objects = table.map({...}, function(o) return tostring(o) end)
|
22
|
+
self.server:send(table.concat(objects, '\t') .. "\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
function showPrompt(self)
|
29
|
+
self.server:send "> "
|
30
|
+
end
|
31
|
+
|
32
|
+
-- DebugServerDelegate
|
33
|
+
----------------------
|
34
|
+
function connected(self)
|
35
|
+
self:showPrompt()
|
36
|
+
end
|
37
|
+
|
38
|
+
function disconnected(self)
|
39
|
+
self.server:send("GOODBYE!")
|
40
|
+
end
|
41
|
+
|
42
|
+
function dataReceived(self, data)
|
43
|
+
local input = NSString:initWithData_encoding(data, NSASCIIStringEncoding)
|
44
|
+
local success, err = wax.eval(input)
|
45
|
+
|
46
|
+
if not success then self.server:send("Error: " .. err .. "\n") end
|
47
|
+
|
48
|
+
self:showPrompt()
|
49
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
function wax.autoload(...)
|
2
|
+
for i, folder in ipairs({...}) do
|
3
|
+
local files = wax.filesystem.search(wax.root(folder), "lua$")
|
4
|
+
for i, file in ipairs(files) do
|
5
|
+
local requireString = file:match(wax.root() .. "/(.*)%.lua$")
|
6
|
+
requireString = requireString:gsub("/", ".")
|
7
|
+
require(requireString)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
-- working lua base64 codec (c) 2006-2008 by Alex Kloss
|
2
|
+
-- compatible with lua 5.1
|
3
|
+
-- http://www.it-rfc.de
|
4
|
+
|
5
|
+
module("wax.base64", package.seeall)
|
6
|
+
|
7
|
+
-- bitshift functions (<<, >> equivalent)
|
8
|
+
-- shift left
|
9
|
+
function lsh(value,shift)
|
10
|
+
return (value*(2^shift)) % 256
|
11
|
+
end
|
12
|
+
|
13
|
+
-- shift right
|
14
|
+
function rsh(value,shift)
|
15
|
+
return math.floor(value/2^shift) % 256
|
16
|
+
end
|
17
|
+
|
18
|
+
-- return single bit (for OR)
|
19
|
+
function bit(x,b)
|
20
|
+
return (x % 2^b - x % 2^(b-1) > 0)
|
21
|
+
end
|
22
|
+
|
23
|
+
-- logic OR for number values
|
24
|
+
function lor(x,y)
|
25
|
+
result = 0
|
26
|
+
for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
|
27
|
+
return result
|
28
|
+
end
|
29
|
+
|
30
|
+
-- encryption table
|
31
|
+
local base64chars = {[0]='A',[1]='B',[2]='C',[3]='D',[4]='E',[5]='F',[6]='G',[7]='H',[8]='I',[9]='J',[10]='K',[11]='L',[12]='M',[13]='N',[14]='O',[15]='P',[16]='Q',[17]='R',[18]='S',[19]='T',[20]='U',[21]='V',[22]='W',[23]='X',[24]='Y',[25]='Z',[26]='a',[27]='b',[28]='c',[29]='d',[30]='e',[31]='f',[32]='g',[33]='h',[34]='i',[35]='j',[36]='k',[37]='l',[38]='m',[39]='n',[40]='o',[41]='p',[42]='q',[43]='r',[44]='s',[45]='t',[46]='u',[47]='v',[48]='w',[49]='x',[50]='y',[51]='z',[52]='0',[53]='1',[54]='2',[55]='3',[56]='4',[57]='5',[58]='6',[59]='7',[60]='8',[61]='9',[62]='+',[63]='/'}
|
32
|
+
|
33
|
+
-- function encode
|
34
|
+
-- encodes input string to base64.
|
35
|
+
function encode(data)
|
36
|
+
local bytes = {}
|
37
|
+
local result = ""
|
38
|
+
for spos=0,string.len(data)-1,3 do
|
39
|
+
for byte=1,3 do bytes[byte] = string.byte(string.sub(data,(spos+byte))) or 0 end
|
40
|
+
result = string.format('%s%s%s%s%s',result,
|
41
|
+
base64chars[rsh(bytes[1],2)],
|
42
|
+
base64chars[lor(lsh((bytes[1] % 4),4), rsh(bytes[2],4))] or "=",
|
43
|
+
((#data-spos) > 1) and base64chars[lor(lsh(bytes[2] % 16,2), rsh(bytes[3],6))] or "=",
|
44
|
+
((#data-spos) > 2) and base64chars[(bytes[3] % 64)] or "=")
|
45
|
+
end
|
46
|
+
return result
|
47
|
+
end
|
48
|
+
|
49
|
+
-- decryption table
|
50
|
+
local base64bytes = {['A']=0,['B']=1,['C']=2,['D']=3,['E']=4,['F']=5,['G']=6,['H']=7,['I']=8,['J']=9,['K']=10,['L']=11,['M']=12,['N']=13,['O']=14,['P']=15,['Q']=16,['R']=17,['S']=18,['T']=19,['U']=20,['V']=21,['W']=22,['X']=23,['Y']=24,['Z']=25,['a']=26,['b']=27,['c']=28,['d']=29,['e']=30,['f']=31,['g']=32,['h']=33,['i']=34,['j']=35,['k']=36,['l']=37,['m']=38,['n']=39,['o']=40,['p']=41,['q']=42,['r']=43,['s']=44,['t']=45,['u']=46,['v']=47,['w']=48,['x']=49,['y']=50,['z']=51,['0']=52,['1']=53,['2']=54,['3']=55,['4']=56,['5']=57,['6']=58,['7']=59,['8']=60,['9']=61,['+']=62,['/']=63,['=']=nil}
|
51
|
+
|
52
|
+
-- function decode
|
53
|
+
-- decode base64 input to string
|
54
|
+
function decode(data)
|
55
|
+
local chars = {}
|
56
|
+
local result=""
|
57
|
+
for dpos=0,string.len(data)-1,4 do
|
58
|
+
for char=1,4 do chars[char] = base64bytes[(string.sub(data,(dpos+char),(dpos+char)) or "=")] end
|
59
|
+
result = result .. string.char(lor(lsh(chars[1],2), rsh(chars[2],4)))
|
60
|
+
result = result .. ((chars[3] ~= nil) and string.char(lor(lsh(chars[2],4), rsh(chars[3],2))) or "")
|
61
|
+
result = result .. ((chars[4] ~= nil) and string.char(lor(lsh(chars[3] % 4,6), (chars[4]))) or "")
|
62
|
+
end
|
63
|
+
return result
|
64
|
+
end
|
@@ -0,0 +1,274 @@
|
|
1
|
+
--[[---------------
|
2
|
+
LuaBit v0.4
|
3
|
+
-------------------
|
4
|
+
a bitwise operation lib for lua.
|
5
|
+
|
6
|
+
http://luaforge.net/projects/bit/
|
7
|
+
|
8
|
+
How to use:
|
9
|
+
-------------------
|
10
|
+
wax.bit.bnot(n) -- bitwise not (~n)
|
11
|
+
wax.bit.band(m, n) -- bitwise and (m & n)
|
12
|
+
wax.bit.bor(m, n) -- bitwise or (m | n)
|
13
|
+
wax.bit.bxor(m, n) -- bitwise xor (m ^ n)
|
14
|
+
wax.bit.brshift(n, bits) -- right shift (n >> bits)
|
15
|
+
wax.bit.blshift(n, bits) -- left shift (n << bits)
|
16
|
+
wax.bit.blogic_rshift(n, bits) -- logic right shift(zero fill >>>)
|
17
|
+
|
18
|
+
Please note that bit.brshift and bit.blshift only support number within
|
19
|
+
32 bits.
|
20
|
+
|
21
|
+
2 utility functions are provided too:
|
22
|
+
bit.tobits(n) -- convert n into a bit table(which is a 1/0 sequence)
|
23
|
+
-- high bits first
|
24
|
+
bit.tonumb(bit_tbl) -- convert a bit table into a number
|
25
|
+
-------------------
|
26
|
+
|
27
|
+
Under the MIT license.
|
28
|
+
|
29
|
+
copyright(c) 2006~2007 hanzhao (abrash_han@hotmail.com)
|
30
|
+
--]]---------------
|
31
|
+
|
32
|
+
do
|
33
|
+
|
34
|
+
------------------------
|
35
|
+
-- bit lib implementions
|
36
|
+
|
37
|
+
local function check_int(n)
|
38
|
+
-- checking not float
|
39
|
+
if(n - math.floor(n) > 0) then
|
40
|
+
error("trying to use bitwise operation on non-integer!")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
local function to_bits(n)
|
45
|
+
check_int(n)
|
46
|
+
if(n < 0) then
|
47
|
+
-- negative
|
48
|
+
return to_bits(bit.bnot(math.abs(n)) + 1)
|
49
|
+
end
|
50
|
+
-- to bits table
|
51
|
+
local tbl = {}
|
52
|
+
local cnt = 1
|
53
|
+
while (n > 0) do
|
54
|
+
local last = math.mod(n,2)
|
55
|
+
if(last == 1) then
|
56
|
+
tbl[cnt] = 1
|
57
|
+
else
|
58
|
+
tbl[cnt] = 0
|
59
|
+
end
|
60
|
+
n = (n-last)/2
|
61
|
+
cnt = cnt + 1
|
62
|
+
end
|
63
|
+
|
64
|
+
return tbl
|
65
|
+
end
|
66
|
+
|
67
|
+
local function tbl_to_number(tbl)
|
68
|
+
local n = table.getn(tbl)
|
69
|
+
|
70
|
+
local rslt = 0
|
71
|
+
local power = 1
|
72
|
+
for i = 1, n do
|
73
|
+
rslt = rslt + tbl[i]*power
|
74
|
+
power = power*2
|
75
|
+
end
|
76
|
+
|
77
|
+
return rslt
|
78
|
+
end
|
79
|
+
|
80
|
+
local function expand(tbl_m, tbl_n)
|
81
|
+
local big = {}
|
82
|
+
local small = {}
|
83
|
+
if(table.getn(tbl_m) > table.getn(tbl_n)) then
|
84
|
+
big = tbl_m
|
85
|
+
small = tbl_n
|
86
|
+
else
|
87
|
+
big = tbl_n
|
88
|
+
small = tbl_m
|
89
|
+
end
|
90
|
+
-- expand small
|
91
|
+
for i = table.getn(small) + 1, table.getn(big) do
|
92
|
+
small[i] = 0
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
local function bit_or(m, n, ...)
|
98
|
+
local tbl_m = to_bits(m)
|
99
|
+
local tbl_n = to_bits(n)
|
100
|
+
expand(tbl_m, tbl_n)
|
101
|
+
|
102
|
+
local tbl = {}
|
103
|
+
local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))
|
104
|
+
for i = 1, rslt do
|
105
|
+
if(tbl_m[i]== 0 and tbl_n[i] == 0) then
|
106
|
+
tbl[i] = 0
|
107
|
+
else
|
108
|
+
tbl[i] = 1
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
local result = tbl_to_number(tbl)
|
113
|
+
if ... then
|
114
|
+
local args = {...}
|
115
|
+
local n = table.remove(args, 1)
|
116
|
+
return bit_or(result, n, #args > 0 and args or nil)
|
117
|
+
else
|
118
|
+
return result
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
local function bit_and(m, n, ...)
|
123
|
+
local tbl_m = to_bits(m)
|
124
|
+
local tbl_n = to_bits(n)
|
125
|
+
expand(tbl_m, tbl_n)
|
126
|
+
|
127
|
+
local tbl = {}
|
128
|
+
local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))
|
129
|
+
for i = 1, rslt do
|
130
|
+
if(tbl_m[i]== 0 or tbl_n[i] == 0) then
|
131
|
+
tbl[i] = 0
|
132
|
+
else
|
133
|
+
tbl[i] = 1
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
local result = tbl_to_number(tbl)
|
138
|
+
if ... then
|
139
|
+
local args = {...}
|
140
|
+
local n = table.remove(args, 1)
|
141
|
+
return bit_and(result, n, #args > 0 and args or nil)
|
142
|
+
else
|
143
|
+
return result
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
local function bit_not(n)
|
148
|
+
|
149
|
+
local tbl = to_bits(n)
|
150
|
+
local size = math.max(table.getn(tbl), 32)
|
151
|
+
for i = 1, size do
|
152
|
+
if(tbl[i] == 1) then
|
153
|
+
tbl[i] = 0
|
154
|
+
else
|
155
|
+
tbl[i] = 1
|
156
|
+
end
|
157
|
+
end
|
158
|
+
return tbl_to_number(tbl)
|
159
|
+
end
|
160
|
+
|
161
|
+
local function bit_xor(m, n)
|
162
|
+
local tbl_m = to_bits(m)
|
163
|
+
local tbl_n = to_bits(n)
|
164
|
+
expand(tbl_m, tbl_n)
|
165
|
+
|
166
|
+
local tbl = {}
|
167
|
+
local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))
|
168
|
+
for i = 1, rslt do
|
169
|
+
if(tbl_m[i] ~= tbl_n[i]) then
|
170
|
+
tbl[i] = 1
|
171
|
+
else
|
172
|
+
tbl[i] = 0
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
--table.foreach(tbl, print)
|
177
|
+
|
178
|
+
return tbl_to_number(tbl)
|
179
|
+
end
|
180
|
+
|
181
|
+
local function bit_rshift(n, bits)
|
182
|
+
check_int(n)
|
183
|
+
|
184
|
+
local high_bit = 0
|
185
|
+
if(n < 0) then
|
186
|
+
-- negative
|
187
|
+
n = bit_not(math.abs(n)) + 1
|
188
|
+
high_bit = 2147483648 -- 0x80000000
|
189
|
+
end
|
190
|
+
|
191
|
+
for i=1, bits do
|
192
|
+
n = n/2
|
193
|
+
n = bit_or(math.floor(n), high_bit)
|
194
|
+
end
|
195
|
+
return math.floor(n)
|
196
|
+
end
|
197
|
+
|
198
|
+
-- logic rightshift assures zero filling shift
|
199
|
+
local function bit_logic_rshift(n, bits)
|
200
|
+
check_int(n)
|
201
|
+
if(n < 0) then
|
202
|
+
-- negative
|
203
|
+
n = bit_not(math.abs(n)) + 1
|
204
|
+
end
|
205
|
+
for i=1, bits do
|
206
|
+
n = n/2
|
207
|
+
end
|
208
|
+
return math.floor(n)
|
209
|
+
end
|
210
|
+
|
211
|
+
local function bit_lshift(n, bits)
|
212
|
+
check_int(n)
|
213
|
+
|
214
|
+
if(n < 0) then
|
215
|
+
-- negative
|
216
|
+
n = bit_not(math.abs(n)) + 1
|
217
|
+
end
|
218
|
+
|
219
|
+
for i=1, bits do
|
220
|
+
n = n*2
|
221
|
+
end
|
222
|
+
return bit_and(n, 4294967295) -- 0xFFFFFFFF
|
223
|
+
end
|
224
|
+
|
225
|
+
local function bit_xor2(m, n)
|
226
|
+
local rhs = bit_or(bit_not(m), bit_not(n))
|
227
|
+
local lhs = bit_or(m, n)
|
228
|
+
local rslt = bit_and(lhs, rhs)
|
229
|
+
return rslt
|
230
|
+
end
|
231
|
+
|
232
|
+
--------------------
|
233
|
+
-- bit lib interface
|
234
|
+
|
235
|
+
wax.bit = {
|
236
|
+
-- bit operations
|
237
|
+
bnot = bit_not,
|
238
|
+
band = bit_and,
|
239
|
+
bor = bit_or,
|
240
|
+
bxor = bit_xor,
|
241
|
+
brshift = bit_rshift,
|
242
|
+
blshift = bit_lshift,
|
243
|
+
bxor2 = bit_xor2,
|
244
|
+
blogic_rshift = bit_logic_rshift,
|
245
|
+
|
246
|
+
-- utility func
|
247
|
+
tobits = to_bits,
|
248
|
+
tonumb = tbl_to_number,
|
249
|
+
}
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
--[[
|
254
|
+
for i = 1, 100 do
|
255
|
+
for j = 1, 100 do
|
256
|
+
if(bit.bxor(i, j) ~= bit.bxor2(i, j)) then
|
257
|
+
error("bit.xor failed.")
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
--]]
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|