Switch to edit mode.
Name(s): compile1: "Compile the description of this object into a verb."
2: set_task_perms(this.owner)
3: caller == this || raise(E_PERM)
4: desc = {@args[1]}
5: vname = "_render_" + args[2]
6: if (index(desc ? desc[$] | "", "<!-- Last modified by ", 1) == 1)
7: desc = listdelete(desc, length(desc))
8: endif
9: code = {"\"*** DON'T TOUCH THIS CODE *** AUTOMATICALLY GENERATED ***\";", "caller == this || raise(E_PERM);"}
10: codemode = 0
11: "Trim off blank leading + trailing lines."
12: while (desc && !$su:triml(desc[1]))
13: desc = desc[2..$]
14: endwhile
15: while (desc && !$su:triml(desc[$]))
16: desc = desc[1..$ - 1]
17: endwhile
18: telllinescache = {}
19: for line in (desc)
20: if (codemode)
21: line = "<% " + line
22: codemode = 0
23: endif
24: program = 0
25: tellitems = {}
26: while (line && (start = index(line, "<%")))
27: $cmd_utils:suspend_if_needed(0)
28: if (length(telllinescache) == 1)
29: code = {@code, "player:tell(" + telllinescache[1] + ");"}
30: elseif (telllinescache)
31: code = {@code, "player:tell({" + $su:from_list(telllinescache, ", ") + "});"}
32: endif
33: telllinescache = {}
34: end = index(line[start..$], "%>")
35: if (line[min(start + 2, $)] == "=" && end)
36: "Parse an eval."
37: program = line[start + 3..start + end - 2]
38: start == 1 || (tellitems = {@tellitems, toliteral(line[1..start - 1])})
39: program && (tellitems = {@tellitems, program})
40: line = start + end == length(line) ? E_NONE | line[start + end + 1..$]
41: elseif (line[min(start + 2, $)] == "=")
42: $msg:mtell("www_error", "Warning! Eval may not span multiple lines.")
43: badline = line
44: badline[start..start + 2] = $su.tab
45: badline = strsub($html_utils:literal_text(badline), $su.tab, "</I><B><%=</B><I>")
46: player:tell("<I>", badline, "</I><BR>")
47: player:tell("Proceeding with compile.<P>")
48: line[start..start + 2] = "<%="
49: else
50: "Parse code."
51: if ($su:triml(line[1..start - 1]))
52: tellitems = {@tellitems, toliteral(line[1..start - 1])}
53: endif
54: if (tellitems)
55: "Clean out the old tellitems list."
56: code = {@code, "player:tell(" + $string_utils:from_list(tellitems, ", ") + ");"}
57: tellitems = {}
58: endif
59: if (end)
60: code = {@code, line[start + 2..start + end - 2]}
61: code[$] = $su:trimr(code[$])
62: if (!code[$] || code[$][$] != ";")
63: code[$] = code[$] + ";"
64: endif
65: line = line[start + end + 1..$]
66: if (!$su:triml(line))
67: line = E_NONE
68: endif
69: else
70: code = {@code, line[start + 2..$]}
71: codemode = 1
72: line = E_NONE
73: endif
74: endif
75: endwhile
76: if (line != E_NONE)
77: tellitems = {@tellitems, toliteral(line)}
78: endif
79: if (length(tellitems) == 1 && !program)
80: telllinescache = {@telllinescache, tellitems[1]}
81: elseif (tellitems)
82: code = {@code, "player:tell(" + $string_utils:from_list(tellitems, ", ") + ");"}
83: endif
84: endfor
85: if (length(telllinescache) == 1)
86: code = {@code, "player:tell(" + telllinescache[1] + ");"}
87: elseif (telllinescache)
88: code = {@code, "player:tell({" + $su:from_list(telllinescache, ", ") + "});"}
89: endif
90: if (codemode)
91: if (player:isa($webber))
92: $msg:mtell("www_error", "Warning! Last code section doesn't end.")
93: else
94: player:tell("Warning! Last code section doesn't end.")
95: endif
96: code[$] = $su:trimr(code[$])
97: if (!code[$] || code[$][$] != ";")
98: code[$] = code[$] + ";"
99: endif
100: player:tell("Proceeding with compile.")
101: endif
102: for x in [1..length(code)]
103: "Small optimisation."
104: if (code[x] == "player:tell(\"\");")
105: code[x] = "player:tell();"
106: endif
107: endfor
108: if (!(vname in verbs(this)))
109: if (where = this:has_verb(vname))
110: if (!index(verb_info(where[1], vname)[2], "o"))
111: raise(E_PERM, "Cannot override a -o verb.", vname)
112: endif
113: endif
114: add_verb(this, {this.owner, "roxd", vname}, {"this", "none", "this"})
115: endif
116: if (result = set_verb_code(this, vname, code))
117: if (player:isa($webber))
118: $msg:mtell("www_error", "Error during compile!")
119: else
120: player:tell("Error during compile!")
121: endif
122: player:tell("<PRE>")
123: player:tell(result)
124: line = toint(result[1][5..index(result[1], ":") - 1])
125: player:tell()
126: for x in [max(1, line - 2)..min(line + 2, length(code))]
127: if (line == x)
128: player:tell("<I>", $html_utils:literal_text(code[x]), "</I>")
129: else
130: player:tell($html_utils:literal_text(code[x]))
131: endif
132: endfor
133: player:tell("</PRE><HR>")
134: else
135: if (bad = $code_utils:bad_ref(this, vname))
136: player:tell("<B>Warning: Invalid $reference detected: ", $su:english_list(bad), "</B><P>")
137: endif
138: if (bad = $code_utils:bad_obj(this, vname))
139: player:tell("<B>Warning: Invalid object number detected: ", $su:english_list(bad), "</B><P>")
140: endif
141: if (bad = $code_utils:bad_var(this, vname))
142: player:tell("<B>Warning: Undefined variables may be present: ", $su:english_list(bad), "</B><P>")
143: endif
144: player:tell("<B>Compile successful!</B><P>")
145: endif
146: "Last modified by whiz (#3135) on Thu Jan 22 22:59:16 2009 EST."