update_luadb_inline.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. local function lsdir(path, files, shortname)
  2. local exe = io.popen("dir /b " .. (shortname and " " or " /s ") .. path)
  3. if exe then
  4. for line in exe:lines() do
  5. table.insert(files, line)
  6. end
  7. exe:close()
  8. end
  9. end
  10. local function oscall(cmd, quite, cwd)
  11. if cwd and Base_CWD then
  12. lfs.chdir(cwd)
  13. end
  14. if tool_debug then
  15. log.info("cmd", cmd)
  16. end
  17. local exe = io.popen(cmd)
  18. if exe then
  19. for line in exe:lines() do
  20. if not quite then
  21. log.info("cmd", line)
  22. end
  23. end
  24. exe:close()
  25. end
  26. if cwd and Base_CWD then
  27. lfs.chdir(Base_CWD)
  28. end
  29. end
  30. function TLD(buff, T, D)
  31. buff:pack("bb", T, D:len())
  32. buff:write(D)
  33. end
  34. local files = {}
  35. lsdir("lib", files, true)
  36. oscall("mkdir tmp")
  37. local buff = zbuff.create(256*1024)
  38. local magic = string.char(0x5A, 0xA5, 0X5A, 0xA5)
  39. -- 先写入magic
  40. --buff:pack("bbbbbb", 0x01, 0x04, 0XA5, 0x5A, 0xA5, 0x5A)
  41. TLD(buff, 0x01, magic)
  42. -- 然后是版本号
  43. --buff:write(string.char(0x02, 0x02, 0x00, 0x02))
  44. TLD(buff, 0x02, string.char(0x00, 0x02))
  45. -- head长度
  46. buff:write(string.char(0x03, 0x04))
  47. buff:pack("I", 0x12)
  48. -- 文件数量
  49. buff:write(string.char(0x04, 0x02))
  50. buff:pack("H", #files)
  51. -- CRC值
  52. buff:write(string.char(0xFE, 0x02))
  53. buff:pack("H", 0xFFFF)
  54. for _, value in ipairs(files) do
  55. TLD(buff, 0x01, magic)
  56. TLD(buff, 0x02, value .. "c")
  57. oscall("..\\air640w\\tools\\luac_536_32bits.exe -s -o tmp\\".. value .. "c lib\\" .. value)
  58. TLD(buff, 0x03, pack.pack("I", io.fileSize("tmp\\" .. value .. "c")))
  59. TLD(buff, 0xFE, string.char(0xFF, 0xFF))
  60. buff:write(io.readFile("tmp\\" .. value .. "c"))
  61. end
  62. local data = buff:toStr(0, buff:seek(0, zbuff.SEEK_CUR))
  63. log.info("target", #data)
  64. local f = io.open("..\\..\\luat\\vfs\\luat_luadb_inline.c", "wb")
  65. if f then
  66. f:write([[#include "luat_base.h"]])
  67. f:write("\n\nconst char luadb_inline[] = {\n")
  68. local index = 0
  69. local max = #data
  70. while index < max do
  71. if index % 8 == 0 then
  72. f:write("\n")
  73. end
  74. f:write(string.format("0x%02X, ", buff[index]))
  75. index = index + 1
  76. end
  77. f:write("};\n")
  78. f:close()
  79. end
  80. os.exit(0)