mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
Hmm hmm, it could help to actually commit the hooks.dm file, couldn't it?
Signed-off-by: Mloc-Argent <colmohici@gmail.com>
This commit is contained in:
39
code/controllers/hooks.dm
Normal file
39
code/controllers/hooks.dm
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @file hooks.dm
|
||||
* Implements hooks, a simple way to run code on pre-defined events.
|
||||
*/
|
||||
|
||||
/** @page hooks Code hooks
|
||||
* @section hooks Hooks
|
||||
* A hook is defined under /hook in the type tree.
|
||||
*
|
||||
* To add some code to be called by the hook, define a proc under the type, as so:
|
||||
* @code
|
||||
/hook/foo/proc/bar()
|
||||
if(1)
|
||||
return 1 //Sucessful
|
||||
else
|
||||
return 0 //Error, or runtime.
|
||||
* @endcode
|
||||
* All hooks must return nonzero on success, as runtimes will force return null.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Calls a hook, executing every piece of code that's attached to it.
|
||||
* @param hook Identifier of the hook to call.
|
||||
* @returns 1 if all hooked code runs successfully, 0 otherwise.
|
||||
*/
|
||||
/proc/callHook(hook)
|
||||
var/hook_path = text2path("/hook/[hook]")
|
||||
if(!hook_path)
|
||||
error("Invalid hook '/hook/[hook]' called.")
|
||||
return 0
|
||||
|
||||
var/caller = new hook_path
|
||||
var/status = 1
|
||||
for(var/P in typesof("[hook_path]/proc"))
|
||||
if(!call(caller, P)())
|
||||
error("Hook '[P]' failed or runtimed.")
|
||||
status = 0
|
||||
|
||||
return status
|
||||
Reference in New Issue
Block a user