Hello, I’ve been working on kerbin, a text editor I’m messing with. I’m trying to use the unstable rust ABI (don’t criticize me on this it’s just for fun), and I’m really struggling with figuring out what is going on. If you look at the repo, in the plugins/…/lib.rs file (only rust file in the plugins dir), you’ll see the function causing me major issues. I’m trying to get a “bevy” like system that can have hooks, defined with Types, to work over the ffi. It works perfectly as expected in the kerbin/src/main.rs file, but not within this system. If anyone could find some time to help that would be incredible, thank you in advance!
You're calling troubles then are surprised troubles come???
Anyway if you will explain what exactly doesn't work that surely will help people to help you.
Not surprised about troubles, just struggling to get past them. The issue I’m getting is a panic, and I cannot for the life of me figure out why, as the system works in regular, but doesn’t in the ffi. If it helps any more, if you go back like 3 commits in the editor, there’s a plugin system that works, but without this system impl.
Actually found the error, but i’m totally unsure as to how to fix it.
let arc_rwlock_any = resources.states.get(&TypeId::of::<T>()).unwrap_or_else(|| {
panic!(
"Resource: `{}` with id `{:?}` Not Found",
type_name::<T>(),
TypeId::of::<T>()
)
});
This code, are TypeIds Not consistent over the boundary? This is in the res_mut and res.rs files.
Edit: Fixed code formatting, specified filename
I mean... sure? You invited trouble.
TypeId are not guaranteed to be consistent across compilations.
Changed this to type_name. Thank you for letting me know I invited trouble, but I’m trying to figure it out, not be negative. What can I do to downcast an any across ffi?
One other thing about this, the dylib and main crate are compiled with the same call to the compiler, so in theory the type ids should be the exact same, no?
Even worse. type_name isn't guaranteed to be equal (or different) even within the same compilation. It's for diagnostic purposes only.
You don't. The Rust ABI isn't stable, and playing with it is, as I said, playing with troubles.
Are you sure? Looking around in the repo I can see there's a command that builds only the plugin.
That is true, that’s to guarentee the output, so I guess technically not, though they are a part of the same workspace, and are compiled at the same time, in the same compiler state, which is more so what I meant. I thought I might be able to get some help on here, but it seems that people are pretty stuck that it’s just “impossible” which I’m fairly sure it’s not, so I guess I’ll just close this.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.