@@ -88,6 +88,13 @@ declare type LuaIterable<TValue, TState = undefined> = Iterable<TValue> &
8888declare type LuaPairsIterable < TKey extends AnyNotNil , TValue > = Iterable < [ TKey , TValue ] > &
8989 LuaExtension < "__luaPairsIterableBrand" > ;
9090
91+ /**
92+ * Represents an object that can be iterated with pairs(), where only the key value is used.
93+ *
94+ * @param TKey The type of the key returned each iteration.
95+ */
96+ declare type LuaPairsKeyIterable < TKey extends AnyNotNil > = Iterable < TKey > & LuaExtension < "__luaPairsKeyIterableBrand" > ;
97+
9198/**
9299 * Calls to functions with this type are translated to `left + right`.
93100 * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
@@ -500,6 +507,24 @@ declare type LuaTableSet<TTable extends AnyTable, TKey extends AnyNotNil, TValue
500507declare type LuaTableSetMethod < TKey extends AnyNotNil , TValue > = ( ( key : TKey , value : TValue ) => void ) &
501508 LuaExtension < "__luaTableSetMethodBrand" > ;
502509
510+ /**
511+ * Calls to functions with this type are translated to `table[key] = true`.
512+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
513+ *
514+ * @param TTable The type to access as a Lua table.
515+ * @param TKey The type of the key to use to access the table.
516+ */
517+ declare type LuaTableAddKey < TTable extends AnyTable , TKey extends AnyNotNil > = ( ( table : TTable , key : TKey ) => void ) &
518+ LuaExtension < "__luaTableAddKeyBrand" > ;
519+
520+ /**
521+ * Calls to methods with this type are translated to `table[key] = true`, where `table` is the object with the method.
522+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
523+ * @param TKey The type of the key to use to access the table.
524+ */
525+ declare type LuaTableAddKeyMethod < TKey extends AnyNotNil > = ( ( key : TKey ) => void ) &
526+ LuaExtension < "__luaTableAddKeyMethodBrand" > ;
527+
503528/**
504529 * Calls to functions with this type are translated to `table[key] ~= nil`.
505530 * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
@@ -574,3 +599,69 @@ declare type LuaTableConstructor = (new <TKey extends AnyNotNil = AnyNotNil, TVa
574599 * @param TValue The type of the values stored in the table.
575600 */
576601declare const LuaTable : LuaTableConstructor ;
602+
603+ /**
604+ * A convenience type for working directly with a Lua table, used as a map.
605+ *
606+ * This differs from LuaTable in that the `get` method may return `nil`.
607+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
608+ * @param K The type of the keys used to access the table.
609+ * @param V The type of the values stored in the table.
610+ */
611+ declare interface LuaMap < K extends AnyNotNil = AnyNotNil , V = any > extends LuaPairsIterable < K , V > {
612+ get : LuaTableGetMethod < K , V | undefined > ;
613+ set : LuaTableSetMethod < K , V > ;
614+ has : LuaTableHasMethod < K > ;
615+ delete : LuaTableDeleteMethod < K > ;
616+ }
617+
618+ /**
619+ * A convenience type for working directly with a Lua table, used as a map.
620+ *
621+ * This differs from LuaTable in that the `get` method may return `nil`.
622+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
623+ * @param K The type of the keys used to access the table.
624+ * @param V The type of the values stored in the table.
625+ */
626+ declare const LuaMap : ( new < K extends AnyNotNil = AnyNotNil , V = any > ( ) => LuaMap < K , V > ) &
627+ LuaExtension < "__luaTableNewBrand" > ;
628+
629+ /**
630+ * Readonly version of {@link LuaMap}.
631+ *
632+ * @param K The type of the keys used to access the table.
633+ * @param V The type of the values stored in the table.
634+ */
635+ declare interface LuaReadonlyMap < K extends AnyNotNil = AnyNotNil , V = any > extends LuaPairsIterable < K , V > {
636+ get : LuaTableGetMethod < K , V > ;
637+ has : LuaTableHasMethod < K > ;
638+ }
639+
640+ /**
641+ * A convenience type for working directly with a Lua table, used as a set.
642+ *
643+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
644+ * @param T The type of the keys used to access the table.
645+ */
646+ declare interface LuaSet < T extends AnyNotNil = AnyNotNil > extends LuaPairsKeyIterable < T > {
647+ add : LuaTableAddKeyMethod < T > ;
648+ has : LuaTableHasMethod < T > ;
649+ delete : LuaTableDeleteMethod < T > ;
650+ }
651+
652+ /**
653+ * A convenience type for working directly with a Lua table, used as a set.
654+ *
655+ * For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
656+ * @param T The type of the keys used to access the table.
657+ */
658+ declare const LuaSet : ( new < T extends AnyNotNil = AnyNotNil > ( ) => LuaSet < T > ) & LuaExtension < "__luaTableNewBrand" > ;
659+
660+ /**
661+ * Readonly version of {@link LuaSet}.
662+ *
663+ * @param T The type of the keys used to access the table.
664+ */
665+ declare interface LuaReadonlySet < T extends AnyNotNil = AnyNotNil > extends LuaPairsKeyIterable < T > {
666+ has : LuaTableHasMethod < T > ;
667+ }
0 commit comments