Files
CHOMPStation2/code/modules/vore/trycatch_vr.dm
CHOMPStation2StaffMirrorBot 111e61a0a3 [MIRROR] BYOND 516 Compatibility (#9382)
Co-authored-by: ShadowLarkens <shadowlarkens@gmail.com>
Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
2024-11-02 18:18:18 +01:00

64 lines
1.7 KiB
Plaintext

/*
This file is for jamming single-line procs into Polaris procs.
It will prevent runtimes and allow their code to run if VOREStation's fails.
It will also log when we mess up our code rather than making it vague.
Call it at the top of a stock proc with...
if(attempt_vr(object,proc to call,args)) return
...if you are replacing an entire proc.
The proc you're attemping should return nonzero values on success.
*/
/proc/attempt_vr(callon, procname, list/args=null)
try
if(!callon || !procname)
error("attempt_vr: Invalid obj/proc: [callon]/[procname]")
return 0
var/result = call(callon,procname)(arglist(args))
return result
catch(var/exception/e)
error("attempt_vr runtimed when calling [procname] on [callon].")
error("attempt_vr catch: [e] on [e.file]:[e.line]")
log_runtime(e)
return 0
/*
This is the _vr version of calling hooks.
It's meant to have different messages, and also the try/catch block.
For when you want hooks and want to know when you ruin everything,
vs when Polaris ruins everything.
Call it at the top of a stock proc with...
if(hook_vr(proc,args)) return
...if you are replacing an entire proc.
The hooks you're calling should return nonzero values on success.
*/
/proc/hook_vr(hook, list/args=null)
try
var/hook_path = text2path("/hook/[hook]")
if(!hook_path)
error("hook_vr: Invalid hook '/hook/[hook]' called.")
return 0
var/hook_instance = new hook_path
var/status = 1
for(var/P in typesof("[hook_path]/proc"))
if(!call(hook_instance, P)(arglist(args)))
error("hook_vr: Hook '[P]' failed or runtimed.")
status = 0
return status
catch(var/exception/e)
error("hook_vr itself failed or runtimed. Exception below.")
error("hook_vr catch: [e] on [e.file]:[e.line]")