@verb #14:"eval_cmd_string" this none this rxdo #55 @program #14:"eval_cmd_string" this none this "Copied from Generic Programming student&&Etudiant d'informatique generique (#3924):eval_cmd_string by Sleeping_Beauty (#2) Sat Jul 1 06:25:09 1995 EDT" ":eval_cmd_string(string[,debug])" "Evaluates the string the way this player would normally expect to see it evaluated if it were typed on the command line. debug (defaults to 1) indicates how the debug flag should be set during the evaluation." " => {@eval_result, ticks, seconds}" "where eval_result is the result of the actual eval() call." "" "For the case where string is an expression, we need to prefix `return ' and append `;' to string before passing it to eval(). However this is not appropriate for statements, where it is assumed an explicit return will be provided somewhere or that the return value is irrelevant. The code below assumes that string is an expression unless it either begins with a semicolon `;' or one of the MOO language statement keywords." "Next, the substitutions described by this.eval_subs, which should be a list of pairs {string, sub}, are performed on string" "Finally, this.eval_env is prefixed to the beginning while this.eval_ticks is subtracted from the eventual tick count. This allows string to refer to predefined variables like `here' and `me'." set_task_perms(cp = caller_perms()) progr = valid(cp) && cp.programmer {program, ?debug = 1} = args program = program + ";" if (!match(program, "^ *%(;%|%(if%|fork?%|return%|while%|try%)[^a-z0-9A-Z_]%)")) program = "return " + program elseif (program == ";") program = "return 0;" endif program = $code_utils:substitute(program, this.eval_subs) "manta's timing hack begins..." quoted = 0 skip = 0 inreturn = 0 newprogram = "" for index in [1..length(program)] x = index + skip if (x > length(program)) break endif if (program[x] == "\\") skip = skip + 1 newprogram = newprogram + program[x..x + 1] elseif (program[x] == "\"") newprogram = newprogram + "\"" quoted = !quoted elseif (!quoted && program[x..min(x + 5, $)] == "return" && program[min($, x + 6)] in {" ", "\"", "(", "#", "{", "!", "-", "."}) newprogram = newprogram + "EvalReturnValue =" inreturn = 1 skip = skip + 6 elseif (!quoted && program[x..min(x + 5, $)] == "return" && program[min($, x + 6)] == ";") newprogram = newprogram + "\"Killing \"+\" a tick.\";" inreturn = 1 skip = skip + 6 elseif (!quoted && program[x] == ";" && inreturn) inreturn = 0 newprogram = newprogram + ";break EvalReturnLabelThingy;" else newprogram = newprogram + program[x] endif endfor program = tostr("for EvalReturnLabelThingy in [1..1]", this.eval_env, ";", "EvalTicks = ticks_left(); EvalFTime = ftime();", newprogram, "endfor return {ftime()-EvalFTime, EvalTicks-ticks_left(), `EvalReturnValue ! E_VARNF =>0'};") if (progr) if (debug) value = eval(program) tickconst = 9 else value = $code_utils:eval_d(program) tickconst = 27 endif else tickconst = 0 value = $no_one:(debug ? "eval" | "eval_d")(program) endif if (value[1] == 0) return {0, value[2], 0, 0} elseif (typeof(value[2]) == $ERR) return {1, value[2], 0, 0.0} else return {1, value[2][$], value[2][2] - tickconst, value[2][1]} endif "Last modified by Dax (#789) on Tue May 3 13:45:56 2005 MDT." .