diff --git a/doomsday/libdeng2/include/de/data/record.h b/doomsday/libdeng2/include/de/data/record.h index 7d68f202c5..255552063f 100644 --- a/doomsday/libdeng2/include/de/data/record.h +++ b/doomsday/libdeng2/include/de/data/record.h @@ -178,6 +178,19 @@ namespace de * @return The block variable. */ Variable &addBlock(String const &variableName); + + /** + * Adds a function variable to the record. The variable is set up to only + * accept function values. + * + * @param variableName Name of the variable. + * @param func Function. The variable's value will hold a + * reference to the Function; the caller may release + * its reference afterwards. + * + * @return The function variable. + */ + Variable &addFunction(String const &variableName, Function *func); /** * Adds a new subrecord to the record. Adds a variable named @a name diff --git a/doomsday/libdeng2/include/de/scriptsys/functionvalue.h b/doomsday/libdeng2/include/de/scriptsys/functionvalue.h index 22abab8a27..3792120ff8 100644 --- a/doomsday/libdeng2/include/de/scriptsys/functionvalue.h +++ b/doomsday/libdeng2/include/de/scriptsys/functionvalue.h @@ -49,7 +49,7 @@ namespace de // Implements ISerializable. void operator >> (Writer &to) const; - void operator << (Reader &from); + void operator << (Reader &from); private: Function *_func; diff --git a/doomsday/libdeng2/src/data/record.cpp b/doomsday/libdeng2/src/data/record.cpp index a4116811bc..83ee1541eb 100644 --- a/doomsday/libdeng2/src/data/record.cpp +++ b/doomsday/libdeng2/src/data/record.cpp @@ -267,6 +267,13 @@ Variable &Record::addBlock(String const &name) Variable::verifyName(name); return add(new Variable(name, new BlockValue(), Variable::AllowBlock)); } + +Variable &Record::addFunction(const String &name, Function *func) +{ + /// @throw Variable::NameError @a name is not a valid variable name. + Variable::verifyName(name); + return add(new Variable(name, new FunctionValue(func), Variable::AllowFunction)); +} Record &Record::add(String const &name, Record *subrecord) { diff --git a/doomsday/libdeng2/src/scriptsys/operatorexpression.cpp b/doomsday/libdeng2/src/scriptsys/operatorexpression.cpp index f37bff9b90..fc428ecce6 100644 --- a/doomsday/libdeng2/src/scriptsys/operatorexpression.cpp +++ b/doomsday/libdeng2/src/scriptsys/operatorexpression.cpp @@ -208,9 +208,11 @@ Value *OperatorExpression::evaluate(Evaluator &evaluator) const case INDEX: { + /* LOG_DEV_TRACE("INDEX: types %s [ %s ] byref:%b", DENG2_TYPE_NAME(*leftValue) << DENG2_TYPE_NAME(*rightValue) << flags().testFlag(ByReference)); + */ // As a special case, records can be indexed also by reference. RecordValue *recValue = dynamic_cast(leftValue);