Files
Aurora.3/code/controllers/hooks.dm
Fluffy b183188689 Better logging (#16164)
* Initial

* Cleared duplicates

* More work, get rid of log_error

* more

* log_debug() to macro LOG_DEBUG

* More work

* More

* Guh

* Maybe better?

* More work

* gah

* Dear lord

* *inserts swears here*

* gdi

* More work

* More

* dear lord

* fsdfsdafs

* rsdaf

* sadfasf

* sdafsad

* fgsd

* small fuckup fix

* jfsd

* sdafasf

* gdi

* sdfa

* sfdafgds

* sdafasdvf

* sdfasdfg

* sdfsga

* asdf

* dsfasfsagf

* ihibhbjh

* fsadf

* adfas

* sdafsad

* sdfasd

* fsda

* vhb

* asf

* for arrow

* removed source file-line logging, added header for tgui
2023-08-05 21:53:11 +00:00

40 lines
1.0 KiB
Plaintext

/**
* @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, list/args=null)
var/hook_path = text2path("/hook/[hook]")
if(!hook_path)
log_world("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)(arglist(args)))
log_world("ERROR: Hook '[P]' failed or runtimed.")
status = 0
return status