2
0

basic.lua 3.3 KB

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