bgfx-idl.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. -- Copyright 2019 云风 https://github.com/cloudwu . All rights reserved.
  2. -- License (the same with bgfx) : https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  3. function doIdl()
  4. local idl = require "idl"
  5. local codegen = require "codegen"
  6. assert(loadfile("bgfx.idl" , "t", idl))()
  7. codegen.nameconversion(idl.types, idl.funcs)
  8. local code_temp_include = [[
  9. /*
  10. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  11. */
  12. /*
  13. *
  14. * AUTO GENERATED! DO NOT EDIT!
  15. *
  16. */
  17. $c99decl
  18. /**/
  19. typedef struct bgfx_interface_vtbl
  20. {
  21. $interface_struct
  22. } bgfx_interface_vtbl_t;
  23. ]]
  24. local code_temp_impl = [[
  25. /*
  26. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  27. */
  28. /*
  29. *
  30. * AUTO GENERATED! DO NOT EDIT!
  31. *
  32. */
  33. $c99
  34. /**/
  35. BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
  36. {
  37. if (_version == BGFX_API_VERSION)
  38. {
  39. static bgfx_interface_vtbl_t s_bgfx_interface =
  40. {
  41. $interface_import
  42. };
  43. return &s_bgfx_interface;
  44. }
  45. return NULL;
  46. }
  47. ]]
  48. local function codes()
  49. local temp = {}
  50. local action = {
  51. c99 = "\n",
  52. c99decl = "\n",
  53. interface_struct = "\n\t",
  54. interface_import = ",\n\t\t\t",
  55. }
  56. for k in pairs(action) do
  57. temp[k] = {}
  58. end
  59. for _, f in ipairs(idl.funcs) do
  60. for k in pairs(action) do
  61. table.insert(temp[k], (codegen["gen_"..k](f)))
  62. end
  63. end
  64. for k, ident in pairs(action) do
  65. temp[k] = table.concat(temp[k], ident)
  66. end
  67. return temp
  68. end
  69. local codes_tbl = codes()
  70. for filename, temp in pairs {
  71. ["../include/bgfx/c99/bgfx.idl.h"] = code_temp_include ,
  72. ["../src/bgfx.idl.inl"] = code_temp_impl } do
  73. print ("Generate " .. filename)
  74. local out = io.open(filename, "wb")
  75. out:write((temp:gsub("$([%l%d_]+)", codes_tbl)))
  76. out:close()
  77. end
  78. os.exit()
  79. end