diff --git a/src/bin/example.rs b/src/bin/example.rs index 6486f63..23161f0 100644 --- a/src/bin/example.rs +++ b/src/bin/example.rs @@ -270,6 +270,11 @@ impl retro::wrapper::Handler for MyEmulator { Some(std::env::temp_dir()) } + fn get_variable(&mut self, key: &str) -> Option { + eprintln!("ignored: get_variable({})", key); + None + } + fn set_system_av_info(&mut self, av_info: SystemAvInfo) -> bool { self.set_geometry(av_info.geometry.clone()); self.av_info = av_info; diff --git a/src/retro/wrapper.rs b/src/retro/wrapper.rs index b077285..923fb82 100644 --- a/src/retro/wrapper.rs +++ b/src/retro/wrapper.rs @@ -50,8 +50,8 @@ pub trait Handler: Unpin + 'static { fn set_pixel_format(&mut self, format: PixelFormat) -> bool { false } fn set_input_descriptors(&mut self, input_descriptors: &[InputDescriptor]) -> bool { false } fn set_hw_render(&mut self, hw_render_callback: HwRenderCallback) -> bool { false } - fn get_variable(&mut self) -> Option { None } - fn set_variables(&mut self, variables: &[EnvVariable]) -> bool { false } + fn get_variable(&mut self, key: &str) -> Option { None } + fn set_variables(&mut self, variables: &[Variable]) -> bool { false } fn get_variable_update(&mut self) -> Option { None } fn set_support_no_game(&mut self, supports_no_game: bool) -> bool { false } fn get_libretro_path(&mut self) -> Option { None } @@ -123,12 +123,12 @@ impl StaticCallbacks { // TODO EnvCmd::SetDiskControlInterface => {}, // TODO EnvCmd::SetHwRender => {}, EnvCmd::GetVariable => { - // TODO: actually implement - let v = Self::from_void::(data)?; - eprintln!( - "Unsupported env cmd: GetVariable ({})", - unsafe { CStr::from_ptr(v.key) }.to_string_lossy()); - false + let mut var = Self::from_void::(data)?; + let value = handler + .get_variable(unsafe { CStr::from_ptr(var.key) }.to_str().ok()?)?; + // leaks memory. + var.value = CString::new(value).ok()?.into_raw(); + true }, // TODO EnvCmd::SetVariables => {}, EnvCmd::GetVariableUpdate => Self::clone_into_void(data, &handler.get_variable_update()?)?,