From faa8312074e6ea8a96efd70d6188ef592f81e579 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 4 May 2019 15:52:00 -0400 Subject: Updated tutorials Various fixes and updates for the tutorials --- tutorials/tut021_detouring.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tutorials/tut021_detouring.md') diff --git a/tutorials/tut021_detouring.md b/tutorials/tut021_detouring.md index baf6b08..b6c31e3 100644 --- a/tutorials/tut021_detouring.md +++ b/tutorials/tut021_detouring.md @@ -1,7 +1,7 @@ # Tut 0x021 ## Detouring -Detouring is a method commonly used in lua, even outside of gmod development. The idea is to redirect a function through your function first, then call the function you're redirecting at the end (or maybe the beginning, or anywhere really). Let's see an example: +Detouring is a method commonly used in Lua, even outside of Garry's Mod development. The idea is to redirect a function through your function first, then call the function you're redirecting at the end (or maybe the beginning, or anywhere really). Let's see an example: garrysmod/lua/autorun/detourprint.lua @@ -12,7 +12,7 @@ garrysmod/lua/autorun/detourprint.lua oldprint(unpack(args)) end -The above script __replaces__ the print function, with a new function, which eventually calls the original print function, with modified arguments. The above can be done with modules in Artery as well. For example, `log.lua`'s .error() function currently only prints a message in red, it dosn't actually show what failed or why. Let's modify it to show a stack trace. +The above script __replaces__ the print function with a new function which eventually calls the original print function with modified arguments. The above can be done with modules in Artery as well. For example, `log.lua`'s .error() function currently only prints a message in red, it doesn't actually show what failed or why. Let's modify it to show a stack trace. garrysmod/addons/artery\_rougelite/trace\_errors.lua @@ -26,8 +26,10 @@ garrysmod/addons/artery\_rougelite/trace\_errors.lua end -For more information on colortheme.lua see @{colortheme.lua}, for more on debug.traceback() see [the gmod wiki](http://wiki.garrysmod.com/page/debug/traceback). +For more information on colortheme.lua see @{colortheme.lua}, for more on debug.traceback() see [the Gmod wiki](http://wiki.garrysmod.com/page/debug/traceback). ***Note*** : When detouring, mind the order that you do your logic and the logic that was there before. Does it make sense to do your function first? Maybe it makes more sense to do the usual logic, then come back to your function to do more stuff. +***Note 2***: Be sure you pass ALL the arguments from the original function through your function. Even if you don't need them, someone else might! If the target function takes a variable number of arguments (It has `...` in the function signature), you must also have `...` in your function signature to capture all arguments. + Next tutorial: @{tut030_inventories.md} -- cgit v1.2.3-70-g09d2