This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

perl pack equivalent in lua
#4
(15.03.2021, 14:21)baggins Wrote: Thanks admin.

Now, I am developping this script not on LM but on a 'normal' Linux box, because I don't want to use the LM that is in production... Is there some standard lua equivalent for lmcore.hextostring?

Also the perl script converts the command to a readable string for logging purposes:

Code:
$commandhex =~ s/(.)/sprintf("0x%x ",ord($1))/eg;

How would that be done in lua?

Thanks!

I've found a script and written another one that I can use on my Linux box.

Code:
function string.fromhex(str)
    return (str:gsub('..', function (cc)
        return string.char(tonumber(cc, 16))
    end))
end

function printhex (str)
    length = string.len(str)
    result = ""
    for i = 1, length,2 do
        result = result..'0x'..string.sub(str,i,i+1).." "
    end
    return result
end
Reply


Messages In This Thread
perl pack equivalent in lua - by baggins - 15.03.2021, 12:09
RE: perl pack equivalent in lua - by admin - 15.03.2021, 13:25
RE: perl pack equivalent in lua - by baggins - 15.03.2021, 14:21
RE: perl pack equivalent in lua - by baggins - 15.03.2021, 22:17

Forum Jump: