https://github.com/ts-defold/tstl-userdata-sugar
TypeScriptToLua plugin that provides syntax sugar for Userdata types in lua
https://github.com/ts-defold/tstl-userdata-sugar
lua typescript typings
Last synced: 6 months ago
JSON representation
TypeScriptToLua plugin that provides syntax sugar for Userdata types in lua
- Host: GitHub
- URL: https://github.com/ts-defold/tstl-userdata-sugar
- Owner: ts-defold
- License: mit
- Created: 2020-10-28T16:28:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T13:31:52.000Z (about 2 years ago)
- Last Synced: 2025-03-26T13:38:37.526Z (6 months ago)
- Topics: lua, typescript, typings
- Language: TypeScript
- Homepage: https://ts-defold.dev
- Size: 320 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tstl-userdata-sugar
![]()
> TypeScriptToLua plugin that provides syntax sugar for Userdata types in lua## Features
### `...` => unpack
Support array-like user data object destructuring.
> Lua's `unpack` function only supports unpacking tables, even if the required metamethods of `__index` and `__len` are present to treat them like an array.To support this feature we detect a `...` of an `Array` & `LuaUserdata` type and implicitly inject a call to `map(x => x)`. This then returns a table from the userdata and passes it to unpack. There may exist more efficient methods of unpacking your array data directly from the userdata type, and you may want to avoid this syntax sugar if moving large amounts of data.
```ts
declare type UserDataArray = Array & LuaUserdata & {
};declare function makeUserData(): UserDataArray;
const userData: UserDataArray = makeUserData();
console.log([...userData]);
```