Search in sources :

Example 1 with UDFImpl

use of lucee.runtime.type.UDFImpl in project Lucee by lucee.

the class CFFunction method call.

// private static Map udfs=new ReferenceMap();
public static Object call(PageContext pc, Object[] objArr) throws PageException {
    if (objArr.length < 3)
        throw new ExpressionException("invalid call of a CFML Based built in function");
    // translate arguments
    String filename = Caster.toString((((FunctionValue) objArr[0]).getValue()));
    Collection.Key name = KeyImpl.toKey((((FunctionValue) objArr[1]).getValue()));
    boolean isweb = Caster.toBooleanValue((((FunctionValue) objArr[2]).getValue()));
    UDF udf = loadUDF(pc, filename, name, isweb);
    Struct meta = udf.getMetaData(pc);
    boolean callerScopes = (meta == null) ? false : Caster.toBooleanValue(meta.get("callerScopes", Boolean.FALSE), false);
    boolean caller = meta == null ? false : Caster.toBooleanValue(meta.get(KeyConstants._caller, Boolean.FALSE), false);
    Struct namedArguments = null, cs = null;
    if (callerScopes) {
        cs = new StructImpl();
        if (pc.undefinedScope().getCheckArguments()) {
            cs.set(KeyConstants._local, pc.localScope().duplicate(false));
            cs.set(KeyConstants._arguments, pc.argumentsScope().duplicate(false));
        }
    }
    Object[] arguments = null;
    if (objArr.length <= 3)
        arguments = ArrayUtil.OBJECT_EMPTY;
    else if (objArr[3] instanceof FunctionValue) {
        FunctionValue fv;
        namedArguments = new StructImpl(Struct.TYPE_LINKED);
        if (callerScopes)
            namedArguments.setEL(KeyConstants._caller, cs);
        else if (caller)
            namedArguments.setEL(KeyConstants._caller, Duplicator.duplicate(pc.undefinedScope(), false));
        for (int i = 3; i < objArr.length; i++) {
            fv = toFunctionValue(name, objArr[i]);
            namedArguments.set(fv.getName(), fv.getValue());
        }
    } else {
        int offset = (caller || callerScopes ? 2 : 3);
        arguments = new Object[objArr.length - offset];
        if (callerScopes)
            arguments[0] = cs;
        else if (caller)
            arguments[0] = Duplicator.duplicate(pc.undefinedScope(), false);
        for (int i = 3; i < objArr.length; i++) {
            arguments[i - offset] = toObject(name, objArr[i]);
        }
    }
    // execute UDF
    if (namedArguments == null) {
        return ((UDFImpl) udf).call(pc, name, arguments, false);
    }
    return ((UDFImpl) udf).callWithNamedValues(pc, name, namedArguments, false);
}
Also used : StructImpl(lucee.runtime.type.StructImpl) UDF(lucee.runtime.type.UDF) FunctionValue(lucee.runtime.type.FunctionValue) Collection(lucee.runtime.type.Collection) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct) UDFImpl(lucee.runtime.type.UDFImpl)

Aggregations

ExpressionException (lucee.runtime.exp.ExpressionException)1 Collection (lucee.runtime.type.Collection)1 FunctionValue (lucee.runtime.type.FunctionValue)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 UDF (lucee.runtime.type.UDF)1 UDFImpl (lucee.runtime.type.UDFImpl)1