DefoldSharp
A downloadable tool
This tool is an ongoing effort. It was pushed to Alpha for the Jam, but it is not ready for production use. Additionally, I have specifically stated this tool does NOT qualify for any prizes from the Jam.
C# support for Defold is now in alpha! There is still LOTS to add, but most of the Defold API is covered. On building your C# project, your code is converted in to lua code and .script files created!
There are a quintet of repositories:
(I want to use it)
- RealityStop/DefoldSharp (github.com) - a C# api version of the Defold game engine API
- RealityStop/DefoldCSharpCompiler: The C# to Lua compiler (github.com) - a specialized variant of CSharp.lua that handles Defold-special operations
- RealityStop/DefoldSharpExamples (github.com) - examples and sample projects that demonstrate how to use DefoldSharp
The other two are only of interest for generating the API.
(I want to update it)
- RealityStop/DefoldAPIGen (github.com) - which can be used to generate DefoldSharp
- RealityStop/DefoldAPIRules (github.com) - the current set of rules DefoldAPIGen uses to customize and map to C#.
Caveats:
-optional parameters are still handled on a case-by-case basis. Many are missing.
- while custom messages designed in C# are fully supported, common message formats for the existing messages Defold already uses are not converted yet.
- The alpha focuses on a 1-1 conversion of the Defold API with a little sugar added. Improved support to make the API more C#-esque is a bit lower priority.
Also bugs. Lots of bugs.
Status | In development |
Category | Tool |
Author | Reality.Stop() |
Tags | c, compiler, defold, language, tool |
Development log
- Alpha 2 releasedOct 08, 2022
- Alpha 1 example projectOct 06, 2022
Comments
Log in with itch.io to leave a comment.
It's cool but I wonder why would anyone want to write C# instead of Lua for the same API access ?
I mean, if C# could be native instead of translation into Lua, directly connected to Defold Engine via a C++/C# bridge, then this could be more meaningful.
Good question!
And while (like a lot of open source) at some level it starts as simply a "why not?" mixed with a bit of personal interest, at some point there needs to be more to justify continued personal investment. So, I hope to give you a deeper answer, so this will be long because I think it deserves a longer answer. I'm not trying to attack your position, I think this is a question that needs to be answered fully.
I know my initial forays into this approach were simply seeing if it was possible and largely personal as I've used C# for 19 years, and over 15 of that was professionally. So that initial motivation is probably the same as that behind hxdefold and TS-Defold: a desire for a static-typed language compatibility for Defold that the author is more comfortable with. There's nothing wrong with lua! The beauty of lua and other dynamic languages is the freedom it offers without requiring really anything of the user. It's entirely possible to program a game in Defold and never really understand metatables, perhaps beyond some rote copy-paste for modules. Literally a beginner can learn everything that they need in hours to days (code-wise) and I think that cannot be stated enough.
It's just over the years I've come to value what a static-typed language brings as the project size grows. At some point, being able to track where variables are used, refactor and rename variables, group things logically, and shift as many errors to compile-time rather than having to discover the exceptions at runtime becomes more valuable to me personally. Maybe my brain just works differently, but I'm not alone in this.
And that's where we get to the more meaty stuff. My initial look to even see if this was possible was prompted by a discussion on GameFromScratch's discord, in which a number of users were discussing hobbyists and indies abandoning Unity in favor of other engines following several questionable actions on Unity's part this summer. Defold was mentioned as a possible alternative, but most users agreed that if anyone left Unity they'd probably go to Godot, given its similarities, large userbase, and support for C# (which Unity also uses). Several users chimed in that Defold's use of lua was the reason they weren't using it and had moved to other engines. Does this mean lua is bad? No, absolutely not, but it did make me wonder if C# was available, would they have stayed?
Defold obviously is a different class of engine from Unity, but how many other users bounced off Defold after looking at it and thinking it wasn't a serious option? Just like ts-defold offers a hook for users coming from javascript engines, I hope C# being offered is a hook for Unity/Godot developers. Even if it is just to give them a foothold of comfortableness to learn the lua side. To further cater to those users, DefoldSharp also has an OOP API that is being added in. You absolutely can use the regular Defold API if you wish, which should help when converting tutorials, but you don't have to. You can use more natural C# as well.
There's definitely some interest. I've had numerous people contact me to let me know they're interested, and the Defold developers have taken every opportunity to cheer me on and assist with any questions I have. Seriously, I can't thank them enough for their encouragement. Which has been quite refreshing, after reading Godot's primary development team ridicule and condescend C# users, despite them being 20% of their users.
Lastly, would something like this be better if it were directly loaded C#? Yes and no. On the one hand, there would be more direct control of performance, a better debugging experience, and so on. On the other hand, it would be immediately limited by runtimes and platform support. Right now, DefoldSharp doesn't have that issue, because it is NOT running C# and .NET, and ultimately adds zero dependencies and can integrate with other Defold extensions. It compiles down to the same API used by straight lua code. The extra OOP API I'm adding is just sugar.
And you kinda hit the nail on the head. This is a bit of a niche solution that a small subset of users might prefer. I don't want to tie up the main development team for months adding in a bridge and the runtimes, and working out the platform integrations, for something that at this point we frankly don't know will even be used much. At the end of the day, I think it's a perfect fit that this be created on the side as a community project. If there's sudden usage and overwhelming support, then that justifies the Defold development team effort and official support. But until then, their efforts are better focused on the engine and what it can do.
Very interesting! I look forward to futher development!