diff --git a/README.md b/README.md index 1d8a92d..0575155 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # lua-simulation-libraries + Lua libraries to be used in CarSimulator simulation scripts. + +## Supported functions + +### hex.lua + +- hexToAscii (convert string from hex to ASCII) +- asciiToHex (convert string from ASCII to hex) diff --git a/hex.lua b/hex.lua new file mode 100644 index 0000000..43325a0 --- /dev/null +++ b/hex.lua @@ -0,0 +1,14 @@ +--[[ + Convert the given number to hexadecimal notation +]] +function numberToHex(num) + return string.format('%x', num) +end + +--[[ + Convert the given ASCII string to hexadecimal notation +]] +function asciiToHex(str) + return (str:gsub(".", function(char) return string.format("%2x", char:byte()) end)) +end + diff --git a/lualib.lua b/lualib.lua deleted file mode 100644 index 161c176..0000000 --- a/lualib.lua +++ /dev/null @@ -1,4 +0,0 @@ - -function toHex(intValue, numBytes) - return string.format('%0' .. numBytes*2 .. 'X', intValue) -end