We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The inner field value of a struct is not being changed, requiring extraction and reinsertion.
Minimal example:
pub fn main(player) { dbg!(player.position.x); player.position.x = 0; dbg!(player.position.x); }
use rune::alloc::clone::TryClone; use rune::termcolor::{ColorChoice, StandardStream}; use rune::{Any, ContextError, Diagnostics, Module, Vm}; use std::sync::Arc; #[derive(Any, TryClone, Debug)] pub struct Position { #[rune(get, set)] pub x: u16, #[rune(get, set)] pub y: u16, } #[derive(Any, Debug)] pub struct Player { #[rune(get, set)] pub position: Position, } pub fn module() -> Result<Module, ContextError> { let mut module = Module::new(); module.ty::<Position>()?; module.ty::<Player>()?; Ok(module) } fn main() -> rune::support::Result<()> { let mut context = rune_modules::default_context()?; context.install(module()?)?; let mut sources = rune::sources!( entry => { pub fn main(player) { dbg!(player.position.x); player.position.x = 0; dbg!(player.position.x); } } ); let mut diagnostics = Diagnostics::new(); let result = rune::prepare(&mut sources) .with_context(&context) .with_diagnostics(&mut diagnostics) .build(); if !diagnostics.is_empty() { let mut writer = StandardStream::stderr(ColorChoice::Always); diagnostics.emit(&mut writer, &sources)?; } let mut vm = Vm::new(Arc::new(context.runtime()?), Arc::new(result?)); let mut player = Player { position: Position { x: 10, y: 10 }, }; vm.call(["main"], (&mut player,))?; Ok(()) }
Output
10 10
Expected result
10 0
Note: when the field is extracted, it works.
pub fn main(player) { let position = player.position; dbg!(position.x); position.x = 0; dbg!(position.x); player.position = position; dbg!(player.position.x); }
Ouput
10 0 0
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The inner field value of a struct is not being changed, requiring extraction and reinsertion.
Minimal example:
Output
Expected result
Note: when the field is extracted, it works.
Ouput
The text was updated successfully, but these errors were encountered: