basic.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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-2014 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 "tolua++.h"
  65. #include "ToluaUtils.h"]]
  66. )
  67. WRITE(result)
  68. end
  69. -- Is Urho3D Vector type.
  70. function urho3d_is_vector(t)
  71. return t:find("Vector<") ~= nil
  72. end
  73. -- Is Urho3D PODVector type.
  74. function urho3d_is_podvector(t)
  75. return t:find("PODVector<") ~= nil
  76. end
  77. local old_get_push_function = get_push_function
  78. local old_get_to_function = get_to_function
  79. local old_get_is_function = get_is_function
  80. function get_push_function(t)
  81. if not urho3d_is_vector(t) then
  82. return old_get_push_function(t)
  83. end
  84. if not urho3d_is_podvector(t) then
  85. return "ToluaPushVector" .. t:match("<.*>")
  86. else
  87. return "ToluaPushPODVector" .. t:match("<.*>")
  88. end
  89. end
  90. function get_to_function(t)
  91. if not urho3d_is_vector(t) then
  92. return old_get_to_function(t)
  93. end
  94. if not urho3d_is_podvector(t) then
  95. return "ToluaToVector" .. t:match("<.*>")
  96. else
  97. return "ToluaToPODVector" .. t:match("<.*>")
  98. end
  99. end
  100. function get_is_function(t)
  101. if not urho3d_is_vector(t) then
  102. return old_get_is_function(t)
  103. end
  104. if not urho3d_is_podvector(t) then
  105. return "ToluaIsVector" .. t:match("<.*>")
  106. else
  107. return "ToluaIsPODVector" .. t:match("<.*>")
  108. end
  109. end
  110. function get_property_methods_hook(ptype, name)
  111. if ptype == "get_set" then
  112. local Name = string.upper(string.sub(name, 1, 1))..string.sub(name, 2)
  113. return "Get"..Name, "Set"..Name
  114. end
  115. if ptype == "is_set" then
  116. local Name = string.upper(string.sub(name, 1, 1))..string.sub(name, 2)
  117. return "Is"..Name, "Set"..Name
  118. end
  119. if ptype == "has_set" then
  120. local Name = string.upper(string.sub(name, 1, 1))..string.sub(name, 2)
  121. return "Has"..Name, "Set"..Name
  122. end
  123. if ptype == "no_prefix" then
  124. local Name = string.upper(string.sub(name, 1, 1))..string.sub(name, 2)
  125. return Name, "Set"..Name
  126. end
  127. end