|
|
|
|
|
by valiant55
433 days ago
|
|
Neat, but with restrictions like no reference types and looking at the examples, they are far from idiomatic C# as to be almost indistinguishable from C I'm trying to figure out the motivation. Maybe it's "because you can" which is fine, but are there any advantages to this approach over using C directly? EDIT: I overlooked the reddit post and comments and jumped straight into the repo, it looks like the creator is on an insane quest to get C# to run anywhere haha, I didn't realize the C tanspiler was by the same author. |
|
So the code in the game example is very much a "port directly from the example C code to make sure it's possible and it works". The next step was to start looking at where things can be made more idiomatic.
For example, C# supports static methods in interfaces now. This means instead of passing function pointers around for things you can create a class that implements an interface and call `InitObjects<T>()` instead of `InitObjects(&initFunction, &updateFunction, null)`, and I think I can do that in a no overhead way.
There are some other ideas I have for making things more idiomatic, but I really wanted to make sure I had a working ROM first before I started mangling the examples and trying to figure out if it's my transpiler or my logic that's breaking things.
There is a limit to how idiomatic I can make it though. Since the SNES has limited memory, any stack variable you create risks accidentally overwriting other memory. So it seems like you want to limit how many stack variables you use, which ends up meaning storing things in pointers and globals when using them.
There are some other slight advantages, like better enums, but yeah. At the end of the day this is a usecase of my transpiler allowing C# to be used on non-standard platforms.