Skip to content

Instantly share code, notes, and snippets.

@plonp
Forked from tabularelf/function_execute.gml
Created December 2, 2022 22:02
Show Gist options
  • Save plonp/b504b29f7545c94288c33c8c355fbdf1 to your computer and use it in GitHub Desktop.
Save plonp/b504b29f7545c94288c33c8c355fbdf1 to your computer and use it in GitHub Desktop.
Executing functions or methods with an array of arguments
/// @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