Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This has 3 commits can submit them separately or remove any not wanted but some of the lines were too close to avoid conflicts otherwise.
Most of these changes are minor, adding better MSVC debug flags, switching some char* to const char* when they are const. Adding names to the interface_bind function pointer. In addition to making things a bit more clear it assists autogeneration of the code with a tool like CPPSharp. More details on that below.
The final item that is here is adding a magic cookie to event structs. I dislike the idea of expanding the struct to include a memory check but it is one of two ways I thought to do this effectively. Events are only executed in serial one at a time and do not support callbacks. This may make users more likely to use them in an async fashion and potentially try to set the result after they should (or call another function on them). As we try to use the event ID directly this could cause use after free issues (but with something like interfaces may not be invalid due to the event buffer).
I thought about just adding this with a DEBUG compile time flag, but changing the event struct size based on that seemed like a bad idea. The only other option takes advantage of the serial call limitation. We could store the pointer to the current event struct, and the current event's id (for interface callbacks). We could then assert if the pointer/id number that come in don't match.
Auto Code Generation
With these changes no modifications are needed to generate a fairly 1:1 api: https://github.com/mitchcapper/WebUIAutoBuild/blob/master/CodeGen/WebUIGeneratorDirect.cs
resulting in: https://github.com/mitchcapper/WebUIAutoBuild/blob/master/Generated/WebUI.cs
With a more complicated generator can generate it into a more standardized class form: https://github.com/mitchcapper/WebUIAutoBuild/blob/master/CodeGen/WebUIGeneratorClass.cs
I put together a quick sample for what each looks like when used at:
https://github.com/mitchcapper/WebUIAutoBuild/tree/master/ConsoleSampleApp
but for the class version its pretty spot on:
Note these were not to replace the actual c# lib ( https://github.com/Juff-Ma/WebUI.NET ) but I generated for some testing.