/*
* call_other.c
*
* possibly override call_other to emulate MudOS some
*
* (C) Frank Schmidt, Jesus@NorseMUD
*
*/
/* call another object failing all DRIVER_PRIV and AUTO_PRIV checks */
static varargs mixed __call_other(mixed var1, mixed var2, mixed args...) {
return ::call_other(var1, var2, args...);
}
/* call any local function, may be static (driver objects only) */
nomask varargs mixed __call_local(string func, mixed args...) {
if (DRIVER_PRIV()) {
return ::call_other(this_object(), func, args...);
}
else
illegal();
}
/* THIS DEFINE IS NOT RECOMMENDED DUE TO PERFORMANCE CONCERNS! */
#ifdef MUDOS_CALL_OTHER_ARRAY
/* call a function in another object, may be an array of objects */
static varargs mixed call_other(mixed var1, mixed var2, mixed args...) {
if (!arrayp(var1)) {
/* EXTRA BUT NEEDED DRIVER SECURITY / CPU HOGGER */
if (!IS_DRIVER_SOURCE(previous_program())) {
string file;
if (objectp(var1)) file = object_name(var1);
else file = var1;
if (IS_DRIVER_SOURCE(file)) {
/* illegal: non-DriverLib object calling DriverLib object */
error("Illegal call_other()!");
return 0;
}
}
return ::call_other(var1, var2, args...);
}
else {
int sz;
if ((sz=::sizeof(var1)) > 0) {
int i;
mixed *rets;
for (rets = allocate(sz); i < sz; ++i) {
mixed ob;
if (ob=var1[i]) {
/* EXTRA BUT NEEDED DRIVER SECURITY / CPU HOGGER */
if (!IS_DRIVER_SOURCE(previous_program())) {
string file;
if (objectp(ob)) file = object_name(ob);
else file = ob;
if (IS_DRIVER_SOURCE(file)) {
/* illegal: non-DriverLib object calling DriverLib object */
error("Illegal call_other()!");
return 0;
}
}
rets[i] = ::call_other(ob, var2, args...);
}
}
/* return array of returned values */
return rets;
}
else
return ({ });
}
}
#endif
#ifdef MUDOS_FUNCTIONP
/* test if <var> is a function */
static int functionp(mixed var) {
if (arrayp(var) && ::sizeof(var) == 2 && stringp(_FUNC(var))) {
switch (typeof(_OB(var))) {
case T_OBJECT:
case T_STRING:
return 1;
}
}
return 0;
}
/* call a functionpointer with some arguments */
static varargs mixed call_fp(mixed func, mixed args...) {
#if 0
if (functionp(func))
#endif
return __call_other(_OB(func), _FUNC(func), args...);
error("Illegal argument 1 to function call_fp() (needs functionpointer)");
return 0;
}
#endif