Skip to content

Conversation

@daosgava
Copy link

@daosgava daosgava commented May 11, 2025

Description

Add support for generating C# WebAssembly bindings and JavaScript method names.

Details

  • Introduced a new translator class CSharpWasm to generate C# bindings compatible with WebAssembly.
  • Implemented logic to filter and convert only primitive-type functions into valid C# partial methods.
  • Outputs SplashKit.Generated.cs, which includes method signatures for WASM interop.
  • Added generation of splashKitMethods.generated.js, which exports a list of available function names in snake_case format.
  • Both files are placed in generated/csharpwasm/ as part of the build output.

Command

docker compose run --rm headerdoc csharpwasm

Notes

Once the translator is fetched as a submodule into splashkit-core, it should generate the files in generated/csharpwasm.

Screenshot 2025-05-11 at 10 07 00 PM

Sample of SplashKit.Generated.cs

using System.Runtime.InteropServices.JavaScript;

namespace SplashKitSDK
{
    public partial class SplashKit
    {
        [JSImport("SplashKitBackendWASM.free_all_animation_scripts", "main.js")]
        public static partial void FreeAllAnimationScripts();

        [JSImport("SplashKitBackendWASM.free_animation_script", "main.js")]
        public static partial void FreeAnimationScript(string name);

        [JSImport("SplashKitBackendWASM.has_animation_script", "main.js")]
        public static partial bool HasAnimationScript(string name);

        [JSImport("SplashKitBackendWASM.audio_ready", "main.js")]
        public static partial bool AudioReady();
        ...

Sample of splashKitMethods.generated.js

const methods = `
  accept_all_new_connections,
  accept_new_connection,
  add_column,
  add_column_relative,
  alpha_of,
  angle_between,
  animation_count,
  animation_current_cell,
  animation_current_vector,
...

The two generated files need to be copied into the SplashKitOnline repo.

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.

2 participants