basic.lua 3.1 KB

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