[Suggestion] dynamic function call
Posted: 05 Oct 2011, 15:56
Hey,
This is a "high end" suggestion. I'm not sure it's even possible. I would love to be able to do dynamic function calls (Ã la http://php.net/manual/en/function.call-user-func.php) ie. you specify the function name with a String and you pass the parameters in some other way (in php you can either put the params as params of call_user_func, or in an array with call_user_func_array but they require respectively dynamic param numbers and heterogenous arrays - both of which seem not to be possible in ManiaScript).
The obvious use case for that is to implement patterns such as event listener, dependency injection etc. (more precisely I have a standard main loop function, and i would be able to dynamically plug new function that listen to the events on that main loop).
This is a "high end" suggestion. I'm not sure it's even possible. I would love to be able to do dynamic function calls (Ã la http://php.net/manual/en/function.call-user-func.php) ie. you specify the function name with a String and you pass the parameters in some other way (in php you can either put the params as params of call_user_func, or in an array with call_user_func_array but they require respectively dynamic param numbers and heterogenous arrays - both of which seem not to be possible in ManiaScript).
The obvious use case for that is to implement patterns such as event listener, dependency injection etc. (more precisely I have a standard main loop function, and i would be able to dynamically plug new function that listen to the events on that main loop).