factoriolib / flib

A set of high-quality, commonly-used utilities for creating Factorio mods.
https://mods.factorio.com/mod/flib
MIT License
61 stars 15 forks source link

Math expression parser to be added to flib? #52

Closed gabfv closed 1 year ago

gabfv commented 1 year ago

Hi, I saw another mod (cybersyn combinator) that implemented a way to parse math expression (like in a combinator when setting a signal). However, I wanted a safer version of a math expression parser so I wrote one proof of concept. It's kinda basic but it supports parsing the followings operations: -, +, *, /, parenthesis and negative numbers.

So I wanted to know, would you like to integrate this into flib (I'll make a PR for this later, if you choose this)? Or should I spin off my own factorio mod library?

raiguard commented 1 year ago

The API actually has a function for this: game.evaluate_expression. It's normally only used for infinite technology costs, but it's pretty general-purpose and could be used elsewhere as well!