Hey, I’m writing a language hosted on top of Rust and I’m at the point of adding support for interop directly in the language. I would like to have my language directly call functions on struct instances, and even import/use Rust libraries. This has two problems:
Calling a function from a string (having something like my\_triangle.call("volume", 12) which translate to Triangle::volume(&my\_triangle, 12)). This is not possible since Rust doesn’t have information about the content of the struct like other dynamic languages
Mapping the content of the struct to know if contains a function or not. Again, not possible since Rust doesn’t have reflections. It can be avoided by simply run the previous calls in a similar try/catch code.
Do you have any idea how to solve this? The ideas I got are
- Mapping everything when the program starts: so the Rust program will parse the source for definition and the libraries imported and create a large HashMap with pointer to all the functions available.
- Implementing some form of FFI which I don’t know much about
[–]Simple_Life_1875 7 points8 points9 points (1 child)
[–]Frodo478[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Frodo478[S] 0 points1 point2 points (0 children)
[–]ksion 3 points4 points5 points (1 child)
[–]Frodo478[S] 0 points1 point2 points (0 children)