View/Edit #50:com*pile save

Switch to edit mode.

Name(s): com*pile save
1:   if (!player.programmer)
2:     player:tell("You are not a programmer; you cannot compile things.")
3:     if (player:isa($prog))
4:       player:tell("(Perhaps you are a programmer and have no quota though.)")
5:     endif
6:     return
7:   endif
8:   pas = {{}, {}}
9:   if (!(who = this:loaded(player)))
10:    return player:tell(this:nothing_loaded_msg())
11:  elseif (!args)
12:    object = this.objects[who]
13:    vname = this.verbnames[who]
14:    if (typeof(vname) == $LIST)
15:      vargs = listdelete(vname, 1)
16:      vname = vname[1]
17:    else
18:      vargs = {}
19:    endif
20:    changeverb = 0
21:  elseif (args[1] != "as" || (length(args) < 2 || (!(spec = $code_utils:parse_verbref(args[2])) || (typeof(pas = $code_utils:parse_argspec(@args[3..$])) != $LIST || pas[2]))))
22:    if (typeof(pas) != $LIST)
23:      player:tell(pas)
24:    elseif (pas[2])
25:      player:tell("I don't understand \"", $string_utils:from_list(pas[2], " "), "\"")
26:    endif
27:    return player:tell("Usage: ", verb, " [as &lt;object&gt;:&lt;verb&gt;]")
28:  elseif ($command_utils:object_match_failed(object = player:my_match_object(spec[1], this:get_room(player)), spec[1]))
29:    return
30:  else
31:    vname = spec[2]
32:    vargs = pas[1] && {@pas[1], "none", "none"}[1..3]
33:    if (vargs)
34:      vargs[2] = $code_utils:full_prep(vargs[2]) || vargs[2]
35:    endif
36:    changeverb = 1
37:  endif
38:  if (vargs)
39:    vnum = $code_utils:find_verb_named(object, vname)
40:    while (vnum >= 0 && verb_args(object, vnum) != vargs)
41:      vnum = $code_utils:find_verb_named(object, vname, vnum + 1)
42:    endwhile
43:    if (vnum < 0)
44:      player:tell("There is no ", object, ":", vname, " verb with args (", $string_utils:from_list(vargs, " "), ").")
45:      if (!changeverb)
46:        player:tell("Use 'compile as ...' to write your code to another verb.")
47:      endif
48:      return
49:    endif
50:    objverbname = tostr(object, ":", vname, " (", $string_utils:from_list(vargs, " "), ")")
51:  else
52:    vnum = -1
53:    objverbname = tostr(object, ":", $code_utils:toint(vname) == E_TYPE ? vname | this:verb_name(object, vname))
54:  endif
55:  "..."
56:  "...perform eval_subs on verb code if necessary..."
57:  "..."
58:  if (player.eval_subs && player:edit_option("eval_subs"))
59:    verbcode = {}
60:    for x in (this:text(who))
61:      verbcode = {@verbcode, $code_utils:substitute(x, player.eval_subs)}
62:    endfor
63:  else
64:    verbcode = this:text(who)
65:  endif
66:  "..."
67:  "...write it out..."
68:  "..."
69:  existingcode = `this:fetch_verb_code(object, vnum >= 1 ? vnum | vname) ! E_VERBNF => {}'
70:  if (!verbcode && existingcode)
71:    player:tell("You are about to compile a blank verb onto some non-blank verb code!")
72:    if (!$cmd_utils:yes_or_no("  Are you sure?"))
73:      return player:tell("Compilation aborted.")
74:    endif
75:  endif
76:  if (prepstr != "as" && this.hashes[who] && this.hashes[who] != value_hash(existingcode))
77:    player:tell("Sharing violation!")
78:    player:tell("While you were in this editor, the contents of this verb changed.  This could be the result of someone using a web editor, or @program, or even self-modifying code.  You have two choices: you can either lose your changes or you can lose the other person's changes.")
79:    player:tell("It might be wise to @list ", object, ":", vname, " to see what has changed, and determine if you want to redo your changes on the new version, or recompile and overwrite the other person's changes.")
80:    if (!$cmd_utils:yes_or_no("  Are you sure you want to overwrite the other person's changes?", 2))
81:      return player:tell("Compilation aborted.")
82:    endif
83:  endif
84:  try
85:    result = this:set_verb_code(object, vnum >= 0 ? vnum | vname, verbcode)
86:  except e (ANY)
87:    result = e[1]
88:    player:tell({result, "You do not have write permission on " + objverbname + ".", "The verb " + objverbname + " does not exist (!?!)", "The object " + tostr(object) + " does not exist (!?!)"}[1 + (result in {E_PERM, E_VERBNF, E_INVARG})])
89:    if (!changeverb)
90:      player:tell("Do 'compile as &lt;object&gt;:&lt;verb&gt;' to write your code to another verb.")
91:    endif
92:    return
93:  endtry
94:  if (result)
95:    player:tell(objverbname, " not compiled because:")
96:    for x in (result)
97:      player:tell("  ", x)
98:      if ((m = match(x, "Line %([0-9]+%):")) && toint(x[m[3][1][1]..m[3][1][2]]) > length(verbcode))
99:        player:tell("  Check for missing endif/endfor/endwhile/endtry/endtry statements.")
100:     endif
101:   endfor
102: else
103:   player:tell(objverbname, verbcode ? " successfully compiled." | " verbcode removed.")
104:   if (bad = $code_utils:bad_ref(object, vnum >= 0 ? vnum | vname))
105:     player:tell("Warning: Invalid $reference detected: ", $su:english_list(bad))
106:   endif
107:   if (bad = $code_utils:bad_obj(object, vnum >= 0 ? vnum | vname))
108:     player:tell("Warning: Invalid object number detected: ", $su:english_list(bad))
109:   endif
110:   if (bad = $code_utils:bad_var(object, vnum >= 0 ? vnum | vname))
111:     player:tell("Warning: Undefined variables may be present: ", $su:english_list(bad))
112:   endif
113:   if (bad = $code_utils:bad_var_unused(object, vnum >= 0 ? vnum | vname))
114:     player:tell("Warning: Unused variables may be present: ", $su:english_list(bad))
115:   endif
116:   if (length(verbcode) >= 10 && !$help_utils:verb_documentation(object, vnum >= 0 ? vnum | vname))
117:     player:tell("Warning: This verb has no documentation comments.")
118:   endif
119:   this:set_changed(who, 0)
120:   this.hashes[who] = value_hash(this:fetch_verb_code(object, vnum >= 1 ? vnum | vname))
121: endif
122: if (changeverb)
123:   this.objects[who] = object
124:   this.verbnames[who] = vargs ? {vname, @vargs} | vname
125: endif
126: "Last modified by Dax (#789) on Sat May 21 14:52:34 2005 MDT."

Verb arguments: none any any
Verb perms: Readable NOT-Debug
Verb owned by: Hacker (#60)

You are not logged in.

[home | help | who | search | setup | code]