mgr.inz.Player I post too much
Reputation: 221
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sat May 13, 2017 4:16 pm Post subject: pointerstring mistakes tester |
|
|
This code will add additional check for all Lua functions which are using address as parameter.
It should catch those:
Code: |
readInteger('[basePtr]+4F10]') - too many closing bracket ']'
readInteger('[basePtr+4F10') - missing closing bracket ']'
readInteger('basePtr]+4F10') - missing opening bracket ']'
|
readInteger, and the rest from this function family, will just return a nil value.
writeInteger, and the rest from this function family, will return a nil or false, false when errorOnLookupFailure is set to false.
readBytes - will throw "Error:Failure determining what ... means" exception and break Lua execution, or nil when errorOnLookupFailure is set to false.
writeBytes - will throw "Error:Failure determining what ... means" exception and break Lua execution, or 0 when errorOnLookupFailure is set to false.
getAddress - will throw "Error:Failure determining what ... means" exception and break Lua execution, or 0 when errorOnLookupFailure is set to false.
Of course, you might think those are easy to find mistakes. But, imagine you have many level5 or above pointers and your script has few hundreds lines.
With this Lua script you will get exact line number:
Code: | local function addressMistakeCheck(addressString)
--debug
--print(addressString)
local counted_leftBracket,counted_rightBracket = 0,0
addressString:gsub('%[',function (c) counted_leftBracket=counted_leftBracket+1 end)
addressString:gsub(']',function (c) counted_rightBracket=counted_rightBracket+1 end)
if ((counted_leftBracket>0) or (counted_rightBracket>0)) and
(counted_leftBracket~=counted_rightBracket) then
local dbgInf3 = debug.getinfo(3)
local isAALuaCode = (stringToMD5String(dbgInf3.short_src)=='313cfbaaa930b9d4e2ed8108511db63a') or
(stringToMD5String(dbgInf3.short_src)=='cc1345622ea008b92ad7f1b6f4de8f49')
local extraInfo = isAALuaCode and ' (counting starts from {$Lua} line)' or ''
print('"address" parameter must have the same amount of "[" and "]"')
print('line number: '..(dbgInf3.currentline + (isAALuaCode and -1 or 0))..extraInfo)
end
end
registerSymbolLookupCallback( addressMistakeCheck, slNotInt) |
Script is designed as additional tool for debugging huge tables with mulilevel pointers used in Lua script. _________________
|
|