awlck / frankendrift

Cross-platform frontend for the ADRIFT Runner
MIT License
8 stars 1 forks source link

Glk opaque types #40

Closed awlck closed 1 year ago

awlck commented 1 year ago

Use structs to represent Glk opaque types, rather than using IntPtr everywhere.

Part of #38.

(@curiousdannii I'd formally request a review but GitHub is being dense again.)

curiousdannii commented 1 year ago

It looks okay, I think. My only concern is whether the new structs will collapse down to IntPtrs for JS interop, or whether they'll be some other object. In other words, whether they're newtypes or wrapper types that have a different memory structure. I've read a little that makes it seem like this kind of record structs are basically newtypes.

FYI, the supported types for JS interop are listed in a table here: https://learn.microsoft.com/en-us/aspnet/core/client-side/dotnet-interop?view=aspnetcore-7.0#javascript-interop-on-

awlck commented 1 year ago

I've read a little that makes it seem like this kind of record structs are basically newtypes.

I'm not sure in this context. Single-member structs decay when calling native functions because of how the runtime stores structs (the info that those eight bytes represent, say, a WindowHandle is stored elsewhere, so we can pass a WindowHandle to a native function as if it were a plain IntPtr), but for JS I'd sort of expect it to create a JS object at the transition.

But I guess the WASM/JS implementation of IGlk can unwrap and re-wrap the raw IntPtrs if those are what the JS code expects.

curiousdannii commented 1 year ago

Yes of course! If they won't auto-marshall I can just unwrap them manually. No reason not to merge this PR then.

IntPtrs are only 4 bytes aren't they?

awlck commented 1 year ago

They're the size of a pointer on the platform, so yes, they're 4 bytes on WebAssembly (at least for now).

Dannii Willis @.***> schrieb am So. 26. Feb. 2023 um 22:28:

Yes of course! If they won't auto-marshall I can just unwrap them manually. No reason not to merge this PR then.

IntPtrs are only 4 bytes aren't they?

— Reply to this email directly, view it on GitHub https://github.com/awlck/frankendrift/pull/40#issuecomment-1445471931, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADC2UMXB2BB7BGHEREY6HLTWZPDGHANCNFSM6AAAAAAVIO3IYA . You are receiving this because you authored the thread.Message ID: @.***>