build/litegraph.js
function(
            name,
            func,
            param_types,
            return_type,
            properties
        ) {
            var params = Array(func.length);
            var code = "";
            var names = LiteGraph.getParameterNames(func);
            for (var i = 0; i < names.length; ++i) {
                code +=
                    "this.addInput('" +
                    names[i] +
                    "'," +
                    (param_types && param_types[i]
                        ? "'" + param_types[i] + "'"
                        : "0") +
                    ");\n";
            }
            code +=
                "this.addOutput('out'," +
                (return_type ? "'" + return_type + "'" : 0) +
                ");\n";
            if (properties) {
                code +=
                    "this.properties = " + JSON.stringify(properties) + ";\n";
            }
            var classobj = Function(code);
            classobj.title = name.split("/").pop();
            classobj.desc = "Generated from " + func.name;
            classobj.prototype.onExecute = function onExecute() {
                for (var i = 0; i < params.length; ++i) {
                    params[i] = this.getInputData(i);
                }
                var r = func.apply(this, params);
                this.setOutputData(0, r);
            };
            this.registerNodeType(name, classobj);
        }
function(
            name,
            func,
            param_types,
            return_type,
            properties
        ) {
            var params = Array(func.length);
            var code = "";
            var names = LiteGraph.getParameterNames(func);
            for (var i = 0; i < names.length; ++i) {
                code +=
                    "this.addInput('" +
                    names[i] +
                    "'," +
                    (param_types && param_types[i]
                        ? "'" + param_types[i] + "'"
                        : "0") +
                    ");\n";
            }
            code +=
                "this.addOutput('out'," +
                (return_type ? "'" + return_type + "'" : 0) +
                ");\n";
            if (properties) {
                code +=
                    "this.properties = " + JSON.stringify(properties) + ";\n";
            }
            var classobj = Function(code);
            classobj.title = name.split("/").pop();
            classobj.desc = "Generated from " + func.name;
            classobj.prototype.onExecute = function onExecute() {
                for (var i = 0; i < params.length; ++i) {
                    params[i] = this.getInputData(i);
                }
                var r = func.apply(this, params);
                this.setOutputData(0, r);
            };
            this.registerNodeType(name, classobj);
        }
function ( name , func , param_types , return_type , properties ) { var params = Array ( func . length ) ; var code = "" ; var names = LiteGraph . getParameterNames ( func ) ; for ( var i = 0 ; i < names . length ; ++ i ) { code += "this.addInput('" + names [ i ] + "'," + ( param_types && param_types [ i ] ? "'" + param_types [ i ] + "'" : "0" ) + ");\n" ; } code += "this.addOutput('out'," + ( return_type ? "'" + return_type + "'" : 0 ) + ");\n" ; if ( properties ) { code += "this.properties = " + JSON . stringify ( properties ) + ";\n" ; } var classobj = Function ( code ) ; classobj . title = name . split ( "/" ) . pop ( ) ; classobj . desc = "Generated from " + func . name ; classobj . prototype . onExecute = function onExecute ( ) { for ( var i = 0 ; i < params . length ; ++ i ) { params [ i ] = this . getInputData ( i ) ; } var r = func . apply ( this , params ) ; this . setOutputData ( 0 , r ) ; } ; this . registerNodeType ( name , classobj ) ; }
Create a new nodetype by passing a function, it wraps it with a proper class and generates inputs according to the parameters of the function.
Useful to wrap simple methods that do not require properties, and that only process some input to generate an output.
@method wrapFunctionAsNode
@param {String} name node name with namespace (p.e.: 'math/sum')
@param {Function} func
@param {Array} param_types [optional] an array containing the type of every parameter, otherwise parameters will accept any type
@param {String} return_type [optional] string with the return type, otherwise it will be generic
@param {Object} properties [optional] properties to be configurable
Create a new nodetype by passing a function it wraps it with a proper class and generates inputs according to the parameters of the function . Useful to wrap simple methods that do not require properties and that only process some input to generate an output .