Skip to content
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

Refactor Casting and support arrays #30

Merged
merged 1 commit into from
Oct 15, 2024
Merged

Refactor Casting and support arrays #30

merged 1 commit into from
Oct 15, 2024

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented Oct 10, 2024

Refactors casting a bit. Fixes a bug where arrays were not being cast correctly. I think this won't really scale to more complex types and we should consider a dependency to handle this or code up a more runtime dependent solution. But for now i'm aiming to get it working well for the simple cases. Still have some tests to do.

@bhelx bhelx force-pushed the array-cast-2 branch 2 times, most recently from e4a4fab to 210068d Compare October 10, 2024 15:59
@bhelx bhelx changed the title Array cast 2 Refactor Casting and support arrays Oct 10, 2024
Refactors casting a bit. Fixes a bug where arrays were not being cast
correctly. I think this won't really scale to more complex types and we
should consider a dependency to handle this or code up a more
runtime dependent solution. But for now i'm aiming to
get it working well for the simple cases. Still have some tests to do.
@bhelx
Copy link
Contributor Author

bhelx commented Oct 10, 2024

Will merge with dylibso/xtp-bindgen-test#16

@bhelx bhelx marked this pull request as ready for review October 11, 2024 20:13
@bhelx
Copy link
Contributor Author

bhelx commented Oct 14, 2024

Actually will follow up with dylibso/xtp-bindgen-test#16 because i need to port to other languages.

@bhelx bhelx requested a review from nilslice October 14, 2024 16:29
return v === undefined || v === null
}

function cast(caster: (v: any) => any, v: any): any {
Copy link
Contributor Author

@bhelx bhelx Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast can apply caster to any value. If the value is an array, then it will apply caster to every value and return a new array. this saves us from having to put this logic into the codegen. However i don't think this will scale to all use cases.

@bhelx bhelx merged commit 2c8aaf7 into main Oct 15, 2024
3 checks passed
@bhelx bhelx deleted the array-cast-2 branch October 15, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant