PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Jul 03 2018, 9:53 AM PST 2 min

A standard format for viewing the contents of memory. Used by many development IDEs like Visual Studio.

Far left column shows the memory address, far right column shows the ASCII representation of the bytes in memory.

function f()
print("Hello World")
end

function hex_dump(buf)
    local s = ""
    for i = 1, math.ceil(#buf/16) * 16 do
        if (i-1)  16 == 0 then s = s .. (**__CODE_SAMPLE[1]8X **):format(i-1) end
        s = s .. ( i > #buf and **   ** or (**__CODE_SAMPLE[1]2X **):format(buf:byte(i)) )
        if i   8 == 0 then s = s .. ** ** end
        if i  16 == 0 then s = s .. buf:sub(i-16+1, i):gsub(**c**,**.**) .. **\n** end
    end
    return s
end

print(hex_dump(string.dump(f)))

Outputs

00000000 1B 4C 75 61 51 00 01 04 04 04 08 00 12 00 00 00 .LuaQ........... 
00000010 3D 57 6F 72 6B 73 70 61 63 65 2E 53 63 72 69 70 =Workspace.Scrip 
00000020 74 00 01 00 00 00 03 00 00 00 00 00 00 02 04 00 t............... 
00000030 00 00 05 00 00 00 41 40 00 00 1C 40 00 01 1E 00 ......A@...@.... 
00000040 80 00 02 00 00 00 04 06 00 00 00 70 72 69 6E 74 €..........print 
00000050 00 04 0C 00 00 00 48 65 6C 6C 6F 20 57 6F 72 6C ......Hello Worl 
00000060 64 00 00 00 00 00 04 00 00 00 02 00 00 00 02 00 d............... 
00000070 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 ................ 
00000080 00 00                                           .. 
Tags:
  • memory
  • tools
  • performance
  • coding