AddDebugHook: Difference between revisions
Jump to navigation
Jump to search
m (Updated template at →Optional Arguments) |
(Undo revision 43236 by AlexTMjugador (talk)) |
||
Line 20: | Line 20: | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{New feature/item| | {{New feature/item|9.06054|1.3.5|6142| | ||
*'''nameList:''' Table of strings for restricting which functions and events the hook will be triggered on | *'''nameList:''' Table of strings for restricting which functions and events the hook will be triggered on | ||
}} | }} |
Revision as of 19:30, 14 December 2014
This function allows tracing of MTA functions and events. It should only be used when debugging scripts as it may degrade script performance.
Debug hooks are not recursive, so functions and events triggered inside the hook callback will not be traced.
Syntax
bool addDebugHook( string hookType, function callbackFunction[, table nameList ] )
Required Arguments
- hookType: The type of hook to add. This can be:
- preEvent
- postEvent
- preFunction
- postFunction
- callbackFunction : The function to call
Optional Arguments
Returns
Returns true if the hook was successfully added, or false otherwise.
Callback parameters
pre/postEvent( resource sourceResource, string eventName, element eventSource, element eventClient, string luaFilename, int luaLineNumber, eventArguments ) pre/postFunction( resource sourceResource, string functionName, bool isAllowedByACL, string luaFilename, int luaLineNumber, functionArguments )
Example
This example will dump info about all triggered events:
function onPreEvent( sourceResource, eventName, eventSource, eventClient, luaFilename, luaLineNumber, ... ) local args = { ... } local srctype = eventSource and getElementType(eventSource) local resname = sourceResource and getResourceName(sourceResource) local plrname = eventClient and getPlayerName(eventClient) outputDebugString( "preEvent" .. " " .. tostring(resname) .. " " .. tostring(eventName) .. " source:" .. tostring(srctype) .. " player:" .. tostring(plrname) .. " file:" .. tostring(luaFilename) .. "(" .. tostring(luaLineNumber) .. ")" .. " numArgs:" .. tostring(#args) .. " arg1:" .. tostring(args[1]) ) end addDebugHook( "preEvent", onPreEvent )
This example will dump info about all called MTA functions:
function onPreFunction( sourceResource, functionName, isAllowedByACL, luaFilename, luaLineNumber, ... ) local args = { ... } local resname = sourceResource and getResourceName(sourceResource) outputDebugString( "preFunction" .. " " .. tostring(resname) .. " " .. tostring(functionName) .. " allowed:" .. tostring(isAllowedByACL) .. " file:" .. tostring(luaFilename) .. "(" .. tostring(luaLineNumber) .. ")" .. " numArgs:" .. tostring(#args) .. " arg1:" .. tostring(args[1]) ) end addDebugHook( "preFunction", onPreFunction)
This example adds a hook which will only be triggered for the named functions
addDebugHook( "preFunction", onPreFunction, {"setElementPosition","loadstring"} )
Changelog
Version | Description |
---|
1.3.5-9.06054 | Added clientside |
1.3.5-9.06142 | Added option to restrict to specified functions and events |
Requirements
This template will be deleted.
See Also
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace