Execute functions before exiting: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
For example: | For example: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="C" line='line'> | ||
define my_exit_function () { vmessage("Exit time: %s", strftime("%H:%M:%S")); } | define my_exit_function () { vmessage("Exit time: %s", strftime("%H:%M:%S")); } | ||
| Line 16: | Line 16: | ||
The same behaviour can be accomplished in an slang module written in C. The function that needs to be called gets appended via | The same behaviour can be accomplished in an slang module written in C. The function that needs to be called gets appended via | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="C" line='line'> | ||
void my_module_exit_function (void) { | void my_module_exit_function (void) { | ||
destroy(global_object); | destroy(global_object); | ||
printf("Cleaning up mess!"); | printf("Cleaning up mess!\n"); | ||
} | } | ||
Latest revision as of 11:10, 13 August 2018
Sometimes it is necessary to execute functions when slang/isis is closed. In slang scripts this can be easily done via the atexit function.
For example:
define my_exit_function () { vmessage("Exit time: %s", strftime("%H:%M:%S")); }
atexit(&my_exit_function);
will print the exit time of the slang/isis process to stdout.
Exit function in C
The same behaviour can be accomplished in an slang module written in C. The function that needs to be called gets appended via
void my_module_exit_function (void) {
destroy(global_object);
printf("Cleaning up mess!\n");
}
SLang_add_cleanup_function(&my_module_exit_function);
This might be necessary when memory is allocated and used until the very end.