MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Re: [dumping code using] FUP



>I recently installed FUP 1.8 on my moo running LambdaMOO 1.7.9p2. Is
>there a way i can dump moocode from disk to MOO using FUP?

Naturally, since you can write lists of strings easily to files, and this
is what MOO code looks like.

As an example, consider the following utility, $wiz_utils:dump_to_file,
which is the same as the $prog:@dump verb, but 1) without the user
interface, and 2) writes to a file.

@verb $wiz_utils:"dump_to_file"   this none this   rx   #2
@prog $wiz_utils:dump_to_file
":dump_to_file({path,filename},what,id,props,verbs,create)";
"This spills out all properties and verbs on an object, calling suspend at
appropriate intervals.";
"   id=#nnn -- specifies an idnumber to use in place of the object's actual
id (for porting to another MOO)";
"   noprops -- don't show properties.";
"   noverbs -- don't show verbs.";
if (!caller_perms().wizard)
  return E_PERM;
endif
cu = $command_utils;
su = $string_utils;
file = args[1];
if (fileexists(@file))
  return E_PERM;
endif
dobj = args[2];
targname = args[3] || tostr(dobj);
props = args[4];
verbs = args[5];
create = args[6];
if (create)
  parent = parent(dobj);
  pstring = tostr(parent);
  for p in (properties(#0))
    if (#0.(p) == parent)
      pstring = "$" + p;
    endif
  endfor
  fileappend(@file, {tostr("@create ", pstring, " named ", dobj.name, ":",
su:from_list(dobj.aliases, ","))});
endif
for p in (props ? properties(dobj) | {})
  pquoted = su:print(p);
  info = property_info(dobj, p);
  value = dobj.(p);
  if (create)
    uvalue = typeof(value) == LIST ? "{}" | 0;
    fileappend(@file, {tostr("@prop ", targname, ".", pquoted, " ", uvalue
|| su:print_suspended(value), " ", info[2] || "\"\"", info[1] == dobj.owner
? "" | tostr(" ", info[1]))});
    if (uvalue && value)
      fileappend(@file, {tostr(";", targname, ".(", pquoted, ") = ",
su:print_suspended(value))});
    endif
  else
    if (info[2] != "rc")
      fileappend(@file, {tostr("@chmod ", targname, ".", pquoted, " ",
info[2])});
    endif
    if (info[1] != dobj.owner)
      fileappend(@file, {tostr("@chown ", targname, ".", pquoted, " ",
info[1])});
    endif
    fileappend(@file, {tostr(";", targname, ".(", pquoted, ") = ",
su:print_suspended(value))});
  endif
  cu:suspend_if_needed(0);
endfor
for a in (props ? $object_utils:ancestors(dobj) | {})
  for p in (properties(a))
    cu:suspend_if_needed(1);
    pquoted = su:print(p);
    value = dobj.(p);
    avalue = a.(p);
    if (typeof(value) == ERR)
      fileappend(@file, {tostr("\"", targname, ".(", pquoted, ") => ",
$code_utils:error_name(value), " (", value, ")")});
    elseif (typeof(avalue) == ERR || value != avalue)
      fileappend(@file, {tostr(";", targname, ".(", pquoted, ") = ",
su:print_suspended(value))});
    endif
  endfor
  cu:suspend_if_needed(1);
endfor
if (!verbs)
  return;
endif
fileappend(@file, {""});
v = tostr(0);
while ((info = verb_info(dobj, v)) || info == E_PERM)
  if (index(info[3], "(old)") && 0)
    "Thought about skipping (old) verbs...";
  else
    suspend(1);
    if (typeof(info) == ERR)
      fileappend(@file, {tostr("\"", dobj, ":", v, " --- ", info, "\";")});
    else
      if (i = index(vname = info[3], " "))
        vname = vname[1..i - 1];
      endif
      if (vname[1] != "*")
        vname = strsub(vname, "*", "");
      endif
      args = verb_args(dobj, v);
      prep = args[2] in {"any", "none"} ? args[2] |
$code_utils:short_prep(args[2]);
      perms = info[2] != (args == {"this", "none", "this"} ? "rxd" | "rd")
? info[2] || "\"\"" | "";
      if (create)
        if (info[1] == dobj.owner)
          tail = perms ? tostr(" ", perms) | "";
        else
          tail = tostr(" ", perms || info[2], " ", info[1]);
        endif
        fileappend(@file, {tostr("@verb ", targname, ":\"", info[3], "\" ",
args[1], " ", prep, " ", args[3], tail)});
      else
        fileappend(@file, {tostr("@args ", targname, ":\"", info[3], "\" ",
args[1], " ", prep, " ", args[3])});
        if (info[1] != dobj.owner)
          fileappend(@file, {tostr("@chown ", targname, ":", vname, " ",
info[1])});
        endif
        if (perms)
          fileappend(@file, {tostr("@chmod ", targname, ":", vname, " ",
perms)});
        endif
      endif
      if (code = verb_code(dobj, v, 1, 1))
        fileappend(@file, {tostr("@program ", targname, ":", vname)});
        for c in (code)
          fileappend(@file, {c});
          cu:suspend_if_needed(0);
        endfor
        fileappend(@file, {".", ""});
      endif
    endif
  endif
  if (index(tostr(" ", info[3], " "), " * "))
    "... we have a * verb.  may as well forget trying to list...";
    "... the rest; they're invisible.  set v to something nonstring.";
    v = E_TYPE;
  else
    v = tostr(tonum(v) + 1);
  endif
  cu:suspend_if_needed(0);
endwhile
"Last modified Tue Mar 28 19:21:50 1995 IST by Gustavo (#2).";
<end>


Can probably be improved a lot, but it works nicely. :)

-------------------------------------------------------------
Gustavo Glusman               Founder/administrator of BioMOO
-- Gustavo@bioinformatics.weizmann.ac.il
-- http://bioinformatics.weizmann.ac.il/Gustavo
-- BioMOO: telnet bioinformatics.weizmann.ac.il 8888
           WWW:   http://bioinfo.weizmann.ac.il/BioMOO





Home | Subject Index | Thread Index