UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

55 lines 3.17 kB
/** * In a `Map`, you can use the `clear` method to delete every element. However, in a `LuaMap`, the * `clear` method does not exist. Use this helper function as a drop-in replacement for this. */ export declare function clearTable(luaMap: LuaMap<AnyNotNil, unknown>): void; /** Helper function to copy specific values from a userdata object (e.g. `Vector`) to a table. */ export declare function copyUserdataValuesToTable(object: unknown, keys: readonly string[], luaMap: LuaMap<string, unknown>): void; /** * Helper function to safely get boolean values from a Lua table. Will throw an error if the * specific value does not exist on the table. * * This function is variadic, meaning that you can specify N arguments to get N values. */ export declare function getBooleansFromTable(luaMap: LuaMap<string, unknown>, objectName: string, ...keys: readonly string[]): readonly boolean[]; /** * Helper function to safely get number values from specific keys on a Lua table. If the values are * strings, they will be converted to numbers. Will throw an error if the specific value does not * exist on the table or if it cannot be converted to a number. * * This function is variadic, meaning that you can specify N arguments to get N values. */ export declare function getNumbersFromTable(luaMap: LuaMap<string, unknown>, objectName: string, ...keys: readonly string[]): readonly number[]; /** * Helper function to safely get string values from a Lua table. Will throw an error if the specific * value does not exist on the table. * * This function is variadic, meaning that you can specify N arguments to get N values. */ export declare function getStringsFromTable(luaMap: LuaMap<string, unknown>, objectName: string, ...keys: readonly string[]): readonly string[]; /** Helper function to check if a Lua table has 0 keys. */ export declare function isTableEmpty(luaMap: LuaMap<AnyNotNil, unknown>): boolean; /** * Helper function to iterate over a table deterministically. This is useful because by default, the * `pairs` function will return the keys of a Lua table in a random order. * * This function will sort the table entries based on the value of the key. * * This function will only work on tables that have number keys or string keys. It will throw a * run-time error if it encounters a key of another type. * * @param luaMap The table to iterate over. * @param func The function to run for each iteration. * @param inOrder Optional. Whether to iterate in order. True by default. You can dynamically set to * false in situations where iterating randomly would not matter and you need the * extra performance. */ export declare function iterateTableInOrder<K extends AnyNotNil, V>(luaMap: LuaMap<K, V>, func: (key: K, value: V) => void, inOrder?: boolean): void; /** * Helper function to check if a Lua table has all of the provided keys. * * This function is variadic, meaning that you can specify as many arguments as you want to check * for. */ export declare function tableHasKeys(luaMap: LuaMap<AnyNotNil, unknown>, ...keys: readonly string[]): boolean; //# sourceMappingURL=table.d.ts.map