hook.GetTable

From Garry's Mod
Revision as of 17:03, 29 December 2016 by EstevanTH (Talk | contribs)
Jump to: navigation, search
 hook.GetTable( )

Contents

Description

Returns a table containing subtables which contain all hooks.

Returns

table

hooks

Examples

Example

This code removes all hooks which have their function defined in the current file.

If you wish to cleanup previously defined hooks automatically when using Lua refresh, place it at the top of your file. It will save you from reloading the map or removing those hooks manually.

Be aware that it cleans up by testing the location where hook functions are defined, not where hooks were added!

-- Cleanup hooks that were previously defined in this file.
local source = debug.getinfo( 1, "S" ).source
for EventName,EventHooks in pairs( hook.GetTable() ) do
	for HookName,HookFunction in pairs( EventHooks ) do
		if debug.getinfo( HookFunction, "S" ).source == source then
			hook.Remove( EventName, HookName )
		end
	end
end


Personal tools
Navigation