Open bvssvni opened 8 years ago
What I had in mind was something akin to stack based implementations of other scripting languages, where you can execute expressions one at a time. Something like:
dyon::execute("let a = 10");
let result = dyon::execute("10 + a");
I don't know if this makes sense for Dyon, but it would be really nice for doing stuff like damage formulas, e.g.:
pub struct Battler {
pub hp: i32,
pub dmg: i32,
pub def: i32,
}
dyon_obj!{ Battler { hp, dmg, def } }
let hero = Battler { hp: 10, atk: 10, def: 4 }
let enemy = Battler { hp: 5, atk: 3, def: 2 }
dyon::set_var("attacker", hero);
dyon::set_var("defender", enemy);
enemy.hp -= dyon::execute("attacker.atk - defender.def").ok();
I am unsure about the best approach for this. Some lifetime/type checking is required, but this runs currently on whole modules. The run-time is also designed to run whole programs.
This was requested on reddit https://www.reddit.com/r/rust_gamedev/comments/4lk6la/dyon_gets_adhoc_types/d3owjsq