This question does not have a right/wrong answer. I am mainly looking for advice of the form "look at how crate XYZ solved it / look at this technique."
I have a basic Lisp interpreter running in Rust. It has something like a
Now for handling Rust <-> Lisp interop, I want a flexible way to add Rust types defined OUTSIDE of the lisp crates to be added. Current idea is to do something like:
Lua has a similar concept where you can make native objects accessible to Lua code. It doesn't quite do what you suggested by letting you look at the fields/arms of the type, but instead lets the type define a method that gets called every time you access a field on the native object, and it can return whatever it wants.
Yeah sorta. To be more precise, they aren't called fields but instead values in a table/map, but fundamentally it's the same idea. They also have a way to call the external value as if it was a function object, and maybe other things - I don't remember.
I know very little Lua, but IIRC they also have 'metatables' Programming in Lua : 13.4.1 which also makes it easy to dynamically query for all the keys.
Is https://crates.io/crates/lua-rs the most mature pure-rust lua impl? (I'm trying to minimize external C dependencies to ensure everything builds nicely on wasm32 too.)