@thigasdevelopment/luam 0.17.0 → 0.18.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.
- package/README.md +26 -7
- package/lua/class.lua +79 -15
- package/luam.mjs +1192 -888
- package/package.json +1 -1
- package/template/luam.manifest +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ class Luam {
|
|
|
44
44
|
end
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
local luam = new Luam('0.
|
|
47
|
+
local luam = new Luam('0.18.0')
|
|
48
48
|
|
|
49
49
|
outputServerLog(luam:compile('src/server/main.luam'))
|
|
50
50
|
```
|
|
@@ -232,7 +232,7 @@ name = 'my-resource'
|
|
|
232
232
|
serverPath = 'C:/MTA Server'
|
|
233
233
|
```
|
|
234
234
|
|
|
235
|
-
Optional fields cover `meta.xml` info, `
|
|
235
|
+
Optional fields cover `meta.xml` info, `compiler`, `sources`, `assets`,
|
|
236
236
|
`dependencies`, `engine.minVersion`, `environment`, `outDir`, `loadOrder`,
|
|
237
237
|
`output`, `helpers`, `resourcesDir`, `development.logs` and
|
|
238
238
|
`development.server.executable`.
|
|
@@ -248,7 +248,20 @@ Optional fields cover `meta.xml` info, `compilerOptions`, `sources`, `assets`,
|
|
|
248
248
|
The **Luam** VS Code extension runs a language server built on the same frontend
|
|
249
249
|
as the CLI, so the editor and the build never disagree: syntax highlighting,
|
|
250
250
|
diagnostics on every keystroke, scoped completion, hover types, go to
|
|
251
|
-
definition, find references and rename.
|
|
251
|
+
definition, find references and rename. It ships the `Luam Dark` and
|
|
252
|
+
`Luam Light` themes — pick one under **File → Preferences → Theme → Color
|
|
253
|
+
Theme**:
|
|
254
|
+
|
|
255
|
+
<table>
|
|
256
|
+
<tr>
|
|
257
|
+
<td><img src="assets/theme-luam-dark.svg" alt="The README example highlighted by the Luam Dark theme" width="100%"></td>
|
|
258
|
+
<td><img src="assets/theme-luam-light.svg" alt="The README example highlighted by the Luam Light theme" width="100%"></td>
|
|
259
|
+
</tr>
|
|
260
|
+
<tr>
|
|
261
|
+
<td align="center"><sub><b>Luam Dark</b></sub></td>
|
|
262
|
+
<td align="center"><sub><b>Luam Light</b></sub></td>
|
|
263
|
+
</tr>
|
|
264
|
+
</table>
|
|
252
265
|
|
|
253
266
|
Supported and auto-installed by `luam setup`: VS Code, VS Code Insiders, Cursor,
|
|
254
267
|
VSCodium and Windsurf. The language server itself is editor-agnostic and speaks
|
|
@@ -262,16 +275,22 @@ VSCodium and Windsurf. The language server itself is editor-agnostic and speaks
|
|
|
262
275
|
|
|
263
276
|
## Known limitations
|
|
264
277
|
|
|
265
|
-
- **
|
|
266
|
-
|
|
278
|
+
- **Narrowing reaches names, not fields.** `if value ~= nil then` refines a local;
|
|
279
|
+
`self.value` keeps its declared type however you test it.
|
|
280
|
+
- **A class is a type everywhere, a value from its declaration** — `extends` may
|
|
281
|
+
name a parent written further down, a top-level `new` may not.
|
|
267
282
|
- **The MTA catalog can lag a release** — a newer function stays `any`.
|
|
268
283
|
- **No static members, declared metamethods, or generic classes.**
|
|
269
|
-
- **The editor
|
|
284
|
+
- **The editor re-checks by declaration** — a declaration change re-analyzes every
|
|
285
|
+
file that can see it, an edit inside a function body only its own file.
|
|
270
286
|
- **An export is named, never verified** against the side that calls it.
|
|
287
|
+
- **Type annotations are erased**, so validate anything a client can send.
|
|
271
288
|
|
|
272
289
|
> [Limitations](https://thigasdevelopment.github.io/luam/en/reference/limitations)
|
|
273
290
|
> · [Limitações](https://thigasdevelopment.github.io/luam/pt-br/reference/limitations)
|
|
274
|
-
> —
|
|
291
|
+
> — each one labelled planned, design boundary, upstream or platform constraint,
|
|
292
|
+
> with the workaround. The decisions behind the boundaries are recorded in
|
|
293
|
+
> [`docs/adr`](docs/adr).
|
|
275
294
|
|
|
276
295
|
---
|
|
277
296
|
|
package/lua/class.lua
CHANGED
|
@@ -24,21 +24,69 @@ local function bindSuper(value, inherited)
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
local function bindLateSuper(definition, key, value)
|
|
28
|
+
return function(self, ...)
|
|
29
|
+
local inherited = definition.__super and definition.__super[key]
|
|
30
|
+
|
|
31
|
+
if type(inherited) ~= 'function' then
|
|
32
|
+
return value(self, ...)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
return bindSuper(value, inherited)(self, ...)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
local function declare(name)
|
|
40
|
+
local existing = classes[name]
|
|
41
|
+
|
|
42
|
+
if existing then
|
|
43
|
+
return existing
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
local definition = { __name = name, __pending = true }
|
|
47
|
+
|
|
48
|
+
classes[name] = definition
|
|
49
|
+
|
|
50
|
+
return definition
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
local function pendingAncestor(definition)
|
|
54
|
+
local current = definition.__super
|
|
55
|
+
|
|
56
|
+
while current do
|
|
57
|
+
if current.__pending then
|
|
58
|
+
return current.__name
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
current = current.__super
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
return nil
|
|
65
|
+
end
|
|
66
|
+
|
|
27
67
|
local function create(name, struct, options)
|
|
28
|
-
|
|
68
|
+
local definition = classes[name]
|
|
69
|
+
|
|
70
|
+
if definition and not definition.__pending then
|
|
29
71
|
error('Class ' .. tostring(name) .. ' already exists.')
|
|
30
72
|
end
|
|
31
73
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
74
|
+
definition = definition or { __name = name }
|
|
75
|
+
|
|
76
|
+
definition.__pending = nil
|
|
77
|
+
definition.__super = options.super
|
|
78
|
+
definition.__metamethods = options.metamethods
|
|
79
|
+
|
|
80
|
+
local pending = definition.__super and definition.__super.__pending
|
|
37
81
|
|
|
38
82
|
for key, value in pairs(struct) do
|
|
39
83
|
local inherited = definition.__super and definition.__super[key]
|
|
40
84
|
|
|
41
|
-
if type(value)
|
|
85
|
+
if type(value) ~= 'function' then
|
|
86
|
+
definition[key] = value
|
|
87
|
+
elseif pending then
|
|
88
|
+
definition[key] = bindLateSuper(definition, key, value)
|
|
89
|
+
elseif type(inherited) == 'function' then
|
|
42
90
|
definition[key] = bindSuper(value, inherited)
|
|
43
91
|
else
|
|
44
92
|
definition[key] = value
|
|
@@ -59,11 +107,7 @@ function class(name)
|
|
|
59
107
|
|
|
60
108
|
local modifiers = {
|
|
61
109
|
extends = function(self, super)
|
|
62
|
-
options.super =
|
|
63
|
-
|
|
64
|
-
if not options.super then
|
|
65
|
-
error('Class ' .. tostring(name) .. ' extends ' .. tostring(super) .. ', which is not defined.')
|
|
66
|
-
end
|
|
110
|
+
options.super = declare(super)
|
|
67
111
|
|
|
68
112
|
return self
|
|
69
113
|
end,
|
|
@@ -131,13 +175,19 @@ end
|
|
|
131
175
|
function new(name)
|
|
132
176
|
local definition = classes[name]
|
|
133
177
|
|
|
134
|
-
if not definition then
|
|
178
|
+
if not definition or definition.__pending then
|
|
135
179
|
error('Class ' .. tostring(name) .. ' is not defined.')
|
|
136
180
|
end
|
|
137
181
|
|
|
138
182
|
local constructor = constructors[definition]
|
|
139
183
|
|
|
140
184
|
if not constructor then
|
|
185
|
+
local missing = pendingAncestor(definition)
|
|
186
|
+
|
|
187
|
+
if missing then
|
|
188
|
+
error('Class ' .. tostring(name) .. ' extends ' .. tostring(missing) .. ', which is not defined.')
|
|
189
|
+
end
|
|
190
|
+
|
|
141
191
|
constructor = createConstructor(definition)
|
|
142
192
|
constructors[definition] = constructor
|
|
143
193
|
end
|
|
@@ -170,9 +220,23 @@ function enum(names)
|
|
|
170
220
|
end
|
|
171
221
|
|
|
172
222
|
function getClasses()
|
|
173
|
-
|
|
223
|
+
local defined = {}
|
|
224
|
+
|
|
225
|
+
for name, definition in pairs(classes) do
|
|
226
|
+
if not definition.__pending then
|
|
227
|
+
defined[name] = definition
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
return defined
|
|
174
232
|
end
|
|
175
233
|
|
|
176
234
|
function getClass(name)
|
|
177
|
-
|
|
235
|
+
local definition = classes[name]
|
|
236
|
+
|
|
237
|
+
if not definition or definition.__pending then
|
|
238
|
+
return nil
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
return definition
|
|
178
242
|
end
|