Page 1 of 1

Embbeded code

Posted: Wed Aug 17, 2016 3:27 am
by khofez
I would like to know how the guys that are developing love2d converted a lua file into an unsigned char array with hexadecimal letters separated by commas, for example boot.lua and nogame.lua.

Re: Embbeded code

Posted: Wed Aug 17, 2016 6:20 am
by zorg
Don't know, but something like this should work:

Code: Select all

local data= {}
for line in love.filesystem.lines("code.lua") do
  for c in line:gmatch"." do
    data[#data+1] = ('%02X, '):format(c:byte()) 
  end
end
data = table.concat(data)

Re: Embbeded code

Posted: Wed Aug 17, 2016 8:28 am
by bartbes
Using the file next to it: auto.lua.

Re: Embbeded code

Posted: Wed Aug 17, 2016 12:06 pm
by khofez
Thanks guys !