You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lua supports overloading operators on types using [metatable methods](https://www.lua.org/manual/5.4/manual.html#2.4) such as `__add`. But, JavaScript and TypeScript do not support this. In order to use overloaded operators on types that support them, you can declare special mapping functions in TS that will translate to those operators in Lua.
@@ -343,6 +364,14 @@ end
343
364
344
365
(Remember that in Lua, `pairs()` returns the keys in a random order.)
345
366
367
+
### `LuaMap` and `LuaSet`
368
+
369
+
Similar to `LuaTable`, the `LuaMap` and `LuaSet` types are provided to represent Lua tables used as a map or set. These are much more performant than the `Set`/`Map` classes, but do not come with all the same features (such as guaranteed insertion order).
370
+
371
+
-`LuaMap` has the same methods as `LuaTable`, except that `table.get(key)` may also return `undefined`.
372
+
-`LuaSet`, instead of `table.get/table.set`, has `table.add(value)`, which translates to `table[value] = true`.
373
+
- There are also the readonly variants `ReadonlyLuaMap` and `ReadonlyLuaSet`.
374
+
346
375
### Custom Getters and Setters
347
376
348
377
If you have a type that uses non-string keys, you can use `LuaTableGet` and `LuaTableSet` function types to declare your own getters & setters, similar to [Operator Map Types](#operator-map-types).
0 commit comments