@tilua/compiler 3.1.0 → 5.0.0
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.
- package/README.md +122 -12
- package/dist/{chunk-VANZBLCL.js → chunk-3J2QMA4W.js} +699 -135
- package/dist/cli.cjs +764 -178
- package/dist/cli.js +32 -9
- package/dist/index.cjs +721 -156
- package/dist/index.d.cts +44 -6
- package/dist/index.d.ts +44 -6
- package/dist/index.js +6 -4
- package/package.json +2 -2
- package/runtime/array.luau +17 -9
- package/runtime/console.luau +227 -0
- package/runtime/object.luau +4 -4
- package/runtime/result.luau +122 -0
- package/runtime/string.luau +2 -2
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
local __NAME__ = {}
|
|
2
|
+
|
|
3
|
+
-- The globals whose Luau answer is several values, as tilua has them: one
|
|
4
|
+
-- value — an array, or an object. The compiler calls these instead of the
|
|
5
|
+
-- globals they stand for, and reading one of those globals as a value
|
|
6
|
+
-- (`local p = pcall`) gives the function here, so the two never disagree.
|
|
7
|
+
|
|
8
|
+
-- `pcall`'s `ok, ...` as `{ success, data, error }`. `data` is what the
|
|
9
|
+
-- function returned: one value, since a tilua function returns one.
|
|
10
|
+
local function result(ok, ...)
|
|
11
|
+
if ok then
|
|
12
|
+
return { success = true, data = (...) }
|
|
13
|
+
end
|
|
14
|
+
return { success = false, error = (...) }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
function __NAME__.pcall(f, ...)
|
|
18
|
+
return result(pcall(f, ...))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
function __NAME__.xpcall(f, handler, ...)
|
|
22
|
+
return result(xpcall(f, handler, ...))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
function __NAME__.resume(co, ...)
|
|
26
|
+
return result(coroutine.resume(co, ...))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
-- Several values as an array — or nil, when all there was is nil.
|
|
30
|
+
local function values(...)
|
|
31
|
+
if select("#", ...) <= 1 and (...) == nil then
|
|
32
|
+
return nil
|
|
33
|
+
end
|
|
34
|
+
return { ... }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
function __NAME__.find(s, pattern, init, plain)
|
|
38
|
+
return values(string.find(s, pattern, init, plain))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
function __NAME__.match(s, pattern, init)
|
|
42
|
+
return values(string.match(s, pattern, init))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
function __NAME__.gsub(s, pattern, replacement, n)
|
|
46
|
+
return (string.gsub(s, pattern, replacement, n))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
function __NAME__.byte(s, i, j)
|
|
50
|
+
if j == nil then
|
|
51
|
+
return (string.byte(s, i))
|
|
52
|
+
end
|
|
53
|
+
return { string.byte(s, i, j) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
function __NAME__.modf(x)
|
|
57
|
+
return { math.modf(x) }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
function __NAME__.frexp(x)
|
|
61
|
+
return { math.frexp(x) }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
function __NAME__.next(t, key)
|
|
65
|
+
local k, v = next(t, key)
|
|
66
|
+
if k == nil then
|
|
67
|
+
return nil
|
|
68
|
+
end
|
|
69
|
+
return { k, v }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
function __NAME__.select(n, ...)
|
|
73
|
+
if n == "#" then
|
|
74
|
+
return select("#", ...)
|
|
75
|
+
end
|
|
76
|
+
return { select(n, ...) }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
function __NAME__.unpack(list, i, j)
|
|
80
|
+
return { (table.unpack or unpack)(list, i or 1, j or #list) }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
-- `pairs(t)` and `ipairs(t)` as an iteration — `{ step, state, first }`,
|
|
84
|
+
-- which a loop walks with. Each step answers one `{ key, value }`, and is
|
|
85
|
+
-- handed the one before it.
|
|
86
|
+
local function pairsStep(t, previous)
|
|
87
|
+
local k, v = next(t, previous ~= nil and previous[1] or nil)
|
|
88
|
+
if k == nil then
|
|
89
|
+
return nil
|
|
90
|
+
end
|
|
91
|
+
return { k, v }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
function __NAME__.pairs(t)
|
|
95
|
+
return { pairsStep, t, nil }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
local function ipairsStep(t, previous)
|
|
99
|
+
local i = (previous ~= nil and previous[1] or 0) + 1
|
|
100
|
+
local v = t[i]
|
|
101
|
+
if v == nil then
|
|
102
|
+
return nil
|
|
103
|
+
end
|
|
104
|
+
return { i, v }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
function __NAME__.ipairs(t)
|
|
108
|
+
return { ipairsStep, t, nil }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
-- An iterator function: each call is one match's captures, as an array.
|
|
112
|
+
function __NAME__.gmatch(s, pattern)
|
|
113
|
+
local step = string.gmatch(s, pattern)
|
|
114
|
+
return function()
|
|
115
|
+
return values(step())
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
function __NAME__.loadstring(source, chunkname)
|
|
120
|
+
local f, message = loadstring(source, chunkname)
|
|
121
|
+
return { f, message }
|
|
122
|
+
end
|
package/runtime/string.luau
CHANGED
|
@@ -88,7 +88,7 @@ local function values(...)
|
|
|
88
88
|
if select("#", ...) <= 1 and (...) == nil then
|
|
89
89
|
return nil
|
|
90
90
|
end
|
|
91
|
-
return { ... }
|
|
91
|
+
return __ARRAY__({ ... })
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
function __NAME__.find(s, pattern, init, plain)
|
|
@@ -107,7 +107,7 @@ function __NAME__.byte(s, i, j)
|
|
|
107
107
|
if j == nil then
|
|
108
108
|
return (string.byte(s, i))
|
|
109
109
|
end
|
|
110
|
-
return { string.byte(s, i, j) }
|
|
110
|
+
return __ARRAY__({ string.byte(s, i, j) })
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
-- An iterator function: each call is one match's captures, as an array.
|