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.
Brand new ludicrously overengineered macro for automagically™ interoping with byond smoothly and cleanly.
Here's what you can do with the new macro
All of these are callable directly from byond.
Write bare functions without being wrapped in a macro
Have string arguments and return strings
Have arbitrary args that can be parsed from strings and return arbitrary types that can be converted to strings
Have some arguments be optional and not required to be passed
Gracefully handle errors
Automagic JSON Transport
New macro lives here (at the moment): https://github.com/actioninja/byond_fn
Docs here: https://docs.rs/byond_fn/0.5.1/byond_fn/
How the hell does this work?
In a very overcomplicated way
The tl;dr is it uses a trait to parse arguments from strings, and a separate trait to serialize back to string. There's blanket impls over Option and Result as well for optional args and error handling respectively.
This will be better documented later, read the code, the docs, etc
Error handling
This is very much in flux right now. Especially considering that the best way to handle this may change when FFI V2 becomes available. How it currently works can be found in the docs (though these docs may not be accurate atm): https://docs.rs/byond_fn/0.5.1/byond_fn/str_ffi/index.html#errors
Goals
I never really was super happy with the existing macro. Since it puts the function body inside a macro call, you lose a lot of IDE niceness since inside macros could be anything. On top of that, it always was kind of weird to me that each function was expected to just do the boilerplate of parsing each string argument manually when this is going to be the same in the overwhelming amount of usecases.
The unclear and not well documented nature of the previous macro resulted in a lot of cargo cult as well. Lots of functions that return results despite having no fallibility.
Someone mentioned in coderbus a while ago that it would be nice if the actual FFI junk could be pulled out of rust-g so it could be reused elsewhere more easily. Since proc macros require their own crate anyways, this makes a good opportunity to do so.
byond_fn
todoThings that should happen before this is merged
byond_fn
structure and output and hit 1.0 (above todo list should be finished)byond_fn
under the tgstation org and give more accounts crates.io publish perms