webui icon indicating copy to clipboard operation
webui copied to clipboard

Headers and debug improvements

Open mitchcapper opened this issue 1 year ago • 3 comments

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: image image

Note these were not to replace the actual c# lib ( https://github.com/Juff-Ma/WebUI.NET ) but I generated for some testing.

mitchcapper avatar Mar 19 '24 09:03 mitchcapper