Last active
October 4, 2023 23:46
-
-
Save tabularelf/287cf766c00fca09e13bbdd7a4fa0ab2 to your computer and use it in GitHub Desktop.
Executing functions or methods with an array of arguments
This file contains hidden or 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
/// @func function_execute( function/method, [arguments_in_array]) | |
/// @desc Executes a runtime function, GML function or method, respecting method rules. | |
/// @param function/method | |
/// @param [arguments_in_array] | |
function function_execute(_funcMethod, _args = undefined) { | |
gml_pragma("forceinline"); | |
if (is_undefined(_args)) return _funcMethod(); | |
var _func = _funcMethod; | |
var _self = self; | |
if (is_method(_func)) { | |
_self = method_get_self(_func) ?? self; | |
_func = method_get_index(_func); | |
} | |
with(_self) { | |
return script_execute_ext(_func, _args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would like to note this is substantially faster then the waterfall of doom. Even the optimized version suggested by YAL.
Results:
