Skip to content

Commit

Permalink
libdeng2|Record: Convenience methods for adding function members
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Dec 8, 2012
1 parent a6c292a commit 3542427
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions doomsday/libdeng2/include/de/data/record.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/scriptsys/functionvalue.h
Expand Up @@ -49,7 +49,7 @@ namespace de

// Implements ISerializable.
void operator >> (Writer &to) const;
void operator << (Reader &from);
void operator << (Reader &from);

private:
Function *_func;
Expand Down
7 changes: 7 additions & 0 deletions doomsday/libdeng2/src/data/record.cpp
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libdeng2/src/scriptsys/operatorexpression.cpp
Expand Up @@ -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<RecordValue *>(leftValue);
Expand Down

0 comments on commit 3542427

Please sign in to comment.