# call_function

Michael Brundage (anomaly@u.washington.edu)
Wed, 17 Jan 1996 10:08:36 PST

- Messages sorted by:[ date ][ thread ][ subject ][ author ]

    >><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
    >>-- Added new built-in function `call_function(FNAME, @ARGS)' where FNAME is
    >>    a string naming a built-in function to call and ARGS are the arguments
    >>    to pass to it.  This allows you to compute the name of the function to
    >>    call and, in particular, allows you to write a call to a built-in
    >>    function that may or may not exist in the particular version of the
    >>    server you're using.
    >><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
    >
    > How is call_function("notify", player, "SPAM"); any different from
    > eval("notify(player, \"SPAM\");")?  I fail to see how this adds any new
    > functionality to the server, just maybe a slightly more convienent form
    > than eval in some cases.

    As the Changlog.txt states, it allows one to compute the name of builtin
    functions, or to call non-standard builtin functions in such a way that the
    code you write remains portable.

    As simplistic examples, you can now have verbs with similar functions can
    now handle several different builtin functions at once (before you needed a
    separate verb for each builtin)

    #0:bf_*
      verb = verb[3..$];
      if(this:trusts(player) && verb in $server_options.protected_builtins)
        return call_function(verb, @args);
      else
        return E_PERM;
      endif

    #1234:_grep _egrep
      builtin = (verb == "_egrep") ? "rmatch" | "match";
      ...
      result = call_function(builtin, line_of_code, search_expression, case);
      ...

    #5678:insert append
      return call_function("list"+verb, @args);

    etc.

    You can also create more portable MOO code (since databases containing
    nonexistant builtin functions will not even load):

    if("chr" in $server_options.list_of_all_builtin_functions_on_this_server)
      return call_function("chr", @args);
    else
      player:tell("That function is not supported on this server.");
    endif

    In general, it lets you do the nice things you can do with ordinary verb names
    with builtin functions, which couldn't be done before.

    Many thanks, Pavel, for adding this new feature!!

    michael