Search in sources :

Example 6 with FunctionValue

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

the class _CreateComponent method call.

public static Object call(PageContext pc, Object[] objArr) throws PageException {
    String path = Caster.toString(objArr[objArr.length - 1]);
    // not store the index to make it faster
    Component c = CreateObject.doComponent(pc, path);
    // no init method
    if (!(c.get(KeyConstants._init, null) instanceof UDF)) {
        if (objArr.length > 1) {
            Object arg1 = objArr[0];
            if (arg1 instanceof FunctionValue) {
                Struct args = Caster.toFunctionValues(objArr, 0, objArr.length - 1);
                EntityNew.setPropeties(pc, c, args, true);
            } else if (Decision.isStruct(arg1)) {
                Struct args = Caster.toStruct(arg1);
                EntityNew.setPropeties(pc, c, args, true);
            }
        }
        return c;
    }
    Object rtn;
    // no arguments
    if (objArr.length == 1) {
        rtn = c.call(pc, KeyConstants._init, EMPTY);
    } else // named arguments
    if (objArr[0] instanceof FunctionValue) {
        Struct args = Caster.toFunctionValues(objArr, 0, objArr.length - 1);
        rtn = c.callWithNamedValues(pc, KeyConstants._init, args);
    } else // no name arguments
    {
        Object[] args = new Object[objArr.length - 1];
        for (int i = 0; i < objArr.length - 1; i++) {
            args[i] = objArr[i];
            if (args[i] instanceof FunctionValue)
                throw new ExpressionException("invalid argument defintion, when using named parameters to a function, every parameter must have a name.");
        }
        rtn = c.call(pc, KeyConstants._init, args);
    }
    if (rtn == null || (c.getPageSource() != null && c.getPageSource().getDialect() == CFMLEngine.DIALECT_LUCEE))
        return c;
    return rtn;
}
Also used : UDF(lucee.runtime.type.UDF) FunctionValue(lucee.runtime.type.FunctionValue) Component(lucee.runtime.Component) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct)

Example 7 with FunctionValue

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

the class Query_ method call.

public static Query call(PageContext pc, Object[] arr) throws DatabaseException {
    String[] names = new String[arr.length];
    Array[] columns = new Array[arr.length];
    int count = 0;
    for (int i = 0; i < arr.length; i++) {
        if (arr[i] instanceof FunctionValue) {
            FunctionValue vf = (FunctionValue) arr[i];
            if (vf.getValue() instanceof Array) {
                names[count] = vf.getNameAsString();
                columns[count] = (Array) vf.getValue();
                count++;
            } else
                throw new DatabaseException("invalid argument for function query, only array as value are allowed", "example: query(column1:array(1,2,3))", null, null);
        } else
            throw new DatabaseException("invalid argument for function query, only named argument are allowed", "example: query(column1:array(1,2,3))", null, null);
    }
    Query query = new QueryImpl(names, columns, "query");
    return query;
}
Also used : Array(lucee.runtime.type.Array) QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) FunctionValue(lucee.runtime.type.FunctionValue) DatabaseException(lucee.runtime.exp.DatabaseException)

Aggregations

FunctionValue (lucee.runtime.type.FunctionValue)7 ExpressionException (lucee.runtime.exp.ExpressionException)5 FunctionValueImpl (lucee.runtime.type.FunctionValueImpl)3 Struct (lucee.runtime.type.Struct)3 ArrayList (java.util.ArrayList)2 InterpreterException (lucee.runtime.interpreter.InterpreterException)2 Casting (lucee.runtime.interpreter.ref.cast.Casting)2 LFunctionValue (lucee.runtime.interpreter.ref.literal.LFunctionValue)2 StructImpl (lucee.runtime.type.StructImpl)2 UDF (lucee.runtime.type.UDF)2 Entry (java.util.Map.Entry)1 Component (lucee.runtime.Component)1 DatabaseException (lucee.runtime.exp.DatabaseException)1 FunctionException (lucee.runtime.exp.FunctionException)1 BIF (lucee.runtime.ext.function.BIF)1 JavaObject (lucee.runtime.java.JavaObject)1 Array (lucee.runtime.type.Array)1 Collection (lucee.runtime.type.Collection)1 Key (lucee.runtime.type.Collection.Key)1 Query (lucee.runtime.type.Query)1