* * @param {String|Function} source * @param {IFunctionSettings} [settings] * @returns {IGPUFunction}
(source, settings = {})
| 905 | * @returns {IGPUFunction} |
| 906 | */ |
| 907 | functionToIGPUFunction(source, settings = {}) { |
| 908 | if (typeof source !== 'string' && typeof source !== 'function') throw new Error('source not a string or function'); |
| 909 | const sourceString = typeof source === 'string' ? source : source.toString(); |
| 910 | let argumentTypes = []; |
| 911 | |
| 912 | if (Array.isArray(settings.argumentTypes)) { |
| 913 | argumentTypes = settings.argumentTypes; |
| 914 | } else if (typeof settings.argumentTypes === 'object') { |
| 915 | argumentTypes = utils.getArgumentNamesFromString(sourceString) |
| 916 | .map(name => settings.argumentTypes[name]) || []; |
| 917 | } else { |
| 918 | argumentTypes = settings.argumentTypes || []; |
| 919 | } |
| 920 | |
| 921 | return { |
| 922 | name: utils.getFunctionNameFromString(sourceString) || null, |
| 923 | source: sourceString, |
| 924 | argumentTypes, |
| 925 | returnType: settings.returnType || null, |
| 926 | }; |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * |
no test coverage detected