basic.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. local toWrite = {}
  2. local currentString = ''
  3. local out
  4. local WRITE, OUTPUT = write, output
  5. function output(s)
  6. out = _OUTPUT
  7. output = OUTPUT -- restore
  8. output(s)
  9. end
  10. function write(a)
  11. if out == _OUTPUT then
  12. currentString = currentString .. a
  13. if string.sub(currentString,-1) == '\n' then
  14. toWrite[#toWrite+1] = currentString
  15. currentString = ''
  16. end
  17. else
  18. WRITE(a)
  19. end
  20. end
  21. function get_property_methods_hook(ptype, name)
  22. if ptype == "get_set" then
  23. local Name = string.upper(string.sub(name, 1, 1))..string.sub(name, 2)
  24. return "Get"..Name, "Set"..Name
  25. end
  26. if ptype == "is_set" then
  27. local Name = string.upper(string.sub(name, 1, 1))..string.sub(name, 2)
  28. return "Is"..Name, "Set"..Name
  29. end
  30. end
  31. function post_output_hook(package)
  32. local result = table.concat(toWrite)
  33. local function replace(pattern, replacement)
  34. local k = 0
  35. local nxt, currentString = 1, ''
  36. repeat
  37. local s, e = string.find(result, pattern, nxt, true)
  38. if e then
  39. currentString = currentString .. string.sub(result, nxt, s-1) .. replacement
  40. nxt = e + 1
  41. k = k + 1
  42. end
  43. until not e
  44. result = currentString..string.sub(result, nxt)
  45. if k == 0 then print('Pattern not replaced', pattern) end
  46. end
  47. replace("\t", " ")
  48. replace([[#ifndef __cplusplus
  49. #include "stdlib.h"
  50. #endif
  51. #include "string.h"]], [[//
  52. // Copyright (c) 2008-2013 the Urho3D project.
  53. //
  54. // Permission is hereby granted, free of charge, to any person obtaining a copy
  55. // of this software and associated documentation files (the "Software"), to deal
  56. // in the Software without restriction, including without limitation the rights
  57. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  58. // copies of the Software, and to permit persons to whom the Software is
  59. // furnished to do so, subject to the following conditions:
  60. //
  61. // The above copyright notice and this permission notice shall be included in
  62. // all copies or substantial portions of the Software.
  63. //
  64. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  65. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  66. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  67. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  68. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  69. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  70. // THE SOFTWARE.
  71. //
  72. #include "Precompiled.h"]]
  73. )
  74. WRITE(result)
  75. end