Last active
June 10, 2021 20:33
-
-
Save evolutionleo/308655519b0abc0105275cde8c0ff015 to your computer and use it in GitHub Desktop.
A script that allows you to merge 2+ functions into 1, using a cool workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#macro super merge_functions // uncomment this if you prefer the name 'super' | |
///@function merge_functions(func1, func2, <func3>) | |
///@param {function} func1 | |
///@param {function} *func2 | |
///@param {function} *func3 | |
function merge_functions() { | |
var funcs = array_create(argument_count, undefined) | |
for(var i = 0; i < argument_count; i++) | |
funcs[i] = argument[i] | |
var foo = new MergedFunction() | |
foo.functions = funcs | |
return foo.call | |
} | |
///@function MergedFunction(func1, func2, <func3>) | |
///@param {function} func1 | |
///@param {function} *func2 | |
///@param {function} *func3 | |
function MergedFunction() constructor { | |
self.functions = array_create(argument_count, undefined) | |
for(var i = 0; i < argument_count; i++) | |
self.functions[i] = argument[i] | |
call = function() { | |
var args = array_create(7, undefined) | |
for(var i = 0; i < argument_count; i++) { args[i] = argument[i] } | |
for(var i = 0; i < array_length(self.functions); ++i) { | |
var func = self.functions[i] | |
func(args[0], args[1], args[2], args[3], args[4], args[5], args[6]) // edit this if you need | |
// more than 7 arguments in a function | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment