Previous topicNext topic

User defined functions in expressions?

Suggestions for new features for Magic.
Post Reply
mcornholio
Posts: 22
Joined: Sat Sep 09, 2017 6:57 pm

User defined functions in expressions?

Post by mcornholio »

I think, it would be pretty cool to let user to save and reuse arbitrary expression functions.

For example , I use

Code: Select all

sqrt(x*500)*5000 % 1
as random from seed. I could save it to

Code: Select all

random(x)
and use it in all my scenes.

While exprtk allows user defined functions: https://github.com/ArashPartow/exprtk/b ... .txt#L1803, their user-definition is compile-time and written in C++, so not our option.

What I think is more like preprocessor macros.
So, if user defines

Code: Select all

func wat(a, b, c) = (a + b) * c
and when user writes

Code: Select all

wat(1,2,3)
in the expression, Magic converts it to

Code: Select all

(1 + 2) * 3
before execution.

Sounds not so hard, right?
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: User defined functions in expressions?

Post by Magic »

Everything is hard :). But yes, it seems like a reasonable idea. It would require some kind of new editor though.
Post Reply