1.0.1 • Published 10 months ago

@ts-defold/tstl-userdata-sugar v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
10 months ago

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<T> & 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.

declare type UserDataArray<T> = Array<T> & LuaUserdata & {
};

declare function makeUserData(): UserDataArray<number>;

const userData: UserDataArray<number> = makeUserData();
console.log([...userData]);
1.0.1

10 months ago

1.0.0

3 years ago

0.1.0

4 years ago

0.0.1

4 years ago