update_inline_libs.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if string.endsWith(line, ".lua") then
  6. table.insert(files, line)
  7. end
  8. end
  9. exe:close()
  10. end
  11. end
  12. local function oscall(cmd, quite, cwd)
  13. if cwd and Base_CWD then
  14. lfs.chdir(cwd)
  15. end
  16. if tool_debug then
  17. log.info("cmd", cmd)
  18. end
  19. local exe = io.popen(cmd)
  20. if exe then
  21. for line in exe:lines() do
  22. if not quite then
  23. log.info("cmd", line)
  24. end
  25. end
  26. exe:close()
  27. end
  28. if cwd and Base_CWD then
  29. lfs.chdir(Base_CWD)
  30. end
  31. end
  32. function TLD(buff, T, D)
  33. buff:pack("bb", T, D:len())
  34. buff:write(D)
  35. end
  36. local files = {}
  37. lsdir("core", files, true)
  38. oscall("mkdir tmp")
  39. local f = io.open("..\\..\\luat\\vfs\\luat_inline_libs.c", "wb")
  40. if not f then
  41. os.exit("can't write luat_inline_libs.c")
  42. end
  43. f:write([[#include "luat_base.h"]])
  44. f:write("\r\n")
  45. f:write([[#include "luat_fs.h"]])
  46. f:write("\r\n")
  47. f:write([[#include "luat_luadb.h"]])
  48. f:write("\r\n\r\n")
  49. kvs = {}
  50. for _, value in ipairs(files) do
  51. local lf = loadfile("core\\" .. value)
  52. local data = string.dump(lf, true)
  53. local buff = zbuff.create(256*1024)
  54. -- local data = io.readFile("tmp\\" .. value .. "c")
  55. buff:write(data)
  56. f:write("//------- " .. value .. "\r\n")
  57. local k = "luat_inline2_" .. value:sub(1, value:len() - 4)
  58. print(value, #data, k)
  59. table.insert(kvs, {size=#data,ptr=k, name=value})
  60. f:write("const char ".. k .."[] = {\r\n")
  61. local index = 0
  62. local max = #data
  63. while index < max do
  64. if index % 8 == 0 then
  65. f:write("\r\n")
  66. end
  67. f:write(string.format("0x%02X, ", buff[index]))
  68. index = index + 1
  69. end
  70. f:write("};\r\n\r\n")
  71. end
  72. f:write("const luadb_file_t luat_inline2_libs[] = {\r\n")
  73. for _, value in ipairs(kvs) do
  74. f:write(" {.name=\"" .. value.name .. "\",.size=" .. tostring(value.size) .. ", .ptr=" .. value.ptr .. "},\r\n")
  75. end
  76. f:write(" {.name=\"\",.size=0,.ptr=NULL}\r\n")
  77. f:write("};\r\n\r\n")
  78. f:close()
  79. os.exit(0)