foundation2_fluffos_v1/
foundation2_fluffos_v1/bin/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/ChangeLog.old/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/Win32/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/compat/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/compat/simuls/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/include/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/clone/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/command/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/data/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/etc/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/include/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/inherit/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/inherit/master/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/log/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/single/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/single/tests/compiler/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/single/tests/efuns/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/single/tests/operators/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/u/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/tmp/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/windows/
foundation2_fluffos_v1/lib/cfg/
foundation2_fluffos_v1/lib/cmds/adm/
foundation2_fluffos_v1/lib/daemon/save/
foundation2_fluffos_v1/lib/daemon/services/
foundation2_fluffos_v1/lib/daemon/soul/
foundation2_fluffos_v1/lib/doc/build/
foundation2_fluffos_v1/lib/doc/classes/
foundation2_fluffos_v1/lib/doc/driver/
foundation2_fluffos_v1/lib/doc/driver/applies/
foundation2_fluffos_v1/lib/doc/driver/applies/interactive/
foundation2_fluffos_v1/lib/doc/driver/concepts/
foundation2_fluffos_v1/lib/doc/driver/driver/
foundation2_fluffos_v1/lib/doc/driver/efuns/arrays/
foundation2_fluffos_v1/lib/doc/driver/efuns/buffers/
foundation2_fluffos_v1/lib/doc/driver/efuns/calls/
foundation2_fluffos_v1/lib/doc/driver/efuns/compile/
foundation2_fluffos_v1/lib/doc/driver/efuns/filesystem/
foundation2_fluffos_v1/lib/doc/driver/efuns/floats/
foundation2_fluffos_v1/lib/doc/driver/efuns/functions/
foundation2_fluffos_v1/lib/doc/driver/efuns/general/
foundation2_fluffos_v1/lib/doc/driver/efuns/mappings/
foundation2_fluffos_v1/lib/doc/driver/efuns/numbers/
foundation2_fluffos_v1/lib/doc/driver/efuns/parsing/
foundation2_fluffos_v1/lib/doc/driver/lpc/constructs/
foundation2_fluffos_v1/lib/doc/driver/lpc/types/
foundation2_fluffos_v1/lib/doc/driver/platforms/
foundation2_fluffos_v1/lib/doc/efun/
foundation2_fluffos_v1/lib/doc/etc/
foundation2_fluffos_v1/lib/doc/faq/
foundation2_fluffos_v1/lib/doc/help/creator/
foundation2_fluffos_v1/lib/doc/help/player/
foundation2_fluffos_v1/lib/doc/lpc/basic/
foundation2_fluffos_v1/lib/doc/lpc/data_types/
foundation2_fluffos_v1/lib/doc/lpc/etc/
foundation2_fluffos_v1/lib/doc/lpc/intermediate/
foundation2_fluffos_v1/lib/doc/lpc/types/
foundation2_fluffos_v1/lib/doc/mudlib/
foundation2_fluffos_v1/lib/doc/mudlib/Features/
foundation2_fluffos_v1/lib/domains/Examples/armour/
foundation2_fluffos_v1/lib/domains/Examples/etc/
foundation2_fluffos_v1/lib/domains/Examples/npc/
foundation2_fluffos_v1/lib/domains/Examples/room/
foundation2_fluffos_v1/lib/domains/Examples/virtual/
foundation2_fluffos_v1/lib/domains/Examples/virtual/exaA/
foundation2_fluffos_v1/lib/domains/Examples/virtual/exaB/
foundation2_fluffos_v1/lib/domains/Examples/weapon/
foundation2_fluffos_v1/lib/domains/School/doc/
foundation2_fluffos_v1/lib/domains/School/room/
foundation2_fluffos_v1/lib/domains/School/room/Classes/
foundation2_fluffos_v1/lib/domains/School/room/Offices/
foundation2_fluffos_v1/lib/domains/Standard/
foundation2_fluffos_v1/lib/domains/Standard/pools/
foundation2_fluffos_v1/lib/domains/Standard/std/
foundation2_fluffos_v1/lib/domains/Standard/xtra/
foundation2_fluffos_v1/lib/include/
foundation2_fluffos_v1/lib/lib/obj/
foundation2_fluffos_v1/lib/news/
foundation2_fluffos_v1/lib/save/
foundation2_fluffos_v1/lib/secure/cfg/
foundation2_fluffos_v1/lib/secure/cmds/player/
foundation2_fluffos_v1/lib/secure/lib/
foundation2_fluffos_v1/old/
foundation2_fluffos_v1/win32/
/*    /secure/cmds/creator/call.c
 *    from the Foundation II LPC Library
 *    allows you to call functions in objects ad hoc
 *    created by Descartes of Borg 950430
 */

#include <lib.h>

inherit LIB_DAEMON;

object GetObject(string args);

mixed cmd(string args) {
    mixed *arg_arr;
    string *all_args;
    function f;
    object target;
    mixed val;
    string arg_targ, arg_func, err, this_arg;
    int i, maxi;

    if( !args || args == "" ) return "Call ob->func(arg1, arg2)\n";
    if( sscanf(args, "%s->%s(%s", arg_targ, arg_func, args) != 3 )
      return "Call ob->func(arg1, arg2)\n";
    args = trim(args);
    if( args != ")" ) args = args[0..<2];
    else args = "";
    if( !(target = GetObject(arg_targ)) )
      return "Cannot identify any object as \"" + arg_targ + "\".";
    if( !function_exists(arg_func, target) )
      return "The function " + arg_func +"() is not in " +
	identify(target) + "\n";
    f = (: call_other, target, arg_func :);
    if( args == "" ) {
	err = catch(val = evaluate(f));
	if( err) {
	    message("error", identify(target) + " -> " + arg_func + "()",
		    this_player());
	    message("error", "Error in execution: " + err, this_player());
	    return 1;
	}
	else {
	    message("system", identify(target) + " -> " + arg_func + "() = " +
		    identify(val), this_player());
	    return 1;
	}
    }
    arg_arr = convert_string("({"+args+"})");
    err = catch(val = evaluate(f, arg_arr...));
    args = identify(target) + " -> " + arg_func + "( ";
    for(i = 0, maxi = sizeof(arg_arr); i<maxi; i++) {
	args += identify(arg_arr[i]);
	if( i < maxi - 1 ) args += ", ";
    }
    if( err ) {
	message("error", args + ")", this_player());
	message("error", "Error in execution: " + err, this_player());
	return 1;
    }
    args += " ) = " + identify(val);
    message("system", args, this_player());
    return 1;
}

object GetObject(string str) {
    object ob;
    string file;

    str = trim(str);
    switch(str) {
        case "me":
	  return this_player();
	case "here":
	  return environment(this_player());
    }
    if( ob = find_player(str) ) return ob;
    if( ob = find_living(str) ) return ob;
    if( ob = find_object(str) ) return ob;
    file = absolute_path((string)this_player()->query_cwd(), str);
    if( file[<2..] != ".c" ) file += ".c";
    if( file_size(file) > -1 ) {
	ob = load_object(file);
	if( !ob ) {
	    message("system", "Error in loading object: " +file,
		    this_player());
	    return 0;
	}
	else return ob;
    }
    return 0;
}

void help() {
    message("help", "Syntax: <call [object]->[function](([args]))>\n\n"
	    "Examples:\n\tcall me->GetName()\n"
	    "\tcall \"/realms/descartes/workroom\"->GetProperty(\"light\")\n\n"
	    "Allows you to call any function in any object with any set of "
	    "arguments from the command line.  The syntax is identical to "
	    "that you would use inside LPC code, except that you can refer "
	    "to objects by their names or by pronouns in addition to the "
	    "usual manners.\n\n"
	    "See also: eval, gauge", this_player());
}