277 |
/////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////// |
278 |
// built-in script function: wait() |
// built-in script function: wait() |
279 |
|
|
280 |
|
bool CoreVMFunction_wait::acceptsArgType(vmint iArg, ExprType_t type) const { |
281 |
|
return type == INT_EXPR || type == REAL_EXPR; |
282 |
|
} |
283 |
|
|
284 |
bool CoreVMFunction_wait::acceptsArgUnitType(vmint iArg, StdUnit_t type) const { |
bool CoreVMFunction_wait::acceptsArgUnitType(vmint iArg, StdUnit_t type) const { |
285 |
if (iArg == 0) |
return type == VM_NO_UNIT || type == VM_SECOND; |
|
return type == VM_NO_UNIT || type == VM_SECOND; |
|
|
else |
|
|
return type == VM_NO_UNIT; |
|
286 |
} |
} |
287 |
|
|
288 |
bool CoreVMFunction_wait::acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const { |
bool CoreVMFunction_wait::acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const { |
289 |
return iArg == 0 && type == VM_SECOND; |
return type == VM_SECOND; // only allow metric prefix(es) if 'seconds' is used as unit type |
290 |
} |
} |
291 |
|
|
292 |
VMFnResult* CoreVMFunction_wait::exec(VMFnArgs* args) { |
VMFnResult* CoreVMFunction_wait::exec(VMFnArgs* args) { |
293 |
ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext()); |
ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext()); |
294 |
VMIntExpr* expr = dynamic_cast<VMIntExpr*>(args->arg(0)); |
VMNumberExpr* expr = args->arg(0)->asNumber(); |
295 |
StdUnit_t unit = expr->unitType(); |
StdUnit_t unit = expr->unitType(); |
296 |
vmint us = (unit) ? expr->evalInt(VM_MICRO) : expr->evalInt(); |
vmint us = (unit) ? expr->evalCastInt(VM_MICRO) : expr->evalCastInt(); |
297 |
if (us < 0) { |
if (us < 0) { |
298 |
wrnMsg("wait(): argument may not be negative! Aborting script!"); |
wrnMsg("wait(): argument may not be negative! Aborting script!"); |
299 |
this->result.flags = STMT_ABORT_SIGNALLED; |
this->result.flags = STMT_ABORT_SIGNALLED; |