dub 0.2.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dub might be problematic. Click here for more details.

Files changed (277) hide show
  1. data/History.txt +92 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +115 -0
  4. data/Rakefile +59 -0
  5. data/dub.gemspec +197 -0
  6. data/lib/dub/argument.rb +286 -0
  7. data/lib/dub/entities_unescape.rb +9 -0
  8. data/lib/dub/function.rb +177 -0
  9. data/lib/dub/function_group.rb +72 -0
  10. data/lib/dub/generator.rb +15 -0
  11. data/lib/dub/group.rb +20 -0
  12. data/lib/dub/klass.rb +338 -0
  13. data/lib/dub/lua/class.cpp.erb +114 -0
  14. data/lib/dub/lua/class_gen.rb +96 -0
  15. data/lib/dub/lua/function.cpp.erb +15 -0
  16. data/lib/dub/lua/function_gen.rb +329 -0
  17. data/lib/dub/lua/group.cpp.erb +9 -0
  18. data/lib/dub/lua/lua_cpp_helper.cpp +259 -0
  19. data/lib/dub/lua/lua_cpp_helper.h +219 -0
  20. data/lib/dub/lua/lua_object.cpp +158 -0
  21. data/lib/dub/lua/lua_object.h +69 -0
  22. data/lib/dub/lua/namespace.cpp.erb +42 -0
  23. data/lib/dub/lua/namespace_gen.rb +69 -0
  24. data/lib/dub/lua.rb +24 -0
  25. data/lib/dub/member_extraction.rb +128 -0
  26. data/lib/dub/namespace.rb +295 -0
  27. data/lib/dub/opts_parser.rb +30 -0
  28. data/lib/dub/parser.rb +46 -0
  29. data/lib/dub/templates/lua_template.erb +21 -0
  30. data/lib/dub/version.rb +3 -0
  31. data/lib/dub.rb +24 -20
  32. data/test/argument_test.rb +581 -0
  33. data/test/fixtures/app/CMakeLists.txt +54 -0
  34. data/test/fixtures/app/Doxyfile +1600 -0
  35. data/test/fixtures/app/bindings/all_lua.cpp +299 -0
  36. data/test/fixtures/app/include/matrix.h +283 -0
  37. data/test/fixtures/app/make_lua_bindings.rb +13 -0
  38. data/test/fixtures/app/vendor/lua/CMakeLists.txt +25 -0
  39. data/test/fixtures/app/vendor/lua/COPYRIGHT +34 -0
  40. data/test/fixtures/app/vendor/lua/HISTORY +183 -0
  41. data/test/fixtures/app/vendor/lua/INSTALL +99 -0
  42. data/test/fixtures/app/vendor/lua/Makefile +183 -0
  43. data/test/fixtures/app/vendor/lua/README +37 -0
  44. data/test/fixtures/app/vendor/lua/lapi.c +1080 -0
  45. data/test/fixtures/app/vendor/lua/lapi.h +16 -0
  46. data/test/fixtures/app/vendor/lua/lauxlib.c +653 -0
  47. data/test/fixtures/app/vendor/lua/lauxlib.h +174 -0
  48. data/test/fixtures/app/vendor/lua/lbaselib.c +643 -0
  49. data/test/fixtures/app/vendor/lua/lcode.c +839 -0
  50. data/test/fixtures/app/vendor/lua/lcode.h +76 -0
  51. data/test/fixtures/app/vendor/lua/ldblib.c +397 -0
  52. data/test/fixtures/app/vendor/lua/ldebug.c +622 -0
  53. data/test/fixtures/app/vendor/lua/ldebug.h +33 -0
  54. data/test/fixtures/app/vendor/lua/ldo.c +516 -0
  55. data/test/fixtures/app/vendor/lua/ldo.h +57 -0
  56. data/test/fixtures/app/vendor/lua/ldump.c +164 -0
  57. data/test/fixtures/app/vendor/lua/lfunc.c +174 -0
  58. data/test/fixtures/app/vendor/lua/lfunc.h +34 -0
  59. data/test/fixtures/app/vendor/lua/lgc.c +711 -0
  60. data/test/fixtures/app/vendor/lua/lgc.h +110 -0
  61. data/test/fixtures/app/vendor/lua/liblua.a +0 -0
  62. data/test/fixtures/app/vendor/lua/linit.c +38 -0
  63. data/test/fixtures/app/vendor/lua/liolib.c +532 -0
  64. data/test/fixtures/app/vendor/lua/llex.c +461 -0
  65. data/test/fixtures/app/vendor/lua/llex.h +81 -0
  66. data/test/fixtures/app/vendor/lua/llimits.h +128 -0
  67. data/test/fixtures/app/vendor/lua/lmathlib.c +263 -0
  68. data/test/fixtures/app/vendor/lua/lmem.c +86 -0
  69. data/test/fixtures/app/vendor/lua/lmem.h +49 -0
  70. data/test/fixtures/app/vendor/lua/loadlib.c +664 -0
  71. data/test/fixtures/app/vendor/lua/lobject.c +214 -0
  72. data/test/fixtures/app/vendor/lua/lobject.h +381 -0
  73. data/test/fixtures/app/vendor/lua/lopcodes.c +102 -0
  74. data/test/fixtures/app/vendor/lua/lopcodes.h +268 -0
  75. data/test/fixtures/app/vendor/lua/loslib.c +244 -0
  76. data/test/fixtures/app/vendor/lua/lparser.c +1337 -0
  77. data/test/fixtures/app/vendor/lua/lparser.h +82 -0
  78. data/test/fixtures/app/vendor/lua/lstate.c +214 -0
  79. data/test/fixtures/app/vendor/lua/lstate.h +168 -0
  80. data/test/fixtures/app/vendor/lua/lstring.c +111 -0
  81. data/test/fixtures/app/vendor/lua/lstring.h +31 -0
  82. data/test/fixtures/app/vendor/lua/lstrlib.c +868 -0
  83. data/test/fixtures/app/vendor/lua/ltable.c +588 -0
  84. data/test/fixtures/app/vendor/lua/ltable.h +40 -0
  85. data/test/fixtures/app/vendor/lua/ltablib.c +278 -0
  86. data/test/fixtures/app/vendor/lua/ltm.c +75 -0
  87. data/test/fixtures/app/vendor/lua/ltm.h +54 -0
  88. data/test/fixtures/app/vendor/lua/lua.c +695 -0
  89. data/test/fixtures/app/vendor/lua/lua.h +385 -0
  90. data/test/fixtures/app/vendor/lua/lua_dub_helper.h +77 -0
  91. data/test/fixtures/app/vendor/lua/luac +0 -0
  92. data/test/fixtures/app/vendor/lua/luac.c +200 -0
  93. data/test/fixtures/app/vendor/lua/luaconf.h +762 -0
  94. data/test/fixtures/app/vendor/lua/lualib.h +53 -0
  95. data/test/fixtures/app/vendor/lua/lundump.c +223 -0
  96. data/test/fixtures/app/vendor/lua/lundump.h +36 -0
  97. data/test/fixtures/app/vendor/lua/lvm.c +765 -0
  98. data/test/fixtures/app/vendor/lua/lvm.h +36 -0
  99. data/test/fixtures/app/vendor/lua/lzio.c +82 -0
  100. data/test/fixtures/app/vendor/lua/lzio.h +67 -0
  101. data/test/fixtures/app/vendor/lua/matrix.h +102 -0
  102. data/test/fixtures/app/vendor/lua/print.c +227 -0
  103. data/test/fixtures/app/vendor/lua/test/README +26 -0
  104. data/test/fixtures/app/vendor/lua/test/bisect.lua +27 -0
  105. data/test/fixtures/app/vendor/lua/test/cf.lua +16 -0
  106. data/test/fixtures/app/vendor/lua/test/echo.lua +5 -0
  107. data/test/fixtures/app/vendor/lua/test/env.lua +7 -0
  108. data/test/fixtures/app/vendor/lua/test/factorial.lua +32 -0
  109. data/test/fixtures/app/vendor/lua/test/fib.lua +40 -0
  110. data/test/fixtures/app/vendor/lua/test/fibfor.lua +13 -0
  111. data/test/fixtures/app/vendor/lua/test/globals.lua +13 -0
  112. data/test/fixtures/app/vendor/lua/test/hello.lua +3 -0
  113. data/test/fixtures/app/vendor/lua/test/life.lua +111 -0
  114. data/test/fixtures/app/vendor/lua/test/luac.lua +7 -0
  115. data/test/fixtures/app/vendor/lua/test/printf.lua +7 -0
  116. data/test/fixtures/app/vendor/lua/test/readonly.lua +12 -0
  117. data/test/fixtures/app/vendor/lua/test/sieve.lua +29 -0
  118. data/test/fixtures/app/vendor/lua/test/sort.lua +66 -0
  119. data/test/fixtures/app/vendor/lua/test/table.lua +12 -0
  120. data/test/fixtures/app/vendor/lua/test/trace-calls.lua +32 -0
  121. data/test/fixtures/app/vendor/lua/test/trace-globals.lua +38 -0
  122. data/test/fixtures/app/vendor/lua/test/xd.lua +14 -0
  123. data/test/fixtures/app/xml/classdub_1_1_base.xml +85 -0
  124. data/test/fixtures/app/xml/classdub_1_1_custom_destructor.xml +67 -0
  125. data/test/fixtures/app/xml/classdub_1_1_deletable_out_of_lua.xml +43 -0
  126. data/test/fixtures/app/xml/classdub_1_1_matrix.xml +482 -0
  127. data/test/fixtures/app/xml/classdub_1_1_no_destructor.xml +49 -0
  128. data/test/fixtures/app/xml/classdub_1_1_priv_sub_base.xml +89 -0
  129. data/test/fixtures/app/xml/classdub_1_1_private_constr.xml +68 -0
  130. data/test/fixtures/app/xml/classdub_1_1_static_constr.xml +69 -0
  131. data/test/fixtures/app/xml/classdub_1_1_sub_base.xml +89 -0
  132. data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +252 -0
  133. data/test/fixtures/app/xml/combine.xslt +15 -0
  134. data/test/fixtures/app/xml/compound.xsd +814 -0
  135. data/test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml +12 -0
  136. data/test/fixtures/app/xml/index.xml +91 -0
  137. data/test/fixtures/app/xml/index.xsd +66 -0
  138. data/test/fixtures/app/xml/matrix_8h.xml +310 -0
  139. data/test/fixtures/app/xml/namespacedub.xml +48 -0
  140. data/test/fixtures/classcv_1_1_mat.xml +1996 -0
  141. data/test/fixtures/classcv_1_1_point__.xml +341 -0
  142. data/test/fixtures/classcv_1_1_scalar__.xml +269 -0
  143. data/test/fixtures/classcv_1_1_size__.xml +270 -0
  144. data/test/fixtures/dummy_class.cpp.erb +1 -0
  145. data/test/fixtures/dummy_function.cpp.erb +1 -0
  146. data/test/fixtures/group___magic_type.xml +406 -0
  147. data/test/fixtures/namespacecv.xml +12659 -0
  148. data/test/function_group_test.rb +43 -0
  149. data/test/function_test.rb +405 -0
  150. data/test/group_test.rb +241 -0
  151. data/test/helper.rb +34 -0
  152. data/test/klass_test.rb +551 -0
  153. data/test/lua_function_gen_test.rb +242 -0
  154. data/test/namespace_test.rb +220 -0
  155. data/test/parser_test.rb +36 -0
  156. metadata +229 -272
  157. checksums.yaml +0 -7
  158. data/lib/open_api_sdk/analytics.rb +0 -99
  159. data/lib/open_api_sdk/domains.rb +0 -353
  160. data/lib/open_api_sdk/dub.rb +0 -88
  161. data/lib/open_api_sdk/links.rb +0 -766
  162. data/lib/open_api_sdk/metatags.rb +0 -54
  163. data/lib/open_api_sdk/models/operations/bulkcreatelinks_response.rb +0 -60
  164. data/lib/open_api_sdk/models/operations/bulkupdatelinks_requestbody.rb +0 -27
  165. data/lib/open_api_sdk/models/operations/bulkupdatelinks_response.rb +0 -60
  166. data/lib/open_api_sdk/models/operations/color.rb +0 -24
  167. data/lib/open_api_sdk/models/operations/createdomain_requestbody.rb +0 -33
  168. data/lib/open_api_sdk/models/operations/createdomain_response.rb +0 -60
  169. data/lib/open_api_sdk/models/operations/createlink_requestbody.rb +0 -95
  170. data/lib/open_api_sdk/models/operations/createlink_response.rb +0 -60
  171. data/lib/open_api_sdk/models/operations/createtag_requestbody.rb +0 -32
  172. data/lib/open_api_sdk/models/operations/createtag_response.rb +0 -60
  173. data/lib/open_api_sdk/models/operations/data.rb +0 -83
  174. data/lib/open_api_sdk/models/operations/deletedomain_request.rb +0 -24
  175. data/lib/open_api_sdk/models/operations/deletedomain_response.rb +0 -60
  176. data/lib/open_api_sdk/models/operations/deletedomain_responsebody.rb +0 -24
  177. data/lib/open_api_sdk/models/operations/deletelink_request.rb +0 -24
  178. data/lib/open_api_sdk/models/operations/deletelink_response.rb +0 -60
  179. data/lib/open_api_sdk/models/operations/deletelink_responsebody.rb +0 -24
  180. data/lib/open_api_sdk/models/operations/event.rb +0 -21
  181. data/lib/open_api_sdk/models/operations/getlinkinfo_request.rb +0 -33
  182. data/lib/open_api_sdk/models/operations/getlinkinfo_response.rb +0 -60
  183. data/lib/open_api_sdk/models/operations/getlinks_request.rb +0 -51
  184. data/lib/open_api_sdk/models/operations/getlinks_response.rb +0 -60
  185. data/lib/open_api_sdk/models/operations/getlinkscount_request.rb +0 -48
  186. data/lib/open_api_sdk/models/operations/getlinkscount_response.rb +0 -60
  187. data/lib/open_api_sdk/models/operations/getmetatags_request.rb +0 -24
  188. data/lib/open_api_sdk/models/operations/getmetatags_response.rb +0 -33
  189. data/lib/open_api_sdk/models/operations/getmetatags_responsebody.rb +0 -30
  190. data/lib/open_api_sdk/models/operations/getqrcode_request.rb +0 -39
  191. data/lib/open_api_sdk/models/operations/getqrcode_response.rb +0 -60
  192. data/lib/open_api_sdk/models/operations/gettags_response.rb +0 -60
  193. data/lib/open_api_sdk/models/operations/getworkspace_request.rb +0 -24
  194. data/lib/open_api_sdk/models/operations/getworkspace_response.rb +0 -60
  195. data/lib/open_api_sdk/models/operations/groupby.rb +0 -28
  196. data/lib/open_api_sdk/models/operations/interval.rb +0 -25
  197. data/lib/open_api_sdk/models/operations/level.rb +0 -21
  198. data/lib/open_api_sdk/models/operations/listdomains_response.rb +0 -60
  199. data/lib/open_api_sdk/models/operations/paymentprocessor.rb +0 -20
  200. data/lib/open_api_sdk/models/operations/requestbody.rb +0 -95
  201. data/lib/open_api_sdk/models/operations/retrieveanalytics_request.rb +0 -81
  202. data/lib/open_api_sdk/models/operations/retrieveanalytics_response.rb +0 -60
  203. data/lib/open_api_sdk/models/operations/sort.rb +0 -20
  204. data/lib/open_api_sdk/models/operations/trackcustomer_requestbody.rb +0 -33
  205. data/lib/open_api_sdk/models/operations/trackcustomer_response.rb +0 -60
  206. data/lib/open_api_sdk/models/operations/trackcustomer_responsebody.rb +0 -33
  207. data/lib/open_api_sdk/models/operations/tracklead_requestbody.rb +0 -42
  208. data/lib/open_api_sdk/models/operations/tracklead_response.rb +0 -60
  209. data/lib/open_api_sdk/models/operations/tracklead_responsebody.rb +0 -42
  210. data/lib/open_api_sdk/models/operations/tracksale_requestbody.rb +0 -42
  211. data/lib/open_api_sdk/models/operations/tracksale_response.rb +0 -60
  212. data/lib/open_api_sdk/models/operations/tracksale_responsebody.rb +0 -42
  213. data/lib/open_api_sdk/models/operations/updatedomain_request.rb +0 -27
  214. data/lib/open_api_sdk/models/operations/updatedomain_requestbody.rb +0 -33
  215. data/lib/open_api_sdk/models/operations/updatedomain_response.rb +0 -60
  216. data/lib/open_api_sdk/models/operations/updatelink_request.rb +0 -27
  217. data/lib/open_api_sdk/models/operations/updatelink_requestbody.rb +0 -95
  218. data/lib/open_api_sdk/models/operations/updatelink_response.rb +0 -60
  219. data/lib/open_api_sdk/models/operations/updatetag_color.rb +0 -24
  220. data/lib/open_api_sdk/models/operations/updatetag_request.rb +0 -27
  221. data/lib/open_api_sdk/models/operations/updatetag_requestbody.rb +0 -32
  222. data/lib/open_api_sdk/models/operations/updatetag_response.rb +0 -60
  223. data/lib/open_api_sdk/models/operations/updateworkspace_request.rb +0 -27
  224. data/lib/open_api_sdk/models/operations/updateworkspace_requestbody.rb +0 -27
  225. data/lib/open_api_sdk/models/operations/updateworkspace_response.rb +0 -60
  226. data/lib/open_api_sdk/models/operations/upsertlink_requestbody.rb +0 -95
  227. data/lib/open_api_sdk/models/operations/upsertlink_response.rb +0 -60
  228. data/lib/open_api_sdk/models/operations.rb +0 -74
  229. data/lib/open_api_sdk/models/shared/badrequest.rb +0 -24
  230. data/lib/open_api_sdk/models/shared/code.rb +0 -18
  231. data/lib/open_api_sdk/models/shared/color.rb +0 -24
  232. data/lib/open_api_sdk/models/shared/conflict.rb +0 -24
  233. data/lib/open_api_sdk/models/shared/conflict_code.rb +0 -18
  234. data/lib/open_api_sdk/models/shared/conflict_error.rb +0 -30
  235. data/lib/open_api_sdk/models/shared/countrycode.rb +0 -267
  236. data/lib/open_api_sdk/models/shared/domains.rb +0 -27
  237. data/lib/open_api_sdk/models/shared/domainschema.rb +0 -48
  238. data/lib/open_api_sdk/models/shared/error.rb +0 -30
  239. data/lib/open_api_sdk/models/shared/forbidden.rb +0 -24
  240. data/lib/open_api_sdk/models/shared/forbidden_code.rb +0 -18
  241. data/lib/open_api_sdk/models/shared/forbidden_error.rb +0 -30
  242. data/lib/open_api_sdk/models/shared/geo.rb +0 -771
  243. data/lib/open_api_sdk/models/shared/internalservererror.rb +0 -24
  244. data/lib/open_api_sdk/models/shared/internalservererror_code.rb +0 -18
  245. data/lib/open_api_sdk/models/shared/internalservererror_error.rb +0 -30
  246. data/lib/open_api_sdk/models/shared/inviteexpired.rb +0 -24
  247. data/lib/open_api_sdk/models/shared/inviteexpired_code.rb +0 -18
  248. data/lib/open_api_sdk/models/shared/inviteexpired_error.rb +0 -30
  249. data/lib/open_api_sdk/models/shared/linkgeotargeting.rb +0 -771
  250. data/lib/open_api_sdk/models/shared/linkschema.rb +0 -142
  251. data/lib/open_api_sdk/models/shared/notfound.rb +0 -24
  252. data/lib/open_api_sdk/models/shared/notfound_code.rb +0 -18
  253. data/lib/open_api_sdk/models/shared/notfound_error.rb +0 -30
  254. data/lib/open_api_sdk/models/shared/plan.rb +0 -24
  255. data/lib/open_api_sdk/models/shared/ratelimitexceeded.rb +0 -24
  256. data/lib/open_api_sdk/models/shared/ratelimitexceeded_code.rb +0 -18
  257. data/lib/open_api_sdk/models/shared/ratelimitexceeded_error.rb +0 -30
  258. data/lib/open_api_sdk/models/shared/role.rb +0 -19
  259. data/lib/open_api_sdk/models/shared/security.rb +0 -24
  260. data/lib/open_api_sdk/models/shared/tagschema.rb +0 -30
  261. data/lib/open_api_sdk/models/shared/unauthorized.rb +0 -24
  262. data/lib/open_api_sdk/models/shared/unauthorized_code.rb +0 -18
  263. data/lib/open_api_sdk/models/shared/unauthorized_error.rb +0 -30
  264. data/lib/open_api_sdk/models/shared/unprocessableentity.rb +0 -24
  265. data/lib/open_api_sdk/models/shared/unprocessableentity_code.rb +0 -18
  266. data/lib/open_api_sdk/models/shared/unprocessableentity_error.rb +0 -30
  267. data/lib/open_api_sdk/models/shared/users.rb +0 -24
  268. data/lib/open_api_sdk/models/shared/workspaceschema.rb +0 -81
  269. data/lib/open_api_sdk/models/shared.rb +0 -49
  270. data/lib/open_api_sdk/qr_codes.rb +0 -97
  271. data/lib/open_api_sdk/sdkconfiguration.rb +0 -52
  272. data/lib/open_api_sdk/tags.rb +0 -272
  273. data/lib/open_api_sdk/track.rb +0 -276
  274. data/lib/open_api_sdk/utils/metadata_fields.rb +0 -150
  275. data/lib/open_api_sdk/utils/t.rb +0 -59
  276. data/lib/open_api_sdk/utils/utils.rb +0 -772
  277. data/lib/open_api_sdk/workspaces.rb +0 -192
@@ -0,0 +1,82 @@
1
+ /*
2
+ ** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 roberto Exp $
3
+ ** Lua Parser
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef lparser_h
8
+ #define lparser_h
9
+
10
+ #include "llimits.h"
11
+ #include "lobject.h"
12
+ #include "lzio.h"
13
+
14
+
15
+ /*
16
+ ** Expression descriptor
17
+ */
18
+
19
+ typedef enum {
20
+ VVOID, /* no value */
21
+ VNIL,
22
+ VTRUE,
23
+ VFALSE,
24
+ VK, /* info = index of constant in `k' */
25
+ VKNUM, /* nval = numerical value */
26
+ VLOCAL, /* info = local register */
27
+ VUPVAL, /* info = index of upvalue in `upvalues' */
28
+ VGLOBAL, /* info = index of table; aux = index of global name in `k' */
29
+ VINDEXED, /* info = table register; aux = index register (or `k') */
30
+ VJMP, /* info = instruction pc */
31
+ VRELOCABLE, /* info = instruction pc */
32
+ VNONRELOC, /* info = result register */
33
+ VCALL, /* info = instruction pc */
34
+ VVARARG /* info = instruction pc */
35
+ } expkind;
36
+
37
+ typedef struct expdesc {
38
+ expkind k;
39
+ union {
40
+ struct { int info, aux; } s;
41
+ lua_Number nval;
42
+ } u;
43
+ int t; /* patch list of `exit when true' */
44
+ int f; /* patch list of `exit when false' */
45
+ } expdesc;
46
+
47
+
48
+ typedef struct upvaldesc {
49
+ lu_byte k;
50
+ lu_byte info;
51
+ } upvaldesc;
52
+
53
+
54
+ struct BlockCnt; /* defined in lparser.c */
55
+
56
+
57
+ /* state needed to generate code for a given function */
58
+ typedef struct FuncState {
59
+ Proto *f; /* current function header */
60
+ Table *h; /* table to find (and reuse) elements in `k' */
61
+ struct FuncState *prev; /* enclosing function */
62
+ struct LexState *ls; /* lexical state */
63
+ struct lua_State *L; /* copy of the Lua state */
64
+ struct BlockCnt *bl; /* chain of current blocks */
65
+ int pc; /* next position to code (equivalent to `ncode') */
66
+ int lasttarget; /* `pc' of last `jump target' */
67
+ int jpc; /* list of pending jumps to `pc' */
68
+ int freereg; /* first free register */
69
+ int nk; /* number of elements in `k' */
70
+ int np; /* number of elements in `p' */
71
+ short nlocvars; /* number of elements in `locvars' */
72
+ lu_byte nactvar; /* number of active local variables */
73
+ upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
74
+ unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
75
+ } FuncState;
76
+
77
+
78
+ LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
79
+ const char *name);
80
+
81
+
82
+ #endif
@@ -0,0 +1,214 @@
1
+ /*
2
+ ** $Id: lstate.c,v 2.36 2006/05/24 14:15:50 roberto Exp $
3
+ ** Global State
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+
8
+ #include <stddef.h>
9
+
10
+ #define lstate_c
11
+ #define LUA_CORE
12
+
13
+ #include "lua.h"
14
+
15
+ #include "ldebug.h"
16
+ #include "ldo.h"
17
+ #include "lfunc.h"
18
+ #include "lgc.h"
19
+ #include "llex.h"
20
+ #include "lmem.h"
21
+ #include "lstate.h"
22
+ #include "lstring.h"
23
+ #include "ltable.h"
24
+ #include "ltm.h"
25
+
26
+
27
+ #define state_size(x) (sizeof(x) + LUAI_EXTRASPACE)
28
+ #define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
29
+ #define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
30
+
31
+
32
+ /*
33
+ ** Main thread combines a thread state and the global state
34
+ */
35
+ typedef struct LG {
36
+ lua_State l;
37
+ global_State g;
38
+ } LG;
39
+
40
+
41
+
42
+ static void stack_init (lua_State *L1, lua_State *L) {
43
+ /* initialize CallInfo array */
44
+ L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
45
+ L1->ci = L1->base_ci;
46
+ L1->size_ci = BASIC_CI_SIZE;
47
+ L1->end_ci = L1->base_ci + L1->size_ci - 1;
48
+ /* initialize stack array */
49
+ L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);
50
+ L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;
51
+ L1->top = L1->stack;
52
+ L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
53
+ /* initialize first ci */
54
+ L1->ci->func = L1->top;
55
+ setnilvalue(L1->top++); /* `function' entry for this `ci' */
56
+ L1->base = L1->ci->base = L1->top;
57
+ L1->ci->top = L1->top + LUA_MINSTACK;
58
+ }
59
+
60
+
61
+ static void freestack (lua_State *L, lua_State *L1) {
62
+ luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
63
+ luaM_freearray(L, L1->stack, L1->stacksize, TValue);
64
+ }
65
+
66
+
67
+ /*
68
+ ** open parts that may cause memory-allocation errors
69
+ */
70
+ static void f_luaopen (lua_State *L, void *ud) {
71
+ global_State *g = G(L);
72
+ UNUSED(ud);
73
+ stack_init(L, L); /* init stack */
74
+ sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
75
+ sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
76
+ luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
77
+ luaT_init(L);
78
+ luaX_init(L);
79
+ luaS_fix(luaS_newliteral(L, MEMERRMSG));
80
+ g->GCthreshold = 4*g->totalbytes;
81
+ }
82
+
83
+
84
+ static void preinit_state (lua_State *L, global_State *g) {
85
+ G(L) = g;
86
+ L->stack = NULL;
87
+ L->stacksize = 0;
88
+ L->errorJmp = NULL;
89
+ L->hook = NULL;
90
+ L->hookmask = 0;
91
+ L->basehookcount = 0;
92
+ L->allowhook = 1;
93
+ resethookcount(L);
94
+ L->openupval = NULL;
95
+ L->size_ci = 0;
96
+ L->nCcalls = 0;
97
+ L->status = 0;
98
+ L->base_ci = L->ci = NULL;
99
+ L->savedpc = NULL;
100
+ L->errfunc = 0;
101
+ setnilvalue(gt(L));
102
+ }
103
+
104
+
105
+ static void close_state (lua_State *L) {
106
+ global_State *g = G(L);
107
+ luaF_close(L, L->stack); /* close all upvalues for this thread */
108
+ luaC_freeall(L); /* collect all objects */
109
+ lua_assert(g->rootgc == obj2gco(L));
110
+ lua_assert(g->strt.nuse == 0);
111
+ luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);
112
+ luaZ_freebuffer(L, &g->buff);
113
+ freestack(L, L);
114
+ lua_assert(g->totalbytes == sizeof(LG));
115
+ (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
116
+ }
117
+
118
+
119
+ lua_State *luaE_newthread (lua_State *L) {
120
+ lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
121
+ luaC_link(L, obj2gco(L1), LUA_TTHREAD);
122
+ preinit_state(L1, G(L));
123
+ stack_init(L1, L); /* init stack */
124
+ setobj2n(L, gt(L1), gt(L)); /* share table of globals */
125
+ L1->hookmask = L->hookmask;
126
+ L1->basehookcount = L->basehookcount;
127
+ L1->hook = L->hook;
128
+ resethookcount(L1);
129
+ lua_assert(iswhite(obj2gco(L1)));
130
+ return L1;
131
+ }
132
+
133
+
134
+ void luaE_freethread (lua_State *L, lua_State *L1) {
135
+ luaF_close(L1, L1->stack); /* close all upvalues for this thread */
136
+ lua_assert(L1->openupval == NULL);
137
+ luai_userstatefree(L1);
138
+ freestack(L, L1);
139
+ luaM_freemem(L, fromstate(L1), state_size(lua_State));
140
+ }
141
+
142
+
143
+ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
144
+ int i;
145
+ lua_State *L;
146
+ global_State *g;
147
+ void *l = (*f)(ud, NULL, 0, state_size(LG));
148
+ if (l == NULL) return NULL;
149
+ L = tostate(l);
150
+ g = &((LG *)L)->g;
151
+ L->next = NULL;
152
+ L->tt = LUA_TTHREAD;
153
+ g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
154
+ L->marked = luaC_white(g);
155
+ set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
156
+ preinit_state(L, g);
157
+ g->frealloc = f;
158
+ g->ud = ud;
159
+ g->mainthread = L;
160
+ g->uvhead.u.l.prev = &g->uvhead;
161
+ g->uvhead.u.l.next = &g->uvhead;
162
+ g->GCthreshold = 0; /* mark it as unfinished state */
163
+ g->strt.size = 0;
164
+ g->strt.nuse = 0;
165
+ g->strt.hash = NULL;
166
+ setnilvalue(registry(L));
167
+ luaZ_initbuffer(L, &g->buff);
168
+ g->panic = NULL;
169
+ g->gcstate = GCSpause;
170
+ g->rootgc = obj2gco(L);
171
+ g->sweepstrgc = 0;
172
+ g->sweepgc = &g->rootgc;
173
+ g->gray = NULL;
174
+ g->grayagain = NULL;
175
+ g->weak = NULL;
176
+ g->tmudata = NULL;
177
+ g->totalbytes = sizeof(LG);
178
+ g->gcpause = LUAI_GCPAUSE;
179
+ g->gcstepmul = LUAI_GCMUL;
180
+ g->gcdept = 0;
181
+ for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
182
+ if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
183
+ /* memory allocation error: free partial state */
184
+ close_state(L);
185
+ L = NULL;
186
+ }
187
+ else
188
+ luai_userstateopen(L);
189
+ return L;
190
+ }
191
+
192
+
193
+ static void callallgcTM (lua_State *L, void *ud) {
194
+ UNUSED(ud);
195
+ luaC_callGCTM(L); /* call GC metamethods for all udata */
196
+ }
197
+
198
+
199
+ LUA_API void lua_close (lua_State *L) {
200
+ L = G(L)->mainthread; /* only the main thread can be closed */
201
+ lua_lock(L);
202
+ luaF_close(L, L->stack); /* close all upvalues for this thread */
203
+ luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
204
+ L->errfunc = 0; /* no error function during GC metamethods */
205
+ do { /* repeat until no more errors */
206
+ L->ci = L->base_ci;
207
+ L->base = L->top = L->ci->base;
208
+ L->nCcalls = 0;
209
+ } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
210
+ lua_assert(G(L)->tmudata == NULL);
211
+ luai_userstateclose(L);
212
+ close_state(L);
213
+ }
214
+
@@ -0,0 +1,168 @@
1
+ /*
2
+ ** $Id: lstate.h,v 2.24 2006/02/06 18:27:59 roberto Exp $
3
+ ** Global State
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef lstate_h
8
+ #define lstate_h
9
+
10
+ #include "lua.h"
11
+
12
+ #include "lobject.h"
13
+ #include "ltm.h"
14
+ #include "lzio.h"
15
+
16
+
17
+
18
+ struct lua_longjmp; /* defined in ldo.c */
19
+
20
+
21
+ /* table of globals */
22
+ #define gt(L) (&L->l_gt)
23
+
24
+ /* registry */
25
+ #define registry(L) (&G(L)->l_registry)
26
+
27
+
28
+ /* extra stack space to handle TM calls and some other extras */
29
+ #define EXTRA_STACK 5
30
+
31
+
32
+ #define BASIC_CI_SIZE 8
33
+
34
+ #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
35
+
36
+
37
+
38
+ typedef struct stringtable {
39
+ GCObject **hash;
40
+ lu_int32 nuse; /* number of elements */
41
+ int size;
42
+ } stringtable;
43
+
44
+
45
+ /*
46
+ ** informations about a call
47
+ */
48
+ typedef struct CallInfo {
49
+ StkId base; /* base for this function */
50
+ StkId func; /* function index in the stack */
51
+ StkId top; /* top for this function */
52
+ const Instruction *savedpc;
53
+ int nresults; /* expected number of results from this function */
54
+ int tailcalls; /* number of tail calls lost under this entry */
55
+ } CallInfo;
56
+
57
+
58
+
59
+ #define curr_func(L) (clvalue(L->ci->func))
60
+ #define ci_func(ci) (clvalue((ci)->func))
61
+ #define f_isLua(ci) (!ci_func(ci)->c.isC)
62
+ #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
63
+
64
+
65
+ /*
66
+ ** `global state', shared by all threads of this state
67
+ */
68
+ typedef struct global_State {
69
+ stringtable strt; /* hash table for strings */
70
+ lua_Alloc frealloc; /* function to reallocate memory */
71
+ void *ud; /* auxiliary data to `frealloc' */
72
+ lu_byte currentwhite;
73
+ lu_byte gcstate; /* state of garbage collector */
74
+ int sweepstrgc; /* position of sweep in `strt' */
75
+ GCObject *rootgc; /* list of all collectable objects */
76
+ GCObject **sweepgc; /* position of sweep in `rootgc' */
77
+ GCObject *gray; /* list of gray objects */
78
+ GCObject *grayagain; /* list of objects to be traversed atomically */
79
+ GCObject *weak; /* list of weak tables (to be cleared) */
80
+ GCObject *tmudata; /* last element of list of userdata to be GC */
81
+ Mbuffer buff; /* temporary buffer for string concatentation */
82
+ lu_mem GCthreshold;
83
+ lu_mem totalbytes; /* number of bytes currently allocated */
84
+ lu_mem estimate; /* an estimate of number of bytes actually in use */
85
+ lu_mem gcdept; /* how much GC is `behind schedule' */
86
+ int gcpause; /* size of pause between successive GCs */
87
+ int gcstepmul; /* GC `granularity' */
88
+ lua_CFunction panic; /* to be called in unprotected errors */
89
+ TValue l_registry;
90
+ struct lua_State *mainthread;
91
+ UpVal uvhead; /* head of double-linked list of all open upvalues */
92
+ struct Table *mt[NUM_TAGS]; /* metatables for basic types */
93
+ TString *tmname[TM_N]; /* array with tag-method names */
94
+ } global_State;
95
+
96
+
97
+ /*
98
+ ** `per thread' state
99
+ */
100
+ struct lua_State {
101
+ CommonHeader;
102
+ lu_byte status;
103
+ StkId top; /* first free slot in the stack */
104
+ StkId base; /* base of current function */
105
+ global_State *l_G;
106
+ CallInfo *ci; /* call info for current function */
107
+ const Instruction *savedpc; /* `savedpc' of current function */
108
+ StkId stack_last; /* last free slot in the stack */
109
+ StkId stack; /* stack base */
110
+ CallInfo *end_ci; /* points after end of ci array*/
111
+ CallInfo *base_ci; /* array of CallInfo's */
112
+ int stacksize;
113
+ int size_ci; /* size of array `base_ci' */
114
+ unsigned short nCcalls; /* number of nested C calls */
115
+ lu_byte hookmask;
116
+ lu_byte allowhook;
117
+ int basehookcount;
118
+ int hookcount;
119
+ lua_Hook hook;
120
+ TValue l_gt; /* table of globals */
121
+ TValue env; /* temporary place for environments */
122
+ GCObject *openupval; /* list of open upvalues in this stack */
123
+ GCObject *gclist;
124
+ struct lua_longjmp *errorJmp; /* current error recover point */
125
+ ptrdiff_t errfunc; /* current error handling function (stack index) */
126
+ };
127
+
128
+
129
+ #define G(L) (L->l_G)
130
+
131
+
132
+ /*
133
+ ** Union of all collectable objects
134
+ */
135
+ union GCObject {
136
+ GCheader gch;
137
+ union TString ts;
138
+ union Udata u;
139
+ union Closure cl;
140
+ struct Table h;
141
+ struct Proto p;
142
+ struct UpVal uv;
143
+ struct lua_State th; /* thread */
144
+ };
145
+
146
+
147
+ /* macros to convert a GCObject into a specific value */
148
+ #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
149
+ #define gco2ts(o) (&rawgco2ts(o)->tsv)
150
+ #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
151
+ #define gco2u(o) (&rawgco2u(o)->uv)
152
+ #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
153
+ #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
154
+ #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
155
+ #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
156
+ #define ngcotouv(o) \
157
+ check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
158
+ #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
159
+
160
+ /* macro to convert any Lua object into a GCObject */
161
+ #define obj2gco(v) (cast(GCObject *, (v)))
162
+
163
+
164
+ LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
165
+ LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
166
+
167
+ #endif
168
+
@@ -0,0 +1,111 @@
1
+ /*
2
+ ** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp $
3
+ ** String table (keeps all strings handled by Lua)
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+
8
+ #include <string.h>
9
+
10
+ #define lstring_c
11
+ #define LUA_CORE
12
+
13
+ #include "lua.h"
14
+
15
+ #include "lmem.h"
16
+ #include "lobject.h"
17
+ #include "lstate.h"
18
+ #include "lstring.h"
19
+
20
+
21
+
22
+ void luaS_resize (lua_State *L, int newsize) {
23
+ GCObject **newhash;
24
+ stringtable *tb;
25
+ int i;
26
+ if (G(L)->gcstate == GCSsweepstring)
27
+ return; /* cannot resize during GC traverse */
28
+ newhash = luaM_newvector(L, newsize, GCObject *);
29
+ tb = &G(L)->strt;
30
+ for (i=0; i<newsize; i++) newhash[i] = NULL;
31
+ /* rehash */
32
+ for (i=0; i<tb->size; i++) {
33
+ GCObject *p = tb->hash[i];
34
+ while (p) { /* for each node in the list */
35
+ GCObject *next = p->gch.next; /* save next */
36
+ unsigned int h = gco2ts(p)->hash;
37
+ int h1 = lmod(h, newsize); /* new position */
38
+ lua_assert(cast_int(h%newsize) == lmod(h, newsize));
39
+ p->gch.next = newhash[h1]; /* chain it */
40
+ newhash[h1] = p;
41
+ p = next;
42
+ }
43
+ }
44
+ luaM_freearray(L, tb->hash, tb->size, TString *);
45
+ tb->size = newsize;
46
+ tb->hash = newhash;
47
+ }
48
+
49
+
50
+ static TString *newlstr (lua_State *L, const char *str, size_t l,
51
+ unsigned int h) {
52
+ TString *ts;
53
+ stringtable *tb;
54
+ if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
55
+ luaM_toobig(L);
56
+ ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
57
+ ts->tsv.len = l;
58
+ ts->tsv.hash = h;
59
+ ts->tsv.marked = luaC_white(G(L));
60
+ ts->tsv.tt = LUA_TSTRING;
61
+ ts->tsv.reserved = 0;
62
+ memcpy(ts+1, str, l*sizeof(char));
63
+ ((char *)(ts+1))[l] = '\0'; /* ending 0 */
64
+ tb = &G(L)->strt;
65
+ h = lmod(h, tb->size);
66
+ ts->tsv.next = tb->hash[h]; /* chain new entry */
67
+ tb->hash[h] = obj2gco(ts);
68
+ tb->nuse++;
69
+ if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
70
+ luaS_resize(L, tb->size*2); /* too crowded */
71
+ return ts;
72
+ }
73
+
74
+
75
+ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
76
+ GCObject *o;
77
+ unsigned int h = cast(unsigned int, l); /* seed */
78
+ size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
79
+ size_t l1;
80
+ for (l1=l; l1>=step; l1-=step) /* compute hash */
81
+ h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
82
+ for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
83
+ o != NULL;
84
+ o = o->gch.next) {
85
+ TString *ts = rawgco2ts(o);
86
+ if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
87
+ /* string may be dead */
88
+ if (isdead(G(L), o)) changewhite(o);
89
+ return ts;
90
+ }
91
+ }
92
+ return newlstr(L, str, l, h); /* not found */
93
+ }
94
+
95
+
96
+ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
97
+ Udata *u;
98
+ if (s > MAX_SIZET - sizeof(Udata))
99
+ luaM_toobig(L);
100
+ u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
101
+ u->uv.marked = luaC_white(G(L)); /* is not finalized */
102
+ u->uv.tt = LUA_TUSERDATA;
103
+ u->uv.len = s;
104
+ u->uv.metatable = NULL;
105
+ u->uv.env = e;
106
+ /* chain it on udata list (after main thread) */
107
+ u->uv.next = G(L)->mainthread->next;
108
+ G(L)->mainthread->next = obj2gco(u);
109
+ return u;
110
+ }
111
+
@@ -0,0 +1,31 @@
1
+ /*
2
+ ** $Id: lstring.h,v 1.43 2005/04/25 19:24:10 roberto Exp $
3
+ ** String table (keep all strings handled by Lua)
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef lstring_h
8
+ #define lstring_h
9
+
10
+
11
+ #include "lgc.h"
12
+ #include "lobject.h"
13
+ #include "lstate.h"
14
+
15
+
16
+ #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
17
+
18
+ #define sizeudata(u) (sizeof(union Udata)+(u)->len)
19
+
20
+ #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
21
+ #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
22
+ (sizeof(s)/sizeof(char))-1))
23
+
24
+ #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
25
+
26
+ LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
27
+ LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
28
+ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
29
+
30
+
31
+ #endif