Skip to content
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

Execute single expressions #241

Open
bvssvni opened this issue May 30, 2016 · 2 comments

Comments

@bvssvni
Copy link
Member

commented May 30, 2016

@Izzeri

This comment has been minimized.

Copy link

commented May 30, 2016

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();
@bvssvni

This comment has been minimized.

Copy link
Member Author

commented Jun 1, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.