-
-
Notifications
You must be signed in to change notification settings - Fork 43
feat: Callable unstructs and disarrays #1584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
615b4d8
e3e3289
414a45b
0a27975
bcbdf95
e9926e9
84e9f6d
29d9adf
f1db795
daa54c9
86ce21a
b873cb0
109bda7
bdd0065
e5e4d9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,27 @@ | ||
| import { formatToWGSLType } from './vertexFormatData.ts'; | ||
|
|
||
| /** | ||
| * A wrapper for `schema(item)` call. | ||
| * A wrapper for `schema(item)` or `schema()` call. | ||
| * If the schema is a TgpuVertexFormatData, it instead calls the corresponding constructible schema. | ||
| * Throws an error if the schema is not callable. | ||
| */ | ||
| export function schemaCloneWrapper<T>(schema: unknown, item: T): T { | ||
| export function schemaCallWrapper<T>(schema: unknown, item?: T): T { | ||
| const maybeType = (schema as { type: string })?.type; | ||
|
|
||
| try { | ||
| return (schema as unknown as ((item: T) => T))(item); | ||
| } catch { | ||
| const maybeType = (schema as { type: string })?.type; | ||
| // TgpuVertexFormatData are not callable | ||
| const callSchema = (maybeType in formatToWGSLType | ||
| ? formatToWGSLType[maybeType as keyof typeof formatToWGSLType] | ||
| : schema) as unknown as ((item?: T) => T); | ||
| if (item === undefined) { | ||
| return callSchema(); | ||
| } | ||
|
Comment on lines
+17
to
+19
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say the error is correct. Calling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return callSchema(item); | ||
| } catch (e) { | ||
| throw new Error( | ||
| `Schema of type ${ | ||
| maybeType ?? '<unknown>' | ||
| } is not callable or was called with invalid arguments.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A wrapper for `schema()` call. | ||
| * Throws an error if the schema is not callable. | ||
| */ | ||
| export function schemaDefaultWrapper<T>(schema: unknown): T { | ||
| try { | ||
| return (schema as unknown as (() => T))(); | ||
| } catch { | ||
| const maybeType = (schema as { type: string })?.type; | ||
| throw new Error( | ||
| `Schema of type ${maybeType ?? '<unknown>'} is not callable.`, | ||
| ); | ||
| } | ||
| } | ||

Uh oh!
There was an error while loading. Please reload this page.