ID:2478549
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
I know after seeing the title the first response would be something along the lines of "dan code".

I suggest that eval() be re-implemented entirely to allow for math evaluation only, but created from the ground up by lummox jr, and if not then lummox jr jr.

example:
world << eval("5+4+8+[src.x]")
To be fair, it works for math evaluation right now. The code you posted will work properly.
It works with a lot of other stuff too, but it also doesn't work with a lot of stuff. (as noted by the workaround to make the subtraction operator work below)
mob
verb
Stuff()
world << eval({"
var/a = 5
var/b = 10
return "a: \[a]\\nb: \[b]\\na+b: \[a+b]\\na-b: \[a+-b]"
"}
)
just write a tiny parser
In response to Optimumtact
Optimumtact wrote:
just write a tiny parser

var s = "6 - -3"

Can anyone actually make eval() subtract a negative number? lol
Works if you set one of the variables in my example to a negative.
you're also able to get if() to work but it's weird and I can't figure out how to get comparisons to work:

mob/verb/test_eval(p as num, q as num)
var/g = eval({"
var/num1 =
[p]
var/num2 =
[q]
if(num1) return num1+num2
else return 1
"}
)
world << "[g]"