basic.lua 3.0 KB

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