How to use the blockly.JavaScript function in blockly

To help you get started, we’ve selected a few blockly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github binary-com / binary-bot / src / botPage / view / view.js View on Github external
var run = function run() {
	// Generate JavaScript code and run it.
	try {
		window.LoopTrap = 1000;
		blockly.JavaScript.INFINITE_LOOP_TRAP =
			'if (--window.LoopTrap == 0) throw "Infinite loop.";\n';
		var code = blockly.JavaScript.workspaceToCode(blockly.mainWorkspace);
		blockly.JavaScript.INFINITE_LOOP_TRAP = null;
		var EVAL_BLOCKLY_CODE = eval;
		EVAL_BLOCKLY_CODE(code);
		$('#summaryPanel')
			.show();
		$('#stopButton')
			.bind('click', stop);
	} catch (e) {
		botUtils.showError(e);
	}
};
github binary-com / binary-bot / src / newdesign / botPage / view / blockly / code / finish / read_details.js View on Github external
var blockly = require('blockly');
blockly.JavaScript.read_details = function(block) {
  var detail_index = block.getFieldValue('DETAIL_INDEX');
  // TODO: Assemble JavaScript into code variable.
  var code = '((details instanceof Array && details.length === Bot.config.lists.DETAILS.length) ? details[' + ( parseInt(detail_index.trim()) - 1 ) + '] : \'\' )';
  return [code, blockly.JavaScript.ORDER_ATOMIC];
};
github binary-com / binary-bot / src / ui.js View on Github external
var run = function run() {
	// Generate JavaScript code and run it.
	try {
		window.LoopTrap = 1000;
		blockly.JavaScript.INFINITE_LOOP_TRAP =
			'if (--window.LoopTrap == 0) throw "Infinite loop.";\n';
		var code = blockly.JavaScript.workspaceToCode(blockly.mainWorkspace);
		blockly.JavaScript.INFINITE_LOOP_TRAP = null;
		var EVAL_BLOCKLY_CODE = eval;
		EVAL_BLOCKLY_CODE(code);
		$('#stopButton')
			.text('Stop');
		$('#runButton')
			.text('Restart');
		$('#summaryPanel')
			.show();
		$('#stopButton')
			.unbind('click', reset);
		$('#stopButton')
			.bind('click', stop);
	} catch (e) {
		utils.showError(e);
	}
github Paol-imi / blockly-gamepad / src / gamepad.js View on Github external
}
        Blockly.JavaScript.INFINITE_LOOP_TRAP && (c = Blockly.JavaScript.INFINITE_LOOP_TRAP.replace(/%1/g, "'" + a.id + "'") +
            c);
        (d = Blockly.JavaScript.valueToCode(a, "RETURN", Blockly.JavaScript.ORDER_NONE) || "") && (d = Blockly.JavaScript.INDENT + "return " + d + ";\n");
        for (var e = [], f = 0; f < a.arguments_.length; f++) e[f] = Blockly.JavaScript.variableDB_.getName(a.arguments_[f], Blockly.Variables.NAME_TYPE);

        c = "async function " + b + "(" + e.join(", ") + ") {\n" +
            c + d + "\n" +
            "}";
        c = Blockly.JavaScript.scrub_(a, c);
        Blockly.JavaScript.definitions_["%" + b] = c;

        return null;
    }
    Blockly.JavaScript.procedures_defnoreturn = Blockly.JavaScript.procedures_defreturn;
    Blockly.JavaScript.procedures_callreturn = function (a) {
        for (var b = Blockly.JavaScript.variableDB_.getName(a.getFieldValue("NAME"), Blockly.Procedures.NAME_TYPE), c = [], d = 0; d < a.arguments_.length; d++) c[d] = Blockly.JavaScript.valueToCode(a, "ARG" + d, Blockly.JavaScript.ORDER_COMMA) || "null";
        return ["await " + b + "(" + c.join(", ") + ")", Blockly.JavaScript.ORDER_FUNCTION_CALL]
    }
    Blockly.JavaScript.procedures_callnoreturn = function (a) {
        for (var b = Blockly.JavaScript.variableDB_.getName(a.getFieldValue("NAME"), Blockly.Procedures.NAME_TYPE), c = [], d = 0; d < a.arguments_.length; d++) c[d] = Blockly.JavaScript.valueToCode(a, "ARG" + d, Blockly.JavaScript.ORDER_COMMA) || "null";
        return "await " + b + "(" + c.join(", ") + ");\n"
    }

    Blockly.JavaScript[Gamepad['BLOCKS']['START']] = function () {
        return '';
    }

    // set reserved words
    Blockly.JavaScript.addReservedWords('Blockly,CONTEXT,worker,code,reject,resolve,f');

    // define the start block
github binary-com / binary-bot / src / newdesign / botPage / view / blockly / code / strategy / purchase.js View on Github external
var blockly = require('blockly');
blockly.JavaScript.purchase = function(block) {
	if ( this.parentBlock_ === null ) {
		return '';
	}
	var purchase_list = block.getFieldValue('PURCHASE_LIST');
	var code = purchase_list;
	code = 'Bot.trade.purchase(\'' + code + '\');\n';
	return code;
};
github binary-com / binary-bot / src / cat / bot / view / blockly / code / finish / details.js View on Github external
var blockly = require('blockly');
blockly.JavaScript.contract_details = function(block) {
	var code = 'details';
  return [code, blockly.JavaScript.ORDER_ATOMIC];
};
github binary-com / binary-bot / src / newdesign / botPage / view / blockly / code / finish / result.js View on Github external
blockly.JavaScript.contract_result = function(block) {
	var code = 'result';
  return [code, blockly.JavaScript.ORDER_ATOMIC];
};
github binary-com / binary-bot / src / newdesign / botPage / view / blockly / code / strategy / check_direction.js View on Github external
blockly.JavaScript.check_direction = function(block) {
	var check_with = block.getFieldValue('CHECK_DIRECTION');
	var code = '(direction === \'' + check_with + '\')';
  return [code, blockly.JavaScript.ORDER_ATOMIC];
};
github binary-com / binary-bot / src / cat / bot / view / blockly / code / finish / finish.js View on Github external
var blockly = require('blockly');
blockly.JavaScript.on_finish = function(block) {
  var stack = blockly.JavaScript.statementToCode(block, 'FINISH_STACK');
  var code = 'Bot.globals.on_finish = function on_finish(result, details){\n' + stack + '\n};\n';
  return code;
};
github binary-com / binary-bot / src / newdesign / botPage / view / blockly / code / strategy / direction.js View on Github external
var blockly = require('blockly');
blockly.JavaScript.direction = function(block) {
	var code = 'direction';
  return [code, blockly.JavaScript.ORDER_ATOMIC];
};