@thigasdevelopment/luam 0.17.0 → 0.18.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 CHANGED
@@ -232,7 +232,7 @@ name = 'my-resource'
232
232
  serverPath = 'C:/MTA Server'
233
233
  ```
234
234
 
235
- Optional fields cover `meta.xml` info, `compilerOptions`, `sources`, `assets`,
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`.
@@ -262,16 +262,22 @@ VSCodium and Windsurf. The language server itself is editor-agnostic and speaks
262
262
 
263
263
  ## Known limitations
264
264
 
265
- - **No type narrowing.** `if value ~= nil then` does not refine `string?`.
266
- - **Declaration order matters for classes within a file.**
265
+ - **Narrowing reaches names, not fields.** `if value ~= nil then` refines a local;
266
+ `self.value` keeps its declared type however you test it.
267
+ - **A class is a type everywhere, a value from its declaration** — `extends` may
268
+ name a parent written further down, a top-level `new` may not.
267
269
  - **The MTA catalog can lag a release** — a newer function stays `any`.
268
270
  - **No static members, declared metamethods, or generic classes.**
269
- - **The editor does not re-check an open file when another one changes.**
271
+ - **The editor re-checks by declaration** a declaration change re-analyzes every
272
+ file that can see it, an edit inside a function body only its own file.
270
273
  - **An export is named, never verified** against the side that calls it.
274
+ - **Type annotations are erased**, so validate anything a client can send.
271
275
 
272
276
  > [Limitations](https://thigasdevelopment.github.io/luam/en/reference/limitations)
273
277
  > · [Limitações](https://thigasdevelopment.github.io/luam/pt-br/reference/limitations)
274
- > — with the workaround for each.
278
+ > — each one labelled planned, design boundary, upstream or platform constraint,
279
+ > with the workaround. The decisions behind the boundaries are recorded in
280
+ > [`docs/adr`](docs/adr).
275
281
 
276
282
  ---
277
283
 
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
- if classes[name] then
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
- local definition = {
33
- __name = name,
34
- __super = options.super,
35
- __metamethods = options.metamethods,
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) == 'function' and type(inherited) == 'function' then
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 = classes[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
- return classes
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
- return classes[name]
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