-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues I noticed while implementing a scripting language for godot via godot-rust #970
Comments
I also noticed alot while editing that the the #[godot_api] should NOT block autocomplete. |
IDE interaction with proc-macros is very brittle, and varies a lot between VS Code and Jetbrains. I don't know how we can act upon this in a general way. If you find concrete changes that improve the user experience, please let us know (or open a PR), that would be appreciated a lot! |
I was actually able to get it working: This particular solution is very hacky and definitely not PR-worthy, but basically by ensuring that the I also found that venial panics if you pass in an incomplete |
also if we wanna guarentee that the rust type from use std::marker::PhantomData;
#[repr(C)]
struct InstancePtr<T> where T: Instance {
ptr: Option<*mut std::ffi::c_void>,
ghost: PhantomData<T>
}
trait ScriptInstance {}
trait IScriptLanguage {
type Inst: ScriptInstance;
}
trait IScript {
type Lang: IScriptLanguage;
fn new_instance(&self) -> InstancePtr<<<Self as IScript>::Lang as IScriptLang>::Inst>;
}
fn create_instance<T>(rust: T) -> InstancePtr<T> where T: IScriptInstance{
InstancePtr {
ptr: None,
ghost: PhantomData
}
}
struct MyInstance {} impl IScriptInstance for MyInstance {}
struct MyLanguage {} impl IScriptLanguage for MyLanguage {type Inst = MyInstance;}
struct MyScript {}
impl IScript for MyScript {
type Lang = MyLanguage;
fn new_instance(&self) -> InstancePtr<<<Self as IScript>::Lang as IScriptLanguage>::Inst> {
create_instance(MyInstance {})
}
} this would allow fn obj_get_script_instance<T>(object: Gd<Object>,lang: Gd<T>) -> <T as IScriptLanguage>::Inst where T: IScriptLanguage {
//pointer deref magic
panic!("I dont wanna simulate ffi here")
} |
this would work because godot checks if |
See also #987 (comment) |
@walksanatora I looked into exposing What is your use case for this function? I was thinking to just implement a fn script_instance_exists<T: Inherits<Object>, L: Inherits<ScriptLanguage>>(object: T, language: L) -> bool Because that would make it possible to implement |
I want obj_get_script_instance so that I can call a reload function on it to reload my code without having to do some weird pass through godot and make a weird _reload method |
GDExtensionCallErrorType
a actual enum instead of a type int (used inScriptInstance::call
's return value)IScriptLanguageExtension::make_template
infallable as returning None causes a engine crash due to null ref#[godot_api]
causes IDE autocomplete to have a stroke while filling incomplete information. eg: if you start typingfn handles_t
and try to get the autocomplete it wont work. suggestion: make the span only cover the attribute instead of the whole block mabey?object_get_script_instance
from thegdextension_interface.h
is not exposed in any safe way to rust. it should be decently easy though since it just needs two pointers and returns oneinterfaceThe text was updated successfully, but these errors were encountered: