Hi guys
I am in the process of learn/try to make my code more readable and organized. One thing I think it may be very useful is have the ability to add multple hooks (callback) to a function.
Is there a way to do this? Thanks guys!
That's what I would normally do:
Can we do something like this (similar to Java and C#):
I am in the process of learn/try to make my code more readable and organized. One thing I think it may be very useful is have the ability to add multple hooks (callback) to a function.
Is there a way to do this? Thanks guys!
That's what I would normally do:
Code:
void onEvent(function_ptr_t user_func1, function_ptr_t user_func2){
// do regular stuff for this event
regular_stuff();
// do user stuff
user_func1();
user_func2();
}
Code:
void onEvent(void){
// do regular stuff for this event
regular_stuff();
// do user stuff
some_list = getUserHook();
while (some_list != null){
// do stuff in the list one by one
}
}
// on other part of the code, or maybe different source file
void addEventHook(function_ptr_t func){
// add to a hook list (assuming list is not full, for simplicity)
}