-
Notifications
You must be signed in to change notification settings - Fork 233
Open
Description
cc @bytecodealliance/dotnet-core
As part of the future work, I'm was trying to tidy up the location of the import and export methods. At present we have this for the import-export-same-func.wit
codegen test
// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT!
// <auto-generated />
#nullable enable
namespace MyWorldWorld {
public interface IMyWorldWorld {
static abstract void Purple();
}
namespace exports {
public static class MyWorldWorld
{
internal static class PurpleWasmInterop
{
[global::System.Runtime.InteropServices.DllImportAttribute("$root", EntryPoint = "purple"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern void wasmImportPurple();
}
public static unsafe void Purple()
{
PurpleWasmInterop.wasmImportPurple();
}
[global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "purple")]
public static unsafe void wasmExportPurple() {
MyWorldWorldImpl.Purple();
}
}
}
}
As you can see the user facting imported function is in the exports
namespace, but the imported function is in the interface IMyWorldWorld
. This has the advantage that they can have the same name without a conflict but is not very symmetrical or intuitive. I propose to change this to
// Generated by `wit-bindgen` 0.44.0. DO NOT EDIT!
// <auto-generated />
#nullable enable
namespace MyWorldWorld {
public interface IMyWorldWorld {
public interface Exports
{
public static unsafe void Purple()
{
exports.MyWorldWorldInterop.PurpleWasmInterop.wasmImportPurple();
}
}
public interface Imports
{
static abstract void Purple();
}
}
namespace exports {
public static class MyWorldWorldInterop
{
internal static class PurpleWasmInterop
{
[global::System.Runtime.InteropServices.DllImportAttribute("$root", EntryPoint = "purple"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern void wasmImportPurple();
}
[global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "purple")]
public static unsafe void wasmExportPurple() {
MyWorldWorldImpl.Purple();
}
}
}
}
Where both the import and export are in the interface, but separated to avoid name conflicts by nested interfaces, Imports
and Exports
.
Does this sound bad to anyone?
jsturtevant
Metadata
Metadata
Assignees
Labels
No labels