ISibboI / evalexpr

A powerful expression evaluation crate 🦀.
GNU Affero General Public License v3.0
320 stars 52 forks source link

am I missing the way to return computed values as variable values #162

Open pm100 opened 10 months ago

pm100 commented 10 months ago

I would like to expose variables (not functions) to the expressions that are not simple data items but I cannot find a way to do it .

Specifically - I am writing a 6502 emulator debugger. I want to expose the registers as variables in expressions. I can find no way to do it because of this signature:

fn get_value(&self, identifier: &str) -> Option<&Value>;

In the Context trait. It requires me to return a reference to a Value, if the value is looked up or computed in any way I cannot do that. I note that :

fn call_function(&self, identifier: &str, argument: &Value) -> EvalexprResult<Value>

returns the actual value not a reference. It would be a lot simpler if get_value did the same.. Is there some magic trick I am missing

ISibboI commented 10 months ago

There was #104 that may solve this, but it is outdated and stale. Feel free to make a new one, but I don't have much time to review or merge at the moment.

pm100 commented 10 months ago

I see that bug / PR - two questions

ISibboI commented 10 months ago

Cow because the value may be borrowed or a value. In case of a context that stores values as they are, cloning them every time they are read is wasteful.

Breaking changes are fine.

On Thu, 4 Jan 2024, 3.25 pm100, @.***> wrote:

I see that bug / PR - two questions

  • why return a Cow, why not a simple value just like call_functions does
  • it seems you dont mind a breaking change, this would require a change to the Context trait

— Reply to this email directly, view it on GitHub https://github.com/ISibboI/evalexpr/issues/162#issuecomment-1876185184, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASATXS7LA7AZHVMVPMDTYTYMYAJTAVCNFSM6AAAAABBK4PIIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZWGE4DKMJYGQ . You are receiving this because you commented.Message ID: @.***>