2016-10-23 12:41:45 -04:00
|
|
|
function Scratch3ProcedureBlocks (runtime) {
|
2016-10-03 17:43:24 -04:00
|
|
|
/**
|
|
|
|
* The runtime instantiating this block package.
|
|
|
|
* @type {Runtime}
|
|
|
|
*/
|
|
|
|
this.runtime = runtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the block primitives implemented by this package.
|
|
|
|
* @return {Object.<string, Function>} Mapping of opcode to Function.
|
|
|
|
*/
|
2016-10-23 12:41:45 -04:00
|
|
|
Scratch3ProcedureBlocks.prototype.getPrimitives = function () {
|
2016-10-03 17:43:24 -04:00
|
|
|
return {
|
|
|
|
'procedures_defnoreturn': this.defNoReturn,
|
2016-10-13 13:11:26 -04:00
|
|
|
'procedures_callnoreturn': this.callNoReturn,
|
|
|
|
'procedures_param': this.param
|
2016-10-03 17:43:24 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3ProcedureBlocks.prototype.defNoReturn = function () {
|
|
|
|
// No-op: execute the blocks.
|
|
|
|
};
|
|
|
|
|
|
|
|
Scratch3ProcedureBlocks.prototype.callNoReturn = function (args, util) {
|
|
|
|
if (!util.stackFrame.executed) {
|
2016-10-17 23:23:16 -04:00
|
|
|
var procedureCode = args.mutation.proccode;
|
|
|
|
var paramNames = util.getProcedureParamNames(procedureCode);
|
2016-10-13 13:11:26 -04:00
|
|
|
for (var i = 0; i < paramNames.length; i++) {
|
|
|
|
if (args.hasOwnProperty('input' + i)) {
|
|
|
|
util.pushParam(paramNames[i], args['input' + i]);
|
|
|
|
}
|
|
|
|
}
|
2016-10-03 17:43:24 -04:00
|
|
|
util.stackFrame.executed = true;
|
2016-10-17 23:23:16 -04:00
|
|
|
util.startProcedure(procedureCode);
|
2016-10-03 17:43:24 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-13 13:11:26 -04:00
|
|
|
Scratch3ProcedureBlocks.prototype.param = function (args, util) {
|
|
|
|
var value = util.getParam(args.mutation.paramname);
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
2016-10-03 17:43:24 -04:00
|
|
|
module.exports = Scratch3ProcedureBlocks;
|