mirror of
https://github.com/lua/lua.git
synced 2026-07-27 08:29:08 +00:00
Compare commits
952 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2fc2ce8df | ||
|
|
a241b6cb3c | ||
|
|
f0d143f30f | ||
|
|
c82087b8dd | ||
|
|
138be5b843 | ||
|
|
e320b5b672 | ||
|
|
ca9c405fef | ||
|
|
e2feb886d6 | ||
|
|
5999e14ad9 | ||
|
|
01747f2c24 | ||
|
|
7377fbdebc | ||
|
|
f1d2ac3a98 | ||
|
|
c5da4f4cd0 | ||
|
|
7bcb2462e4 | ||
|
|
0bd99b327b | ||
|
|
6d8b672094 | ||
|
|
e21b26a964 | ||
|
|
0f388193b3 | ||
|
|
7948b8568e | ||
|
|
61b1d9a466 | ||
|
|
3617e04e97 | ||
|
|
8c62bde36f | ||
|
|
51650eac78 | ||
|
|
aea68e5c54 | ||
|
|
ece042fef0 | ||
|
|
217b65e6d9 | ||
|
|
8119374e74 | ||
|
|
3a997eefb5 | ||
|
|
5184ff2096 | ||
|
|
b0cbe77816 | ||
|
|
6e899850b9 | ||
|
|
fded7bef19 | ||
|
|
b5d7255034 | ||
|
|
6cce5c0601 | ||
|
|
eb70f58279 | ||
|
|
ef900f224c | ||
|
|
3105febf9a | ||
|
|
7133e20c94 | ||
|
|
888d39ea75 | ||
|
|
eef22fa4ce | ||
|
|
eda87f1156 | ||
|
|
e0e406ead3 | ||
|
|
30cea671a7 | ||
|
|
a716ae1f50 | ||
|
|
ea382b0be1 | ||
|
|
6d8d282e0f | ||
|
|
00c8a17a2d | ||
|
|
166ce15512 | ||
|
|
87cf2bf711 | ||
|
|
fd8a849621 | ||
|
|
5a568a3b01 | ||
|
|
475e6c5352 | ||
|
|
af00a0772c | ||
|
|
6819c2a98a | ||
|
|
1dd8af67b6 | ||
|
|
1350a2bcb5 | ||
|
|
217e67cb22 | ||
|
|
9bbfe9f3fd | ||
|
|
788a0ecd27 | ||
|
|
6d86b937e4 | ||
|
|
bc90cf4b83 | ||
|
|
d79190e27f | ||
|
|
9caf5b4f79 | ||
|
|
50cddefeeb | ||
|
|
e24f1ee9ff | ||
|
|
f3b0eb3ecf | ||
|
|
162ce8256e | ||
|
|
ad90447eb6 | ||
|
|
87912786af | ||
|
|
5645a84368 | ||
|
|
95ed6c1127 | ||
|
|
12ab78aca6 | ||
|
|
45c346645c | ||
|
|
68ce878292 | ||
|
|
500336efd0 | ||
|
|
5ea8f108e1 | ||
|
|
2275030b86 | ||
|
|
05de314701 | ||
|
|
d281d23f8d | ||
|
|
ec431ce5db | ||
|
|
c8f47c2934 | ||
|
|
ca458f1f52 | ||
|
|
121dc8af66 | ||
|
|
a8675966ec | ||
|
|
3dc5475e23 | ||
|
|
8a008a2057 | ||
|
|
89b59eee73 | ||
|
|
166dd0261a | ||
|
|
51471ba748 | ||
|
|
0b65cb74cd | ||
|
|
ea46b750dc | ||
|
|
92afcf2823 | ||
|
|
b5bf7d9ef4 | ||
|
|
6a5d89b39f | ||
|
|
ae14adc272 | ||
|
|
ff98f17d27 | ||
|
|
59bcd137ae | ||
|
|
5ab6d36d99 | ||
|
|
43c873895f | ||
|
|
03a078493e | ||
|
|
bae57ea088 | ||
|
|
2557107e91 | ||
|
|
32a12e2f3f | ||
|
|
559bb554c9 | ||
|
|
fd5e810e08 | ||
|
|
067f761739 | ||
|
|
7978a8d8b2 | ||
|
|
32e09c2a16 | ||
|
|
df19931ddc | ||
|
|
b5084fdafe | ||
|
|
d8200d5f3c | ||
|
|
79cbc3468c | ||
|
|
9e89a55a4f | ||
|
|
b707e81c3d | ||
|
|
ee37ee50d6 | ||
|
|
ad1a54b5c0 | ||
|
|
88c29c0cd5 | ||
|
|
d93df22bf6 | ||
|
|
5017cc6ba2 | ||
|
|
2f125ebc33 | ||
|
|
49a01c0991 | ||
|
|
17526ed2fe | ||
|
|
f180822fa6 | ||
|
|
594220c624 | ||
|
|
3dd68624dc | ||
|
|
f9eea453b7 | ||
|
|
374773748b | ||
|
|
29644366fc | ||
|
|
6eadedbfa1 | ||
|
|
1978094b3a | ||
|
|
5acc5b0c1e | ||
|
|
59547c6cda | ||
|
|
3d3355b4f3 | ||
|
|
801f43f09a | ||
|
|
719c01359f | ||
|
|
43f13729a2 | ||
|
|
136f8e148d | ||
|
|
f90a130b07 | ||
|
|
cb4950a6d8 | ||
|
|
fdede85419 | ||
|
|
beab626061 | ||
|
|
817f8674af | ||
|
|
cf0562e1e7 | ||
|
|
22e1c5ebad | ||
|
|
470dd56a89 | ||
|
|
20d30bcd33 | ||
|
|
44b6f496b5 | ||
|
|
fd80e63468 | ||
|
|
f62565abea | ||
|
|
c9d1d9f9c6 | ||
|
|
35391d9b1a | ||
|
|
99b1b8e918 | ||
|
|
3b44821334 | ||
|
|
0214dab989 | ||
|
|
821bd7025e | ||
|
|
9b7dddad7d | ||
|
|
3f04a9f2c0 | ||
|
|
2a59a999d4 | ||
|
|
ee7d0c2649 | ||
|
|
aa13c591f5 | ||
|
|
6c8a32217a | ||
|
|
cb09f4fef4 | ||
|
|
3cf1729a02 | ||
|
|
74b0bb3a45 | ||
|
|
e4076fe6d9 | ||
|
|
81952e6884 | ||
|
|
25b4e35ee8 | ||
|
|
7e1facaa4e | ||
|
|
ad2531a0ee | ||
|
|
bc1c718cc0 | ||
|
|
c9ce754e38 | ||
|
|
d34271fe42 | ||
|
|
d120ec29ca | ||
|
|
2aff901c93 | ||
|
|
bad231c481 | ||
|
|
a2b1c279f1 | ||
|
|
2f128c5130 | ||
|
|
4758113043 | ||
|
|
a4e644add2 | ||
|
|
05ca63642b | ||
|
|
f17e3624ef | ||
|
|
2e9b8476ca | ||
|
|
c31f4946e9 | ||
|
|
c86586e866 | ||
|
|
19fbdf6cae | ||
|
|
427ee519db | ||
|
|
a958b711f5 | ||
|
|
1ffdd0bc7a | ||
|
|
5286650894 | ||
|
|
0fb1644c60 | ||
|
|
119d5e46d5 | ||
|
|
83abbac946 | ||
|
|
a25416a8d5 | ||
|
|
682cce3813 | ||
|
|
d806710ab5 | ||
|
|
e049abb69a | ||
|
|
98816d0ce5 | ||
|
|
7482e8f914 | ||
|
|
03b769053a | ||
|
|
3c710f056b | ||
|
|
c0a865fa54 | ||
|
|
0009ac1f3a | ||
|
|
7b968bb514 | ||
|
|
bf8b08295a | ||
|
|
3f5b56c48b | ||
|
|
e7192dfdbb | ||
|
|
0539f48661 | ||
|
|
e7a9c45a48 | ||
|
|
fd6c1f4898 | ||
|
|
f079749287 | ||
|
|
f8d677f94c | ||
|
|
094a7d0290 | ||
|
|
7cc0e63d8a | ||
|
|
a4a8914c20 | ||
|
|
06c7efb4a9 | ||
|
|
dd547c55c8 | ||
|
|
f6bd8b1147 | ||
|
|
a7faa557fa | ||
|
|
026a7e92be | ||
|
|
c4ea0c3b29 | ||
|
|
7106c491dd | ||
|
|
a10d495b18 | ||
|
|
c2e3cc4c89 | ||
|
|
67feed49f1 | ||
|
|
b63b0928cf | ||
|
|
511679313f | ||
|
|
868ff40339 | ||
|
|
aa6faa6331 | ||
|
|
0b3f4e254e | ||
|
|
551b076f1c | ||
|
|
737f119187 | ||
|
|
8980c630bf | ||
|
|
8d579c5bc5 | ||
|
|
d51743b0c7 | ||
|
|
1a92c2b354 | ||
|
|
fe0d54d37e | ||
|
|
c9af0768fc | ||
|
|
7e0caa7d61 | ||
|
|
a40768e5ea | ||
|
|
4a83fe569c | ||
|
|
b83b6ba015 | ||
|
|
af119c8b55 | ||
|
|
1aead7f553 | ||
|
|
75d8470f0f | ||
|
|
81646af13b | ||
|
|
233b71c092 | ||
|
|
ccc4fc9cf0 | ||
|
|
c79b4a97aa | ||
|
|
ac3afc7cd4 | ||
|
|
350cc4bcb6 | ||
|
|
35931bbed4 | ||
|
|
12779b2b71 | ||
|
|
7ca1bd639f | ||
|
|
9b7a12c46d | ||
|
|
5b33e39855 | ||
|
|
a64cf8fac9 | ||
|
|
092fa71ddd | ||
|
|
a2eaad5d81 | ||
|
|
54771c5afa | ||
|
|
bcce769d29 | ||
|
|
24baa919c1 | ||
|
|
d1c0efdb7d | ||
|
|
566758de79 | ||
|
|
50334faad6 | ||
|
|
cee7a8e1ec | ||
|
|
8c21f463ed | ||
|
|
a1952d9c41 | ||
|
|
1a46a713d2 | ||
|
|
23b9ceb0a4 | ||
|
|
0a6a6b9d9d | ||
|
|
1b54197491 | ||
|
|
c97aa9485c | ||
|
|
e885b91326 | ||
|
|
fa1f724378 | ||
|
|
2a966116b1 | ||
|
|
43ec354722 | ||
|
|
700b003fb5 | ||
|
|
f722ba6890 | ||
|
|
c7d4da8746 | ||
|
|
f1629217f1 | ||
|
|
fdd5f2f7a3 | ||
|
|
c6ef3e2672 | ||
|
|
ba8dca00ac | ||
|
|
9be89a1864 | ||
|
|
b9f371a3c2 | ||
|
|
4834de8427 | ||
|
|
94043a3a1a | ||
|
|
e642cc4206 | ||
|
|
da57477c3d | ||
|
|
f39034889d | ||
|
|
6b053a63cb | ||
|
|
572e5e6b28 | ||
|
|
6098e06e09 | ||
|
|
c6b64ffe65 | ||
|
|
4590a89b32 | ||
|
|
1475cb59bf | ||
|
|
9e8e60dd5f | ||
|
|
d72ec210c7 | ||
|
|
c77baf752c | ||
|
|
a122688091 | ||
|
|
f3026c36c2 | ||
|
|
cd0ebd0a80 | ||
|
|
8bc33a088c | ||
|
|
c3eb89544f | ||
|
|
ffff9a49da | ||
|
|
b22356e5c5 | ||
|
|
a289a62717 | ||
|
|
e3eabcf913 | ||
|
|
0df2238063 | ||
|
|
6828f6d427 | ||
|
|
daa5fe3e31 | ||
|
|
8d9ea59d28 | ||
|
|
5e7dbd0b8b | ||
|
|
cd6c276e41 | ||
|
|
fd4b4a2a68 | ||
|
|
d447945685 | ||
|
|
78f9635111 | ||
|
|
8b7cf8c62d | ||
|
|
73b0a3451d | ||
|
|
85c1461422 | ||
|
|
5ba556d27a | ||
|
|
81dd13f4c6 | ||
|
|
6a02bbe1e2 | ||
|
|
7631c29b2f | ||
|
|
a9dc7c8828 | ||
|
|
7192afafee | ||
|
|
a139e2e003 | ||
|
|
a71c5f6f53 | ||
|
|
d9ea6eca7c | ||
|
|
ca3865cf1b | ||
|
|
bef5980744 | ||
|
|
409741e900 | ||
|
|
b98de30b8f | ||
|
|
9f48712c15 | ||
|
|
bd262d591f | ||
|
|
0d116c3ada | ||
|
|
79f11fb2bb | ||
|
|
fabe4ec487 | ||
|
|
575074fd85 | ||
|
|
545f43065f | ||
|
|
3819c30e55 | ||
|
|
e94fac8956 | ||
|
|
2c1a5d678d | ||
|
|
bd619b9311 | ||
|
|
aca84ee1a0 | ||
|
|
5038e3c58c | ||
|
|
5a7dee0c5d | ||
|
|
ddf1f2a053 | ||
|
|
e34d3c06b0 | ||
|
|
e8a2c36909 | ||
|
|
3c39a0e8cb | ||
|
|
3d45a8eb1c | ||
|
|
3d80aeab5a | ||
|
|
3811e23b32 | ||
|
|
12c764ed1e | ||
|
|
e99e9a9473 | ||
|
|
f35ac38e1d | ||
|
|
058279d548 | ||
|
|
69ba1ac441 | ||
|
|
4a925c1552 | ||
|
|
cf531912f2 | ||
|
|
0d00729e31 | ||
|
|
b6e9fcbd70 | ||
|
|
8554baeacf | ||
|
|
f5b7f077ec | ||
|
|
e924a7f9ea | ||
|
|
4fd76b8148 | ||
|
|
de0f51a02c | ||
|
|
0567221848 | ||
|
|
1c1a98e872 | ||
|
|
c006f085d9 | ||
|
|
a48e330f37 | ||
|
|
dcc070683c | ||
|
|
2d81cfa4e1 | ||
|
|
0bccf03d7e | ||
|
|
ad2b5decc8 | ||
|
|
32c1764b5d | ||
|
|
de97177744 | ||
|
|
fa2ddb070a | ||
|
|
0fac33da9e | ||
|
|
8e1bdda66a | ||
|
|
9c1347e647 | ||
|
|
b373a40133 | ||
|
|
25951e0ea5 | ||
|
|
a4f20e3c8b | ||
|
|
8c583c61a3 | ||
|
|
d2ea5b00b7 | ||
|
|
d77898597e | ||
|
|
237f755dca | ||
|
|
7444b5a1d5 | ||
|
|
e7ce7e1850 | ||
|
|
3e662cec89 | ||
|
|
fde866e303 | ||
|
|
2d7a81a204 | ||
|
|
658ea8752b | ||
|
|
aa73403ba4 | ||
|
|
0c27de2e7b | ||
|
|
d25f7f9d78 | ||
|
|
85555646e3 | ||
|
|
4d871ee973 | ||
|
|
b9e1dec2cb | ||
|
|
dc2b8a0073 | ||
|
|
9a9fe42deb | ||
|
|
0062db1e06 | ||
|
|
23001d8607 | ||
|
|
5d79c6684b | ||
|
|
3410dcd375 | ||
|
|
5a7a0c72d8 | ||
|
|
ee7478e884 | ||
|
|
aaa5d7adab | ||
|
|
3eb1788bb4 | ||
|
|
00114a95b2 | ||
|
|
4aaf0ef75c | ||
|
|
ed720d09f3 | ||
|
|
376e939ef6 | ||
|
|
9d28e2b3e5 | ||
|
|
49ca1f7083 | ||
|
|
4db6f20770 | ||
|
|
cca71912e6 | ||
|
|
8003e9544d | ||
|
|
973d81efb3 | ||
|
|
26d4a73962 | ||
|
|
99a39f6f4a | ||
|
|
1bb407e494 | ||
|
|
53f9499f7f | ||
|
|
575befc394 | ||
|
|
e7ffb1b501 | ||
|
|
c066ac10a9 | ||
|
|
1e6940f291 | ||
|
|
d8d81ba891 | ||
|
|
cf22133b69 | ||
|
|
b7be05ad27 | ||
|
|
afdb19ac82 | ||
|
|
7dfa4cd655 | ||
|
|
fc6203ee43 | ||
|
|
b2dd246b7a | ||
|
|
d20ff60615 | ||
|
|
d41b467320 | ||
|
|
4541243355 | ||
|
|
9100f7479a | ||
|
|
055104f5b6 | ||
|
|
28aa733c15 | ||
|
|
6abde1b05a | ||
|
|
d394d5536a | ||
|
|
a2f98314a3 | ||
|
|
a09c8d7beb | ||
|
|
f80ff7a336 | ||
|
|
a08fc34ee4 | ||
|
|
d00d2eaf51 | ||
|
|
11126422d9 | ||
|
|
e54668b696 | ||
|
|
9eb832de54 | ||
|
|
82a1f5d354 | ||
|
|
a8d3aa14fd | ||
|
|
064e406f67 | ||
|
|
5c87f61e6b | ||
|
|
3aa9598177 | ||
|
|
64d39ed1b6 | ||
|
|
4433dbb5f5 | ||
|
|
5cb128ea54 | ||
|
|
74123e9686 | ||
|
|
9c196bebad | ||
|
|
28b2566c97 | ||
|
|
caf74dd731 | ||
|
|
62840c5fad | ||
|
|
5ca7cdd709 | ||
|
|
1514e49d43 | ||
|
|
22ef84b6c8 | ||
|
|
63a2b62468 | ||
|
|
489253d753 | ||
|
|
25c557ec63 | ||
|
|
f292760f12 | ||
|
|
1124cb1247 | ||
|
|
c295147874 | ||
|
|
e560ac4862 | ||
|
|
915a9a912c | ||
|
|
ae0a5e2142 | ||
|
|
347f0c33d1 | ||
|
|
622e448710 | ||
|
|
0fe2576a39 | ||
|
|
d08d237a49 | ||
|
|
64a7ec987c | ||
|
|
4274738e81 | ||
|
|
0d7d559dcc | ||
|
|
af512ad6da | ||
|
|
d27108ccd5 | ||
|
|
a838b3b496 | ||
|
|
4c54cd3a10 | ||
|
|
c8ff7de7f0 | ||
|
|
3bae8e047c | ||
|
|
4f5f2fe367 | ||
|
|
01586d539e | ||
|
|
c8ab34ab7a | ||
|
|
36ab1ee10c | ||
|
|
193ce46970 | ||
|
|
b678f246a4 | ||
|
|
f270e7f044 | ||
|
|
070d3743a7 | ||
|
|
0c7de97d47 | ||
|
|
900b7d4514 | ||
|
|
91f0b20a0e | ||
|
|
e4b4623abc | ||
|
|
cef96b73e1 | ||
|
|
427e01eb63 | ||
|
|
d320c908d0 | ||
|
|
8bfc696676 | ||
|
|
97a35e70af | ||
|
|
03b556b963 | ||
|
|
572b94bbcb | ||
|
|
692209fa8d | ||
|
|
953d499ea2 | ||
|
|
a541ada194 | ||
|
|
55d3138397 | ||
|
|
e74e56f2b1 | ||
|
|
1ebf109c53 | ||
|
|
f75be1cb28 | ||
|
|
16d2ad88fe | ||
|
|
f3a6815000 | ||
|
|
19f8c87375 | ||
|
|
5bcfe0c700 | ||
|
|
8cd395564c | ||
|
|
389c890ed3 | ||
|
|
e3866afa97 | ||
|
|
25189b420d | ||
|
|
cec25167d1 | ||
|
|
1fd4c482a0 | ||
|
|
35e729fa6d | ||
|
|
0dc09cb42e | ||
|
|
cc1cbd19a0 | ||
|
|
cb3f95d516 | ||
|
|
f84b575cfa | ||
|
|
3cb343efd6 | ||
|
|
ec0fc1a13b | ||
|
|
c3a6f3fa1c | ||
|
|
0bbdddc86b | ||
|
|
b3b8dfaaea | ||
|
|
adc6a4865b | ||
|
|
2108754e46 | ||
|
|
46f1429936 | ||
|
|
e0f9d1c8f5 | ||
|
|
de6fc75d63 | ||
|
|
2af0d3b459 | ||
|
|
9fbe0690fb | ||
|
|
a25b8ff69c | ||
|
|
15b823ce4f | ||
|
|
8da245bfd2 | ||
|
|
a2a2abcba4 | ||
|
|
2e51792596 | ||
|
|
3a9ae612a4 | ||
|
|
9db693a57c | ||
|
|
1375435e4a | ||
|
|
2bb19ccf08 | ||
|
|
64d5df7772 | ||
|
|
2643da67c6 | ||
|
|
ed117bb42a | ||
|
|
a4472490bc | ||
|
|
86312e1a7d | ||
|
|
df1dc3f1f5 | ||
|
|
513d0258d9 | ||
|
|
cfa8bc3ca4 | ||
|
|
a654e82f5c | ||
|
|
3e41afcec5 | ||
|
|
3acf5ec5a1 | ||
|
|
93695db903 | ||
|
|
9107dd115c | ||
|
|
dc4c459546 | ||
|
|
19a6c38745 | ||
|
|
3c4d970a7b | ||
|
|
b0f2b288a6 | ||
|
|
2b25489b47 | ||
|
|
a6f465f558 | ||
|
|
9a41506b8f | ||
|
|
9a6d9ea57a | ||
|
|
062e809e54 | ||
|
|
b4c1824824 | ||
|
|
2e5ef6a9fb | ||
|
|
1dea393058 | ||
|
|
45dec34597 | ||
|
|
b40a38a8ac | ||
|
|
ac899a6307 | ||
|
|
ce444bff33 | ||
|
|
2d5931ebc8 | ||
|
|
35fa276099 | ||
|
|
b51d76ce8d | ||
|
|
95020afb63 | ||
|
|
c5050b1c41 | ||
|
|
b9063a08f5 | ||
|
|
7fe405739c | ||
|
|
1ce819333d | ||
|
|
88eb901f81 | ||
|
|
2583bac3d3 | ||
|
|
63a3b1a1eb | ||
|
|
fbf866a1a5 | ||
|
|
49a67c6d3f | ||
|
|
a921d81033 | ||
|
|
155dd01163 | ||
|
|
599789a907 | ||
|
|
9756f56354 | ||
|
|
b7d5f18d71 | ||
|
|
5598b2bc55 | ||
|
|
77077b39d5 | ||
|
|
5bc91c6405 | ||
|
|
f5073de0a7 | ||
|
|
f6ed285cf2 | ||
|
|
1448e736f0 | ||
|
|
6e415e9387 | ||
|
|
b114c99a60 | ||
|
|
916587508c | ||
|
|
a5382b763c | ||
|
|
ba21aa8b2b | ||
|
|
d119cf3035 | ||
|
|
0ac3d07ea6 | ||
|
|
5938212748 | ||
|
|
1829911d7c | ||
|
|
bed2cb725a | ||
|
|
ab75bd23ee | ||
|
|
cee94df6e0 | ||
|
|
fcc46467fa | ||
|
|
f8e354e240 | ||
|
|
a650378822 | ||
|
|
99182c6872 | ||
|
|
67cae2854c | ||
|
|
0e45ffb8e4 | ||
|
|
071e54ae0b | ||
|
|
a68494fb32 | ||
|
|
4b44793dc5 | ||
|
|
90e2a716c8 | ||
|
|
d9fbbe1f23 | ||
|
|
4a714cebd1 | ||
|
|
5b6be84106 | ||
|
|
b2bb2f7f59 | ||
|
|
f096ab5421 | ||
|
|
4e1ffc482a | ||
|
|
bc439e21cd | ||
|
|
1b4480003b | ||
|
|
42167804b8 | ||
|
|
3135a6bbab | ||
|
|
95cbc402dc | ||
|
|
decada8dc2 | ||
|
|
ee5d03b42a | ||
|
|
323f33d014 | ||
|
|
55dc7fb240 | ||
|
|
11d7ba79f2 | ||
|
|
bd5fa9cc8f | ||
|
|
2658c94925 | ||
|
|
215885768c | ||
|
|
a5f68589c0 | ||
|
|
28419c4383 | ||
|
|
5bff2aaf47 | ||
|
|
f76f4cb79d | ||
|
|
abb85fc059 | ||
|
|
aabe3ddbf4 | ||
|
|
0c258c8492 | ||
|
|
d57c9cdefc | ||
|
|
afb3f7e754 | ||
|
|
88564c3aec | ||
|
|
3abe3da9fb | ||
|
|
eb8499c8e0 | ||
|
|
47c562435b | ||
|
|
02504d86d3 | ||
|
|
4a818f068a | ||
|
|
1d6ebce296 | ||
|
|
bc3e02a1b7 | ||
|
|
f4eed60ca9 | ||
|
|
c1de1fdac6 | ||
|
|
a36c8e1718 | ||
|
|
d7872dcf91 | ||
|
|
14115170bc | ||
|
|
ec52149485 | ||
|
|
6980cb1aa7 | ||
|
|
59a59fafc6 | ||
|
|
2bdd194f43 | ||
|
|
96fa34ec32 | ||
|
|
6a024df440 | ||
|
|
77fd93188e | ||
|
|
a21c89ddc8 | ||
|
|
49b88b1c39 | ||
|
|
3db5f60547 | ||
|
|
2258ec6bc9 | ||
|
|
2598138ece | ||
|
|
4a67e48611 | ||
|
|
5cdec7d124 | ||
|
|
9423e22aa3 | ||
|
|
57f8414de1 | ||
|
|
139d562861 | ||
|
|
eea6d10866 | ||
|
|
019ebcb85f | ||
|
|
889284ebd0 | ||
|
|
6956331093 | ||
|
|
92479f1a8b | ||
|
|
e67dc3a227 | ||
|
|
0cc3add9f8 | ||
|
|
71c2eeff98 | ||
|
|
d7bc346d7a | ||
|
|
673c456cba | ||
|
|
ea44570883 | ||
|
|
e091a254df | ||
|
|
58c3aa8b5f | ||
|
|
c1f78ff3d3 | ||
|
|
e5249b9fb5 | ||
|
|
d3037d97ec | ||
|
|
c6b442bd36 | ||
|
|
4f88418170 | ||
|
|
311e9f3ceb | ||
|
|
8775f25830 | ||
|
|
70a63fa5ad | ||
|
|
fffbaede75 | ||
|
|
ae9ad6c694 | ||
|
|
83d2dbb15d | ||
|
|
4e43741943 | ||
|
|
a274596ecc | ||
|
|
7e9bc41fe7 | ||
|
|
b1e1c15ced | ||
|
|
3dbf305408 | ||
|
|
6d0ae11c57 | ||
|
|
3ca739b418 | ||
|
|
9e613b8583 | ||
|
|
9428ec42d0 | ||
|
|
6ffcf21367 | ||
|
|
6427c61e7c | ||
|
|
ba484b9eb1 | ||
|
|
f9d015523e | ||
|
|
1817dfc301 | ||
|
|
7837e34e56 | ||
|
|
910310d3ba | ||
|
|
facfcd497f | ||
|
|
b403317325 | ||
|
|
9bf05e7364 | ||
|
|
e39e758a73 | ||
|
|
5438d77221 | ||
|
|
6905ae900b | ||
|
|
ada82930fd | ||
|
|
f36e319658 | ||
|
|
0cea28a785 | ||
|
|
d2ebdc045b | ||
|
|
81ede6bfce | ||
|
|
2b579b4b83 | ||
|
|
a1d0e1a11a | ||
|
|
8975739839 | ||
|
|
d07abcc6c7 | ||
|
|
189378142a | ||
|
|
82749b765e | ||
|
|
2b590aea40 | ||
|
|
547e47649f | ||
|
|
41dd32e18e | ||
|
|
5d3cc5def8 | ||
|
|
53db607963 | ||
|
|
cbf0c7a103 | ||
|
|
4c399c5dfb | ||
|
|
b472098493 | ||
|
|
84b3daebbd | ||
|
|
f6978173e0 | ||
|
|
e02483dbc0 | ||
|
|
9e58e0df8f | ||
|
|
690efef3de | ||
|
|
b9e92c8b0d | ||
|
|
4376c9bc5f | ||
|
|
f94cd2201c | ||
|
|
fdbb243ff9 | ||
|
|
c1565c16ed | ||
|
|
394646891c | ||
|
|
d69aa51088 | ||
|
|
afe849c9b4 | ||
|
|
ccd678ea3e | ||
|
|
bb92ef23cb | ||
|
|
bb48f456d9 | ||
|
|
df802dc74b | ||
|
|
e23da9edee | ||
|
|
4db2cddeee | ||
|
|
f9dec5fc84 | ||
|
|
6b8725b0ee | ||
|
|
6955666290 | ||
|
|
5298392c5a | ||
|
|
1ceec74370 | ||
|
|
2a84c29bc3 | ||
|
|
4d8a1103d3 | ||
|
|
202de59254 | ||
|
|
f858a155c2 | ||
|
|
9e7de9473c | ||
|
|
0c8f5fc2fd | ||
|
|
1527d8f00d | ||
|
|
8efaf8af81 | ||
|
|
c3525610fe | ||
|
|
7ba62e2985 | ||
|
|
8fd28611d5 | ||
|
|
93869acb2c | ||
|
|
480a1da34a | ||
|
|
59e2973335 | ||
|
|
5d09be4832 | ||
|
|
860e285f31 | ||
|
|
eb8ac6e2a0 | ||
|
|
b1203e036d | ||
|
|
92a0d4c67f | ||
|
|
5fa55df2ca | ||
|
|
a3af42de8e | ||
|
|
198be23f36 | ||
|
|
24359ae294 | ||
|
|
6c84722afa | ||
|
|
facb0519a0 | ||
|
|
ffdca3522e | ||
|
|
4d7469b610 | ||
|
|
2b84e36b93 | ||
|
|
85bda9eef5 | ||
|
|
a4d3080fe3 | ||
|
|
5627d51e05 | ||
|
|
e64b0cada8 | ||
|
|
7316d61a66 | ||
|
|
e2b366c760 | ||
|
|
fa19baab7f | ||
|
|
2f8351fe48 | ||
|
|
32d42bdcdc | ||
|
|
843d53aabb | ||
|
|
5ac3386888 | ||
|
|
6d182faab6 | ||
|
|
f86f4116c8 | ||
|
|
7f69f0efb0 | ||
|
|
f6cab9666c | ||
|
|
3deb38814d | ||
|
|
3b5b14a085 | ||
|
|
aec671c126 | ||
|
|
dd92af69db | ||
|
|
015e973899 | ||
|
|
163f58dac5 | ||
|
|
dcee7d2fe0 | ||
|
|
5f0a2f6248 | ||
|
|
a73930228a | ||
|
|
a76fa25199 | ||
|
|
dd3519ab89 | ||
|
|
3a515df086 | ||
|
|
74897bc52f | ||
|
|
e7c989baf1 | ||
|
|
7a3c8314ac | ||
|
|
6f8257ec5f | ||
|
|
87b0191753 | ||
|
|
56c17ba4c7 | ||
|
|
daddc57abd | ||
|
|
f9cdd09191 | ||
|
|
47b4858357 | ||
|
|
b8d23d6e07 | ||
|
|
fdecdd0cec | ||
|
|
fabdaa37b6 | ||
|
|
bc82b4d78a | ||
|
|
dae850e0ee | ||
|
|
abcc124df0 | ||
|
|
b4164a9aa7 | ||
|
|
9f0d62ad9f | ||
|
|
64ecf24210 | ||
|
|
658e7caf92 | ||
|
|
788506dd58 | ||
|
|
62790ab15d | ||
|
|
ad60b3ead7 | ||
|
|
5e8dd55574 | ||
|
|
0e961ad47a | ||
|
|
c06cc60946 | ||
|
|
2fa476655f | ||
|
|
7a78495f31 | ||
|
|
3138afbe2e | ||
|
|
4eef0aaad1 | ||
|
|
ab09732986 | ||
|
|
b7fa64565a | ||
|
|
2622ed2528 | ||
|
|
9cb0607f6f | ||
|
|
8998032f66 | ||
|
|
80b4753539 | ||
|
|
fe0838cd1c | ||
|
|
8acaa2ce07 | ||
|
|
c676f13e1a | ||
|
|
9b47cee8b2 | ||
|
|
47e666c090 | ||
|
|
3059579253 | ||
|
|
72c2f75648 | ||
|
|
ec68ed66ed | ||
|
|
f6a81dbe97 | ||
|
|
3904a66ab0 | ||
|
|
ffc5f78229 | ||
|
|
3f78748ef3 | ||
|
|
d26bfb5ae4 | ||
|
|
8d3dd04137 | ||
|
|
791d8d8585 | ||
|
|
e85515958b | ||
|
|
dc59444cd1 | ||
|
|
6c042e17b1 | ||
|
|
18a583306b | ||
|
|
fc8d077612 | ||
|
|
e64fcb9d94 | ||
|
|
6c0a9a272e | ||
|
|
01fa1bc114 | ||
|
|
aa003eba8e | ||
|
|
becf19feef | ||
|
|
81fc3c4f45 | ||
|
|
e7fb0d8a6f | ||
|
|
4eb49163c6 | ||
|
|
79cb336d74 | ||
|
|
38063345ae | ||
|
|
ae00b3a76f | ||
|
|
619be354c8 | ||
|
|
94d40f3980 | ||
|
|
585b81f91e | ||
|
|
5f4f0d4a63 | ||
|
|
8e36e1fe49 | ||
|
|
97505caa64 | ||
|
|
df50c84ee0 | ||
|
|
1a455acc81 | ||
|
|
60bc151ed7 | ||
|
|
3b19bd4d57 | ||
|
|
08f902cf49 | ||
|
|
d3c304e92e | ||
|
|
3bf0292cd5 | ||
|
|
a7861d9d66 | ||
|
|
d62a21b9d3 | ||
|
|
cf86576a83 | ||
|
|
92dc64e121 | ||
|
|
593bfc9668 | ||
|
|
850c60e81b | ||
|
|
3d480b04a5 | ||
|
|
c36e2265d9 | ||
|
|
a68df3898d | ||
|
|
4d7cfff6df | ||
|
|
be822a5f1c | ||
|
|
9f5a052c27 | ||
|
|
fc875334fd | ||
|
|
80a267b130 | ||
|
|
3182ac69a7 | ||
|
|
dead3858b8 | ||
|
|
afa0d0ac0d | ||
|
|
742b8be0c1 | ||
|
|
285f926140 | ||
|
|
3c8865cf66 | ||
|
|
569a326931 | ||
|
|
d1ef7e0ec6 | ||
|
|
d513c3c66b | ||
|
|
93d3c8450c | ||
|
|
8667f29c3b | ||
|
|
d22526ec30 | ||
|
|
bd869c7b31 | ||
|
|
d5a23dde90 | ||
|
|
a7c9e45c64 | ||
|
|
cedd2092eb | ||
|
|
c473818017 | ||
|
|
6087e67771 | ||
|
|
93bf618504 | ||
|
|
dfe2f1eeff | ||
|
|
ca7e5b5cb6 | ||
|
|
5019b2dd20 | ||
|
|
33e7bc88f8 | ||
|
|
fa0c03aaa6 | ||
|
|
3fa47c5dc1 | ||
|
|
0782416a74 | ||
|
|
3ca9af51a4 | ||
|
|
c7b89dd280 | ||
|
|
74832b2a10 | ||
|
|
ee41bc03ab |
63
lapi.c
63
lapi.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.c,v 2.171 2013/03/16 21:10:18 roberto Exp $
|
||||
** $Id: lapi.c,v 2.158 2011/11/29 15:55:08 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -40,16 +40,7 @@ const char lua_ident[] =
|
||||
/* corresponding test */
|
||||
#define isvalid(o) ((o) != luaO_nilobject)
|
||||
|
||||
/* test for pseudo index */
|
||||
#define ispseudo(i) ((i) <= LUA_REGISTRYINDEX)
|
||||
|
||||
/* test for valid but not pseudo index */
|
||||
#define isstackindex(i, o) (isvalid(o) && !ispseudo(i))
|
||||
|
||||
#define api_checkvalidindex(L, o) api_check(L, isvalid(o), "invalid index")
|
||||
|
||||
#define api_checkstackindex(L, i, o) \
|
||||
api_check(L, isstackindex(i, o), "index not in the stack")
|
||||
#define api_checkvalidindex(L, i) api_check(L, isvalid(i), "invalid index")
|
||||
|
||||
|
||||
static TValue *index2addr (lua_State *L, int idx) {
|
||||
@@ -60,7 +51,7 @@ static TValue *index2addr (lua_State *L, int idx) {
|
||||
if (o >= L->top) return NONVALIDVALUE;
|
||||
else return o;
|
||||
}
|
||||
else if (!ispseudo(idx)) { /* negative index */
|
||||
else if (idx > LUA_REGISTRYINDEX) {
|
||||
api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
|
||||
return L->top + idx;
|
||||
}
|
||||
@@ -151,7 +142,7 @@ LUA_API const lua_Number *lua_version (lua_State *L) {
|
||||
** convert an acceptable stack index into an absolute index
|
||||
*/
|
||||
LUA_API int lua_absindex (lua_State *L, int idx) {
|
||||
return (idx > 0 || ispseudo(idx))
|
||||
return (idx > 0 || idx <= LUA_REGISTRYINDEX)
|
||||
? idx
|
||||
: cast_int(L->top - L->ci->func + idx);
|
||||
}
|
||||
@@ -183,7 +174,7 @@ LUA_API void lua_remove (lua_State *L, int idx) {
|
||||
StkId p;
|
||||
lua_lock(L);
|
||||
p = index2addr(L, idx);
|
||||
api_checkstackindex(L, idx, p);
|
||||
api_checkvalidindex(L, p);
|
||||
while (++p < L->top) setobjs2s(L, p-1, p);
|
||||
L->top--;
|
||||
lua_unlock(L);
|
||||
@@ -195,9 +186,8 @@ LUA_API void lua_insert (lua_State *L, int idx) {
|
||||
StkId q;
|
||||
lua_lock(L);
|
||||
p = index2addr(L, idx);
|
||||
api_checkstackindex(L, idx, p);
|
||||
for (q = L->top; q > p; q--) /* use L->top as a temporary */
|
||||
setobjs2s(L, q, q - 1);
|
||||
api_checkvalidindex(L, p);
|
||||
for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);
|
||||
setobjs2s(L, p, L->top);
|
||||
lua_unlock(L);
|
||||
}
|
||||
@@ -227,6 +217,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {
|
||||
TValue *fr;
|
||||
lua_lock(L);
|
||||
fr = index2addr(L, fromidx);
|
||||
api_checkvalidindex(L, fr);
|
||||
moveto(L, fr, toidx);
|
||||
lua_unlock(L);
|
||||
}
|
||||
@@ -290,7 +281,7 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
|
||||
}
|
||||
|
||||
|
||||
LUA_API void lua_arith (lua_State *L, int op) {
|
||||
LUA_API void lua_arith (lua_State *L, int op) {
|
||||
StkId o1; /* 1st operand */
|
||||
StkId o2; /* 2nd operand */
|
||||
lua_lock(L);
|
||||
@@ -304,7 +295,7 @@ LUA_API void lua_arith (lua_State *L, int op) {
|
||||
o1 = L->top - 2;
|
||||
o2 = L->top - 1;
|
||||
if (ttisnumber(o1) && ttisnumber(o2)) {
|
||||
setnvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2)));
|
||||
changenvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2)));
|
||||
}
|
||||
else
|
||||
luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD));
|
||||
@@ -620,6 +611,7 @@ LUA_API void lua_gettable (lua_State *L, int idx) {
|
||||
StkId t;
|
||||
lua_lock(L);
|
||||
t = index2addr(L, idx);
|
||||
api_checkvalidindex(L, t);
|
||||
luaV_gettable(L, t, L->top - 1, L->top - 1);
|
||||
lua_unlock(L);
|
||||
}
|
||||
@@ -629,6 +621,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
|
||||
StkId t;
|
||||
lua_lock(L);
|
||||
t = index2addr(L, idx);
|
||||
api_checkvalidindex(L, t);
|
||||
setsvalue2s(L, L->top, luaS_new(L, k));
|
||||
api_incr_top(L);
|
||||
luaV_gettable(L, t, L->top - 1, L->top - 1);
|
||||
@@ -716,6 +709,7 @@ LUA_API void lua_getuservalue (lua_State *L, int idx) {
|
||||
StkId o;
|
||||
lua_lock(L);
|
||||
o = index2addr(L, idx);
|
||||
api_checkvalidindex(L, o);
|
||||
api_check(L, ttisuserdata(o), "userdata expected");
|
||||
if (uvalue(o)->env) {
|
||||
sethvalue(L, L->top, uvalue(o)->env);
|
||||
@@ -749,6 +743,7 @@ LUA_API void lua_settable (lua_State *L, int idx) {
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 2);
|
||||
t = index2addr(L, idx);
|
||||
api_checkvalidindex(L, t);
|
||||
luaV_settable(L, t, L->top - 2, L->top - 1);
|
||||
L->top -= 2; /* pop index and value */
|
||||
lua_unlock(L);
|
||||
@@ -760,6 +755,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 1);
|
||||
t = index2addr(L, idx);
|
||||
api_checkvalidindex(L, t);
|
||||
setsvalue2s(L, L->top++, luaS_new(L, k));
|
||||
luaV_settable(L, t, L->top - 1, L->top - 2);
|
||||
L->top -= 2; /* pop value and key */
|
||||
@@ -815,6 +811,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 1);
|
||||
obj = index2addr(L, objindex);
|
||||
api_checkvalidindex(L, obj);
|
||||
if (ttisnil(L->top - 1))
|
||||
mt = NULL;
|
||||
else {
|
||||
@@ -824,10 +821,9 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
|
||||
switch (ttypenv(obj)) {
|
||||
case LUA_TTABLE: {
|
||||
hvalue(obj)->metatable = mt;
|
||||
if (mt) {
|
||||
if (mt)
|
||||
luaC_objbarrierback(L, gcvalue(obj), mt);
|
||||
luaC_checkfinalizer(L, gcvalue(obj), mt);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LUA_TUSERDATA: {
|
||||
@@ -854,6 +850,7 @@ LUA_API void lua_setuservalue (lua_State *L, int idx) {
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 1);
|
||||
o = index2addr(L, idx);
|
||||
api_checkvalidindex(L, o);
|
||||
api_check(L, ttisuserdata(o), "userdata expected");
|
||||
if (ttisnil(L->top - 1))
|
||||
uvalue(o)->env = NULL;
|
||||
@@ -940,7 +937,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
|
||||
func = 0;
|
||||
else {
|
||||
StkId o = index2addr(L, errfunc);
|
||||
api_checkstackindex(L, errfunc, o);
|
||||
api_checkvalidindex(L, o);
|
||||
func = savestack(L, o);
|
||||
}
|
||||
c.func = L->top - (nargs+1); /* function to be called */
|
||||
@@ -953,7 +950,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
|
||||
ci->u.c.k = k; /* save continuation */
|
||||
ci->u.c.ctx = ctx; /* save context */
|
||||
/* save information for error recovery */
|
||||
ci->extra = savestack(L, c.func);
|
||||
ci->u.c.extra = savestack(L, c.func);
|
||||
ci->u.c.old_allowhook = L->allowhook;
|
||||
ci->u.c.old_errfunc = L->errfunc;
|
||||
L->errfunc = func;
|
||||
@@ -1009,7 +1006,7 @@ LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {
|
||||
}
|
||||
|
||||
|
||||
LUA_API int lua_status (lua_State *L) {
|
||||
LUA_API int lua_status (lua_State *L) {
|
||||
return L->status;
|
||||
}
|
||||
|
||||
@@ -1048,17 +1045,17 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
|
||||
}
|
||||
case LUA_GCSTEP: {
|
||||
if (g->gckind == KGC_GEN) { /* generational mode? */
|
||||
res = (g->GCestimate == 0); /* true if it will do major collection */
|
||||
res = (g->lastmajormem == 0); /* 1 if will do major collection */
|
||||
luaC_forcestep(L); /* do a single step */
|
||||
}
|
||||
else {
|
||||
lu_mem debt = cast(lu_mem, data) * 1024 - GCSTEPSIZE;
|
||||
if (g->gcrunning)
|
||||
debt += g->GCdebt; /* include current debt */
|
||||
luaE_setdebt(g, debt);
|
||||
luaC_forcestep(L);
|
||||
if (g->gcstate == GCSpause) /* end of cycle? */
|
||||
res = 1; /* signal it */
|
||||
while (data-- >= 0) {
|
||||
luaC_forcestep(L);
|
||||
if (g->gcstate == GCSpause) { /* end of cycle? */
|
||||
res = 1; /* signal it */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1106,7 +1103,7 @@ LUA_API int lua_error (lua_State *L) {
|
||||
lua_lock(L);
|
||||
api_checknelems(L, 1);
|
||||
luaG_errormsg(L);
|
||||
/* code unreachable; will unlock when control actually leaves the kernel */
|
||||
lua_unlock(L);
|
||||
return 0; /* to avoid warnings */
|
||||
}
|
||||
|
||||
|
||||
2
lapi.h
2
lapi.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.h,v 2.7 2009/11/27 15:37:59 roberto Exp $
|
||||
** $Id: lapi.h,v 2.6 2009/08/31 14:26:28 roberto Exp roberto $
|
||||
** Auxiliary functions from Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
30
lauxlib.c
30
lauxlib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.248 2013/03/21 13:54:57 roberto Exp $
|
||||
** $Id: lauxlib.c,v 1.239 2011/12/02 13:25:57 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -84,7 +84,7 @@ static void pushfuncname (lua_State *L, lua_Debug *ar) {
|
||||
if (*ar->namewhat != '\0') /* is there a name? */
|
||||
lua_pushfstring(L, "function " LUA_QS, ar->name);
|
||||
else if (*ar->what == 'm') /* main? */
|
||||
lua_pushliteral(L, "main chunk");
|
||||
lua_pushfstring(L, "main chunk");
|
||||
else if (*ar->what == 'C') {
|
||||
if (pushglobalfuncname(L, ar)) {
|
||||
lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
|
||||
@@ -158,8 +158,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
|
||||
if (strcmp(ar.namewhat, "method") == 0) {
|
||||
narg--; /* do not count `self' */
|
||||
if (narg == 0) /* error is in the self argument itself? */
|
||||
return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
|
||||
ar.name, extramsg);
|
||||
return luaL_error(L, "calling " LUA_QS " on bad self", ar.name);
|
||||
}
|
||||
if (ar.name == NULL)
|
||||
ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
|
||||
@@ -215,7 +214,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
|
||||
if (fname)
|
||||
lua_pushfstring(L, "%s: %s", fname, strerror(en));
|
||||
else
|
||||
lua_pushstring(L, strerror(en));
|
||||
lua_pushfstring(L, "%s", strerror(en));
|
||||
lua_pushinteger(L, en);
|
||||
return 3;
|
||||
}
|
||||
@@ -439,7 +438,7 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
|
||||
if (B->size - B->n < sz) { /* not enough space? */
|
||||
char *newbuff;
|
||||
size_t newsize = B->size * 2; /* double buffer size */
|
||||
if (newsize - B->n < sz) /* not big enough? */
|
||||
if (newsize - B->n < sz) /* not bit enough? */
|
||||
newsize = B->n + sz;
|
||||
if (newsize < B->n || newsize - B->n < sz)
|
||||
luaL_error(L, "buffer too large");
|
||||
@@ -521,11 +520,11 @@ LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) {
|
||||
|
||||
LUALIB_API int luaL_ref (lua_State *L, int t) {
|
||||
int ref;
|
||||
t = lua_absindex(L, t);
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1); /* remove from stack */
|
||||
return LUA_REFNIL; /* `nil' has a unique fixed reference */
|
||||
}
|
||||
t = lua_absindex(L, t);
|
||||
lua_rawgeti(L, t, freelist); /* get first free element */
|
||||
ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
|
||||
lua_pop(L, 1); /* remove it from stack */
|
||||
@@ -599,7 +598,7 @@ static int skipBOM (LoadF *lf) {
|
||||
lf->n = 0;
|
||||
do {
|
||||
c = getc(lf->f);
|
||||
if (c == EOF || c != *(const unsigned char *)p++) return c;
|
||||
if (c == EOF || c != *(unsigned char *)p++) return c;
|
||||
lf->buff[lf->n++] = c; /* to be read by the parser */
|
||||
} while (*p != '\0');
|
||||
lf->n = 0; /* prefix matched; discard it */
|
||||
@@ -617,10 +616,8 @@ static int skipBOM (LoadF *lf) {
|
||||
static int skipcomment (LoadF *lf, int *cp) {
|
||||
int c = *cp = skipBOM(lf);
|
||||
if (c == '#') { /* first line is a comment (Unix exec. file)? */
|
||||
do { /* skip first line */
|
||||
c = getc(lf->f);
|
||||
} while (c != EOF && c != '\n') ;
|
||||
*cp = getc(lf->f); /* skip end-of-line, if present */
|
||||
while ((c = getc(lf->f)) != EOF && c != '\n') ; /* skip first line */
|
||||
*cp = getc(lf->f); /* skip end-of-line */
|
||||
return 1; /* there was a comment */
|
||||
}
|
||||
else return 0; /* no comment */
|
||||
@@ -846,7 +843,6 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
|
||||
** Returns with only the table at the stack.
|
||||
*/
|
||||
LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
|
||||
luaL_checkversion(L);
|
||||
luaL_checkstack(L, nup, "too many upvalues");
|
||||
for (; l->name != NULL; l++) { /* fill the table with given functions */
|
||||
int i;
|
||||
@@ -867,8 +863,8 @@ LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {
|
||||
lua_getfield(L, idx, fname);
|
||||
if (lua_istable(L, -1)) return 1; /* table already there */
|
||||
else {
|
||||
lua_pop(L, 1); /* remove previous result */
|
||||
idx = lua_absindex(L, idx);
|
||||
lua_pop(L, 1); /* remove previous result */
|
||||
lua_newtable(L);
|
||||
lua_pushvalue(L, -1); /* copy to be left at top */
|
||||
lua_setfield(L, idx, fname); /* assign new table to field */
|
||||
@@ -893,8 +889,10 @@ LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
|
||||
lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
|
||||
lua_pop(L, 1); /* remove _LOADED table */
|
||||
if (glb) {
|
||||
lua_pushvalue(L, -1); /* copy of 'mod' */
|
||||
lua_setglobal(L, modname); /* _G[modname] = module */
|
||||
lua_pushglobaltable(L);
|
||||
lua_pushvalue(L, -2); /* copy of 'mod' */
|
||||
lua_setfield(L, -2, modname); /* _G[modname] = module */
|
||||
lua_pop(L, 1); /* remove _G table */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.h,v 1.120 2011/11/29 15:55:08 roberto Exp $
|
||||
** $Id: lauxlib.h,v 1.119 2011/11/14 17:10:24 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
34
lbaselib.c
34
lbaselib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbaselib.c,v 1.276 2013/02/21 13:44:53 roberto Exp $
|
||||
** $Id: lbaselib.c,v 1.272 2011/11/30 12:42:21 roberto Exp roberto $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -242,16 +242,10 @@ static int luaB_ipairs (lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
static int load_aux (lua_State *L, int status, int envidx) {
|
||||
if (status == LUA_OK) {
|
||||
if (envidx != 0) { /* 'env' parameter? */
|
||||
lua_pushvalue(L, envidx); /* environment for loaded function */
|
||||
if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
|
||||
lua_pop(L, 1); /* remove 'env' if not used by previous call */
|
||||
}
|
||||
static int load_aux (lua_State *L, int status) {
|
||||
if (status == LUA_OK)
|
||||
return 1;
|
||||
}
|
||||
else { /* error (message is on top of the stack) */
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
lua_insert(L, -2); /* put before error message */
|
||||
return 2; /* return nil plus error message */
|
||||
@@ -262,9 +256,13 @@ static int load_aux (lua_State *L, int status, int envidx) {
|
||||
static int luaB_loadfile (lua_State *L) {
|
||||
const char *fname = luaL_optstring(L, 1, NULL);
|
||||
const char *mode = luaL_optstring(L, 2, NULL);
|
||||
int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
|
||||
int env = !lua_isnone(L, 3); /* 'env' parameter? */
|
||||
int status = luaL_loadfilex(L, fname, mode);
|
||||
return load_aux(L, status, env);
|
||||
if (status == LUA_OK && env) { /* 'env' parameter? */
|
||||
lua_pushvalue(L, 3);
|
||||
lua_setupvalue(L, -2, 1); /* set it as 1st upvalue of loaded chunk */
|
||||
}
|
||||
return load_aux(L, status);
|
||||
}
|
||||
|
||||
|
||||
@@ -295,7 +293,6 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
|
||||
lua_pushvalue(L, 1); /* get function */
|
||||
lua_call(L, 0, 1); /* call it */
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1); /* pop result */
|
||||
*size = 0;
|
||||
return NULL;
|
||||
}
|
||||
@@ -309,9 +306,9 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
|
||||
static int luaB_load (lua_State *L) {
|
||||
int status;
|
||||
size_t l;
|
||||
int top = lua_gettop(L);
|
||||
const char *s = lua_tolstring(L, 1, &l);
|
||||
const char *mode = luaL_optstring(L, 3, "bt");
|
||||
int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
|
||||
if (s != NULL) { /* loading a string? */
|
||||
const char *chunkname = luaL_optstring(L, 2, s);
|
||||
status = luaL_loadbufferx(L, s, l, chunkname, mode);
|
||||
@@ -322,7 +319,11 @@ static int luaB_load (lua_State *L) {
|
||||
lua_settop(L, RESERVEDSLOT); /* create reserved slot */
|
||||
status = lua_load(L, generic_reader, NULL, chunkname, mode);
|
||||
}
|
||||
return load_aux(L, status, env);
|
||||
if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */
|
||||
lua_pushvalue(L, 4); /* environment for loaded function */
|
||||
lua_setupvalue(L, -2, 1); /* set it as 1st upvalue */
|
||||
}
|
||||
return load_aux(L, status);
|
||||
}
|
||||
|
||||
/* }====================================================== */
|
||||
@@ -336,8 +337,7 @@ static int dofilecont (lua_State *L) {
|
||||
static int luaB_dofile (lua_State *L) {
|
||||
const char *fname = luaL_optstring(L, 1, NULL);
|
||||
lua_settop(L, 1);
|
||||
if (luaL_loadfile(L, fname) != LUA_OK)
|
||||
return lua_error(L);
|
||||
if (luaL_loadfile(L, fname) != LUA_OK) lua_error(L);
|
||||
lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);
|
||||
return dofilecont(L);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbitlib.c,v 1.18.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** $Id: lbitlib.c,v 1.15 2010/12/17 13:26:38 roberto Exp roberto $
|
||||
** Standard library for bitwise operations
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -129,8 +129,7 @@ static int b_rot (lua_State *L, int i) {
|
||||
b_uint r = luaL_checkunsigned(L, 1);
|
||||
i &= (LUA_NBITS - 1); /* i = i % NBITS */
|
||||
r = trim(r);
|
||||
if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */
|
||||
r = (r << i) | (r >> (LUA_NBITS - i));
|
||||
r = (r << i) | (r >> (LUA_NBITS - i));
|
||||
lua_pushunsigned(L, trim(r));
|
||||
return 1;
|
||||
}
|
||||
@@ -148,9 +147,7 @@ static int b_rrot (lua_State *L) {
|
||||
|
||||
/*
|
||||
** get field and width arguments for field-manipulation functions,
|
||||
** checking whether they are valid.
|
||||
** ('luaL_error' called without 'return' to avoid later warnings about
|
||||
** 'width' being used uninitialized.)
|
||||
** checking whether they are valid
|
||||
*/
|
||||
static int fieldargs (lua_State *L, int farg, int *width) {
|
||||
int f = luaL_checkint(L, farg);
|
||||
|
||||
11
lcode.c
11
lcode.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lcode.c,v 2.62 2012/08/16 17:34:28 roberto Exp $
|
||||
** $Id: lcode.c,v 2.59 2011/08/15 19:41:58 roberto Exp roberto $
|
||||
** Code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -330,9 +330,10 @@ int luaK_numberK (FuncState *fs, lua_Number r) {
|
||||
setnvalue(&o, r);
|
||||
if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */
|
||||
/* use raw representation as key to avoid numeric problems */
|
||||
setsvalue(L, L->top++, luaS_newlstr(L, (char *)&r, sizeof(r)));
|
||||
n = addk(fs, L->top - 1, &o);
|
||||
L->top--;
|
||||
setsvalue(L, L->top, luaS_newlstr(L, (char *)&r, sizeof(r)));
|
||||
incr_top(L);
|
||||
n = addk(fs, L->top - 1, &o);
|
||||
L->top--;
|
||||
}
|
||||
else
|
||||
n = addk(fs, &o, &o); /* regular case */
|
||||
@@ -425,7 +426,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
|
||||
luaK_nil(fs, reg, 1);
|
||||
break;
|
||||
}
|
||||
case VFALSE: case VTRUE: {
|
||||
case VFALSE: case VTRUE: {
|
||||
luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
2
lcode.h
2
lcode.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lcode.h,v 1.58 2011/08/30 16:26:41 roberto Exp $
|
||||
** $Id: lcode.h,v 1.57 2011/04/07 18:14:12 roberto Exp roberto $
|
||||
** Code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lcorolib.c,v 1.5 2013/02/21 13:44:53 roberto Exp $
|
||||
** $Id: lcorolib.c,v 1.2 2010/07/02 11:38:13 roberto Exp roberto $
|
||||
** Coroutine Library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -73,16 +73,15 @@ static int luaB_auxwrap (lua_State *L) {
|
||||
lua_insert(L, -2);
|
||||
lua_concat(L, 2);
|
||||
}
|
||||
return lua_error(L); /* propagate error */
|
||||
lua_error(L); /* propagate error */
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
static int luaB_cocreate (lua_State *L) {
|
||||
lua_State *NL;
|
||||
lua_State *NL = lua_newthread(L);
|
||||
luaL_checktype(L, 1, LUA_TFUNCTION);
|
||||
NL = lua_newthread(L);
|
||||
lua_pushvalue(L, 1); /* move function to top */
|
||||
lua_xmove(L, NL, 1); /* move function from L to NL */
|
||||
return 1;
|
||||
|
||||
2
lctype.c
2
lctype.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lctype.c,v 1.11 2011/10/03 16:19:23 roberto Exp $
|
||||
** $Id: lctype.c,v 1.10 2011/06/24 12:25:33 roberto Exp roberto $
|
||||
** 'ctype' functions for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
2
lctype.h
2
lctype.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $
|
||||
** $Id: lctype.h,v 1.11 2011/06/27 18:22:46 roberto Exp roberto $
|
||||
** 'ctype' functions for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
31
ldblib.c
31
ldblib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldblib.c,v 1.132.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** $Id: ldblib.c,v 1.130 2011/04/08 19:17:36 roberto Exp roberto $
|
||||
** Interface from Lua to its debug API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -21,11 +21,6 @@
|
||||
#define HOOKKEY "_HKEY"
|
||||
|
||||
|
||||
static void checkstack (lua_State *L, lua_State *L1, int n) {
|
||||
if (L != L1 && !lua_checkstack(L1, n))
|
||||
luaL_error(L, "stack overflow");
|
||||
}
|
||||
|
||||
|
||||
static int db_getregistry (lua_State *L) {
|
||||
lua_pushvalue(L, LUA_REGISTRYINDEX);
|
||||
@@ -119,7 +114,6 @@ static int db_getinfo (lua_State *L) {
|
||||
int arg;
|
||||
lua_State *L1 = getthread(L, &arg);
|
||||
const char *options = luaL_optstring(L, arg+2, "flnStu");
|
||||
checkstack(L, L1, 3);
|
||||
if (lua_isnumber(L, arg+1)) {
|
||||
if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
|
||||
lua_pushnil(L); /* level out of range */
|
||||
@@ -179,7 +173,6 @@ static int db_getlocal (lua_State *L) {
|
||||
else { /* stack-level argument */
|
||||
if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
|
||||
return luaL_argerror(L, arg+1, "level out of range");
|
||||
checkstack(L, L1, 1);
|
||||
name = lua_getlocal(L1, &ar, nvar);
|
||||
if (name) {
|
||||
lua_xmove(L1, L, 1); /* push local value */
|
||||
@@ -203,7 +196,6 @@ static int db_setlocal (lua_State *L) {
|
||||
return luaL_argerror(L, arg+1, "level out of range");
|
||||
luaL_checkany(L, arg+3);
|
||||
lua_settop(L, arg+3);
|
||||
checkstack(L, L1, 1);
|
||||
lua_xmove(L, L1, 1);
|
||||
lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
|
||||
return 1;
|
||||
@@ -261,15 +253,14 @@ static int db_upvaluejoin (lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)
|
||||
#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY);
|
||||
|
||||
|
||||
static void hookf (lua_State *L, lua_Debug *ar) {
|
||||
static const char *const hooknames[] =
|
||||
{"call", "return", "line", "count", "tail call"};
|
||||
gethooktable(L);
|
||||
lua_pushthread(L);
|
||||
lua_rawget(L, -2);
|
||||
lua_rawgetp(L, -1, L);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_pushstring(L, hooknames[(int)ar->event]);
|
||||
if (ar->currentline >= 0)
|
||||
@@ -315,16 +306,10 @@ static int db_sethook (lua_State *L) {
|
||||
count = luaL_optint(L, arg+3, 0);
|
||||
func = hookf; mask = makemask(smask, count);
|
||||
}
|
||||
if (gethooktable(L) == 0) { /* creating hook table? */
|
||||
lua_pushstring(L, "k");
|
||||
lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
|
||||
}
|
||||
checkstack(L, L1, 1);
|
||||
lua_pushthread(L1); lua_xmove(L1, L, 1);
|
||||
gethooktable(L);
|
||||
lua_pushvalue(L, arg+1);
|
||||
lua_rawset(L, -3); /* set new hook */
|
||||
lua_rawsetp(L, -2, L1); /* set new hook */
|
||||
lua_pop(L, 1); /* remove hook table */
|
||||
lua_sethook(L1, func, mask, count); /* set hooks */
|
||||
return 0;
|
||||
}
|
||||
@@ -340,9 +325,7 @@ static int db_gethook (lua_State *L) {
|
||||
lua_pushliteral(L, "external hook");
|
||||
else {
|
||||
gethooktable(L);
|
||||
checkstack(L, L1, 1);
|
||||
lua_pushthread(L1); lua_xmove(L1, L, 1);
|
||||
lua_rawget(L, -2); /* get hook */
|
||||
lua_rawgetp(L, -1, L1); /* get hook */
|
||||
lua_remove(L, -2); /* remove hook table */
|
||||
}
|
||||
lua_pushstring(L, unmakemask(mask, buff));
|
||||
|
||||
69
ldebug.c
69
ldebug.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldebug.c,v 2.90.1.3 2013/05/16 16:04:15 roberto Exp roberto $
|
||||
** $Id: ldebug.c,v 2.87 2011/10/07 20:45:19 roberto Exp roberto $
|
||||
** Debug Interface
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -30,9 +30,6 @@
|
||||
|
||||
|
||||
|
||||
#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_TCCL)
|
||||
|
||||
|
||||
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
|
||||
|
||||
|
||||
@@ -47,16 +44,6 @@ static int currentline (CallInfo *ci) {
|
||||
}
|
||||
|
||||
|
||||
static void swapextra (lua_State *L) {
|
||||
if (L->status == LUA_YIELD) {
|
||||
CallInfo *ci = L->ci; /* get function that yielded */
|
||||
StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
|
||||
ci->func = restorestack(L, ci->extra);
|
||||
ci->extra = savestack(L, temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** this function can be called asynchronous (e.g. during a signal)
|
||||
*/
|
||||
@@ -154,7 +141,6 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
|
||||
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||
const char *name;
|
||||
lua_lock(L);
|
||||
swapextra(L);
|
||||
if (ar == NULL) { /* information about non-active function? */
|
||||
if (!isLfunction(L->top - 1)) /* not a Lua function? */
|
||||
name = NULL;
|
||||
@@ -169,7 +155,6 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||
api_incr_top(L);
|
||||
}
|
||||
}
|
||||
swapextra(L);
|
||||
lua_unlock(L);
|
||||
return name;
|
||||
}
|
||||
@@ -177,21 +162,18 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||
|
||||
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||
StkId pos = 0; /* to avoid warnings */
|
||||
const char *name;
|
||||
const char *name = findlocal(L, ar->i_ci, n, &pos);
|
||||
lua_lock(L);
|
||||
swapextra(L);
|
||||
name = findlocal(L, ar->i_ci, n, &pos);
|
||||
if (name)
|
||||
setobjs2s(L, pos, L->top - 1);
|
||||
L->top--; /* pop value */
|
||||
swapextra(L);
|
||||
lua_unlock(L);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
static void funcinfo (lua_Debug *ar, Closure *cl) {
|
||||
if (noLuaClosure(cl)) {
|
||||
if (cl == NULL || cl->c.isC) {
|
||||
ar->source = "=[C]";
|
||||
ar->linedefined = -1;
|
||||
ar->lastlinedefined = -1;
|
||||
@@ -209,9 +191,9 @@ static void funcinfo (lua_Debug *ar, Closure *cl) {
|
||||
|
||||
|
||||
static void collectvalidlines (lua_State *L, Closure *f) {
|
||||
if (noLuaClosure(f)) {
|
||||
if (f == NULL || f->c.isC) {
|
||||
setnilvalue(L->top);
|
||||
api_incr_top(L);
|
||||
incr_top(L);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
@@ -219,7 +201,7 @@ static void collectvalidlines (lua_State *L, Closure *f) {
|
||||
int *lineinfo = f->l.p->lineinfo;
|
||||
Table *t = luaH_new(L); /* new table to store active lines */
|
||||
sethvalue(L, L->top, t); /* push it on stack */
|
||||
api_incr_top(L);
|
||||
incr_top(L);
|
||||
setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */
|
||||
for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */
|
||||
luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */
|
||||
@@ -228,7 +210,7 @@ static void collectvalidlines (lua_State *L, Closure *f) {
|
||||
|
||||
|
||||
static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
|
||||
Closure *f, CallInfo *ci) {
|
||||
Closure *f, CallInfo *ci) {
|
||||
int status = 1;
|
||||
for (; *what; what++) {
|
||||
switch (*what) {
|
||||
@@ -242,7 +224,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
|
||||
}
|
||||
case 'u': {
|
||||
ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
|
||||
if (noLuaClosure(f)) {
|
||||
if (f == NULL || f->c.isC) {
|
||||
ar->isvararg = 1;
|
||||
ar->nparams = 0;
|
||||
}
|
||||
@@ -284,7 +266,6 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
|
||||
CallInfo *ci;
|
||||
StkId func;
|
||||
lua_lock(L);
|
||||
swapextra(L);
|
||||
if (*what == '>') {
|
||||
ci = NULL;
|
||||
func = L->top - 1;
|
||||
@@ -301,9 +282,8 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
|
||||
status = auxgetinfo(L, what, ar, cl, ci);
|
||||
if (strchr(what, 'f')) {
|
||||
setobjs2s(L, L->top, func);
|
||||
api_incr_top(L);
|
||||
incr_top(L);
|
||||
}
|
||||
swapextra(L);
|
||||
if (strchr(what, 'L'))
|
||||
collectvalidlines(L, cl);
|
||||
lua_unlock(L);
|
||||
@@ -344,20 +324,12 @@ static void kname (Proto *p, int pc, int c, const char **name) {
|
||||
}
|
||||
|
||||
|
||||
static int filterpc (int pc, int jmptarget) {
|
||||
if (pc < jmptarget) /* is code conditional (inside a jump)? */
|
||||
return -1; /* cannot know who sets that register */
|
||||
else return pc; /* current position sets that register */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** try to find last instruction before 'lastpc' that modified register 'reg'
|
||||
*/
|
||||
static int findsetreg (Proto *p, int lastpc, int reg) {
|
||||
int pc;
|
||||
int setreg = -1; /* keep last instruction that changed 'reg' */
|
||||
int jmptarget = 0; /* any code before this address is conditional */
|
||||
for (pc = 0; pc < lastpc; pc++) {
|
||||
Instruction i = p->code[pc];
|
||||
OpCode op = GET_OPCODE(i);
|
||||
@@ -366,38 +338,33 @@ static int findsetreg (Proto *p, int lastpc, int reg) {
|
||||
case OP_LOADNIL: {
|
||||
int b = GETARG_B(i);
|
||||
if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
setreg = pc;
|
||||
break;
|
||||
}
|
||||
case OP_TFORCALL: {
|
||||
if (reg >= a + 2) /* affect all regs above its base */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
if (reg >= a + 2) setreg = pc; /* affect all regs above its base */
|
||||
break;
|
||||
}
|
||||
case OP_CALL:
|
||||
case OP_TAILCALL: {
|
||||
if (reg >= a) /* affect all registers above base */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
if (reg >= a) setreg = pc; /* affect all registers above base */
|
||||
break;
|
||||
}
|
||||
case OP_JMP: {
|
||||
int b = GETARG_sBx(i);
|
||||
int dest = pc + 1 + b;
|
||||
/* jump is forward and do not skip `lastpc'? */
|
||||
if (pc < dest && dest <= lastpc) {
|
||||
if (dest > jmptarget)
|
||||
jmptarget = dest; /* update 'jmptarget' */
|
||||
}
|
||||
if (pc < dest && dest <= lastpc)
|
||||
pc += b; /* do the jump */
|
||||
break;
|
||||
}
|
||||
case OP_TEST: {
|
||||
if (reg == a) /* jumped code can change 'a' */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
if (reg == a) setreg = pc; /* jumped code can change 'a' */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (testAMode(op) && reg == a) /* any instruction that set A */
|
||||
setreg = filterpc(pc, jmptarget);
|
||||
setreg = pc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -548,7 +515,7 @@ l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
|
||||
|
||||
l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
|
||||
if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
|
||||
lua_assert(!ttisstring(p1) && !ttisnumber(p1));
|
||||
lua_assert(!ttisstring(p1) && !ttisnumber(p2));
|
||||
luaG_typeerror(L, p1, "concatenate");
|
||||
}
|
||||
|
||||
@@ -593,7 +560,7 @@ l_noret luaG_errormsg (lua_State *L) {
|
||||
if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
|
||||
setobjs2s(L, L->top, L->top - 1); /* move argument */
|
||||
setobjs2s(L, L->top - 1, errfunc); /* push function */
|
||||
L->top++;
|
||||
incr_top(L);
|
||||
luaD_call(L, L->top - 2, 1, 0); /* call it */
|
||||
}
|
||||
luaD_throw(L, LUA_ERRRUN);
|
||||
|
||||
2
ldebug.h
2
ldebug.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldebug.h,v 2.7 2011/10/07 20:45:19 roberto Exp $
|
||||
** $Id: ldebug.h,v 2.6 2011/06/02 19:31:40 roberto Exp roberto $
|
||||
** Auxiliary functions from Debug Interface module
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
61
ldo.c
61
ldo.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldo.c,v 2.108.1.2 2013/04/19 21:03:23 roberto Exp roberto $
|
||||
** $Id: ldo.c,v 2.101 2011/10/07 20:45:19 roberto Exp roberto $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -260,7 +260,6 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
|
||||
StkId base, fixed;
|
||||
lua_assert(actual >= nfixargs);
|
||||
/* move fixed parameters to final position */
|
||||
luaD_checkstack(L, p->maxstacksize); /* check again for new 'base' */
|
||||
fixed = L->top - actual; /* first fixed argument */
|
||||
base = L->top; /* final position of first argument */
|
||||
for (i=0; i<nfixargs; i++) {
|
||||
@@ -312,7 +311,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||
ci->top = L->top + LUA_MINSTACK;
|
||||
lua_assert(ci->top <= L->stack_last);
|
||||
ci->callstatus = 0;
|
||||
luaC_checkGC(L); /* stack grow uses memory */
|
||||
if (L->hookmask & LUA_MASKCALL)
|
||||
luaD_hook(L, LUA_HOOKCALL, -1);
|
||||
lua_unlock(L);
|
||||
@@ -325,18 +323,12 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||
case LUA_TLCL: { /* Lua function: prepare its call */
|
||||
StkId base;
|
||||
Proto *p = clLvalue(func)->p;
|
||||
n = cast_int(L->top - func) - 1; /* number of real arguments */
|
||||
luaD_checkstack(L, p->maxstacksize);
|
||||
func = restorestack(L, funcr);
|
||||
n = cast_int(L->top - func) - 1; /* number of real arguments */
|
||||
for (; n < p->numparams; n++)
|
||||
setnilvalue(L->top++); /* complete missing arguments */
|
||||
if (!p->is_vararg) {
|
||||
func = restorestack(L, funcr);
|
||||
base = func + 1;
|
||||
}
|
||||
else {
|
||||
base = adjust_varargs(L, p, n);
|
||||
func = restorestack(L, funcr); /* previous call can change stack */
|
||||
}
|
||||
base = (!p->is_vararg) ? func + 1 : adjust_varargs(L, p, n);
|
||||
ci = next_ci(L); /* now 'enter' new function */
|
||||
ci->nresults = nresults;
|
||||
ci->func = func;
|
||||
@@ -346,7 +338,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||
ci->u.l.savedpc = p->code; /* starting point */
|
||||
ci->callstatus = CIST_LUA;
|
||||
L->top = ci->top;
|
||||
luaC_checkGC(L); /* stack grow uses memory */
|
||||
if (L->hookmask & LUA_MASKCALL)
|
||||
callhook(L, ci);
|
||||
return 0;
|
||||
@@ -402,6 +393,7 @@ void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) {
|
||||
luaV_execute(L); /* call it */
|
||||
if (!allowyield) L->nny--;
|
||||
L->nCcalls--;
|
||||
luaC_checkGC(L);
|
||||
}
|
||||
|
||||
|
||||
@@ -410,11 +402,9 @@ static void finishCcall (lua_State *L) {
|
||||
int n;
|
||||
lua_assert(ci->u.c.k != NULL); /* must have a continuation */
|
||||
lua_assert(L->nny == 0);
|
||||
if (ci->callstatus & CIST_YPCALL) { /* was inside a pcall? */
|
||||
ci->callstatus &= ~CIST_YPCALL; /* finish 'lua_pcall' */
|
||||
L->errfunc = ci->u.c.old_errfunc;
|
||||
}
|
||||
/* finish 'lua_callk'/'lua_pcall' */
|
||||
/* finish 'luaD_call' */
|
||||
L->nCcalls--;
|
||||
/* finish 'lua_callk' */
|
||||
adjustresults(L, ci->nresults);
|
||||
/* call continuation function */
|
||||
if (!(ci->callstatus & CIST_STAT)) /* no call status? */
|
||||
@@ -463,7 +453,7 @@ static int recover (lua_State *L, int status) {
|
||||
CallInfo *ci = findpcall(L);
|
||||
if (ci == NULL) return 0; /* no recovery point */
|
||||
/* "finish" luaD_pcall */
|
||||
oldtop = restorestack(L, ci->extra);
|
||||
oldtop = restorestack(L, ci->u.c.extra);
|
||||
luaF_close(L, oldtop);
|
||||
seterrorobj(L, status, oldtop);
|
||||
L->ci = ci;
|
||||
@@ -485,7 +475,7 @@ static int recover (lua_State *L, int status) {
|
||||
static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) {
|
||||
L->top = firstArg; /* remove args from the stack */
|
||||
setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */
|
||||
api_incr_top(L);
|
||||
incr_top(L);
|
||||
luaD_throw(L, -1); /* jump back to 'lua_resume' */
|
||||
}
|
||||
|
||||
@@ -494,10 +484,9 @@ static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) {
|
||||
** do the work for 'lua_resume' in protected mode
|
||||
*/
|
||||
static void resume (lua_State *L, void *ud) {
|
||||
int nCcalls = L->nCcalls;
|
||||
StkId firstArg = cast(StkId, ud);
|
||||
CallInfo *ci = L->ci;
|
||||
if (nCcalls >= LUAI_MAXCCALLS)
|
||||
if (L->nCcalls >= LUAI_MAXCCALLS)
|
||||
resume_error(L, "C stack overflow", firstArg);
|
||||
if (L->status == LUA_OK) { /* may be starting a coroutine */
|
||||
if (ci != &L->base_ci) /* not in base level? */
|
||||
@@ -510,10 +499,10 @@ static void resume (lua_State *L, void *ud) {
|
||||
resume_error(L, "cannot resume dead coroutine", firstArg);
|
||||
else { /* resuming from previous yield */
|
||||
L->status = LUA_OK;
|
||||
ci->func = restorestack(L, ci->extra);
|
||||
if (isLua(ci)) /* yielded inside a hook? */
|
||||
luaV_execute(L); /* just continue running Lua code */
|
||||
else { /* 'common' yield */
|
||||
ci->func = restorestack(L, ci->u.c.extra);
|
||||
if (ci->u.c.k != NULL) { /* does it have a continuation? */
|
||||
int n;
|
||||
ci->u.c.status = LUA_YIELD; /* 'default' status */
|
||||
@@ -524,17 +513,16 @@ static void resume (lua_State *L, void *ud) {
|
||||
api_checknelems(L, n);
|
||||
firstArg = L->top - n; /* yield results come from continuation */
|
||||
}
|
||||
L->nCcalls--; /* finish 'luaD_call' */
|
||||
luaD_poscall(L, firstArg); /* finish 'luaD_precall' */
|
||||
}
|
||||
unroll(L, NULL);
|
||||
}
|
||||
lua_assert(nCcalls == L->nCcalls);
|
||||
}
|
||||
|
||||
|
||||
LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {
|
||||
int status;
|
||||
int oldnny = L->nny; /* save 'nny' */
|
||||
lua_lock(L);
|
||||
luai_userstateresume(L, nargs);
|
||||
L->nCcalls = (from) ? from->nCcalls + 1 : 1;
|
||||
@@ -556,7 +544,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {
|
||||
}
|
||||
lua_assert(status == L->status);
|
||||
}
|
||||
L->nny = oldnny; /* restore 'nny' */
|
||||
L->nny = 1; /* do not allow yields */
|
||||
L->nCcalls--;
|
||||
lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));
|
||||
lua_unlock(L);
|
||||
@@ -571,18 +559,18 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k) {
|
||||
api_checknelems(L, nresults);
|
||||
if (L->nny > 0) {
|
||||
if (L != G(L)->mainthread)
|
||||
luaG_runerror(L, "attempt to yield across a C-call boundary");
|
||||
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
|
||||
else
|
||||
luaG_runerror(L, "attempt to yield from outside a coroutine");
|
||||
}
|
||||
L->status = LUA_YIELD;
|
||||
ci->extra = savestack(L, ci->func); /* save current 'func' */
|
||||
if (isLua(ci)) { /* inside a hook? */
|
||||
api_check(L, k == NULL, "hooks cannot continue after yielding");
|
||||
}
|
||||
else {
|
||||
if ((ci->u.c.k = k) != NULL) /* is there a continuation? */
|
||||
ci->u.c.ctx = ctx; /* save context */
|
||||
ci->u.c.extra = savestack(L, ci->func); /* save current 'func' */
|
||||
ci->func = L->top - nresults - 1; /* protect stack below results */
|
||||
luaD_throw(L, LUA_YIELD);
|
||||
}
|
||||
@@ -639,23 +627,24 @@ static void checkmode (lua_State *L, const char *mode, const char *x) {
|
||||
|
||||
static void f_parser (lua_State *L, void *ud) {
|
||||
int i;
|
||||
Proto *tf;
|
||||
Closure *cl;
|
||||
struct SParser *p = cast(struct SParser *, ud);
|
||||
int c = zgetc(p->z); /* read first character */
|
||||
if (c == LUA_SIGNATURE[0]) {
|
||||
checkmode(L, p->mode, "binary");
|
||||
cl = luaU_undump(L, p->z, &p->buff, p->name);
|
||||
tf = luaU_undump(L, p->z, &p->buff, p->name);
|
||||
}
|
||||
else {
|
||||
checkmode(L, p->mode, "text");
|
||||
cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
|
||||
}
|
||||
lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
|
||||
for (i = 0; i < cl->l.nupvalues; i++) { /* initialize upvalues */
|
||||
UpVal *up = luaF_newupval(L);
|
||||
cl->l.upvals[i] = up;
|
||||
luaC_objbarrier(L, cl, up);
|
||||
tf = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
|
||||
}
|
||||
setptvalue2s(L, L->top, tf);
|
||||
incr_top(L);
|
||||
cl = luaF_newLclosure(L, tf);
|
||||
setclLvalue(L, L->top - 1, cl);
|
||||
for (i = 0; i < tf->sizeupvalues; i++) /* initialize upvalues */
|
||||
cl->l.upvals[i] = luaF_newupval(L);
|
||||
}
|
||||
|
||||
|
||||
|
||||
2
ldo.h
2
ldo.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldo.h,v 2.20 2011/11/29 15:55:08 roberto Exp $
|
||||
** $Id: ldo.h,v 2.19 2011/10/07 20:45:19 roberto Exp roberto $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
7
ldump.c
7
ldump.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldump.c,v 2.17 2012/01/23 23:02:10 roberto Exp $
|
||||
** $Id: ldump.c,v 1.19 2011/11/23 17:48:18 lhf Exp $
|
||||
** save precompiled Lua chunks
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -84,8 +84,8 @@ static void DumpConstants(const Proto* f, DumpState* D)
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
const TValue* o=&f->k[i];
|
||||
DumpChar(ttypenv(o),D);
|
||||
switch (ttypenv(o))
|
||||
DumpChar(ttype(o),D);
|
||||
switch (ttype(o))
|
||||
{
|
||||
case LUA_TNIL:
|
||||
break;
|
||||
@@ -98,7 +98,6 @@ static void DumpConstants(const Proto* f, DumpState* D)
|
||||
case LUA_TSTRING:
|
||||
DumpString(rawtsvalue(o),D);
|
||||
break;
|
||||
default: lua_assert(0);
|
||||
}
|
||||
}
|
||||
n=f->sizep;
|
||||
|
||||
22
lfunc.c
22
lfunc.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lfunc.c,v 2.30 2012/10/03 12:36:46 roberto Exp $
|
||||
** $Id: lfunc.c,v 2.26 2010/06/10 21:27:09 roberto Exp roberto $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -21,15 +21,18 @@
|
||||
|
||||
|
||||
Closure *luaF_newCclosure (lua_State *L, int n) {
|
||||
Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl;
|
||||
Closure *c = &luaC_newobj(L, LUA_TFUNCTION, sizeCclosure(n), NULL, 0)->cl;
|
||||
c->c.isC = 1;
|
||||
c->c.nupvalues = cast_byte(n);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
Closure *luaF_newLclosure (lua_State *L, int n) {
|
||||
Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl;
|
||||
c->l.p = NULL;
|
||||
Closure *luaF_newLclosure (lua_State *L, Proto *p) {
|
||||
int n = p->sizeupvalues;
|
||||
Closure *c = &luaC_newobj(L, LUA_TFUNCTION, sizeLclosure(n), NULL, 0)->cl;
|
||||
c->l.isC = 0;
|
||||
c->l.p = p;
|
||||
c->l.nupvalues = cast_byte(n);
|
||||
while (n--) c->l.upvals[n] = NULL;
|
||||
return c;
|
||||
@@ -52,12 +55,12 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
|
||||
while (*pp != NULL && (p = gco2uv(*pp))->v >= level) {
|
||||
GCObject *o = obj2gco(p);
|
||||
lua_assert(p->v != &p->u.value);
|
||||
lua_assert(!isold(o) || isold(obj2gco(L)));
|
||||
if (p->v == level) { /* found a corresponding upvalue? */
|
||||
if (isdead(g, o)) /* is it dead? */
|
||||
changewhite(o); /* resurrect it */
|
||||
return p;
|
||||
}
|
||||
resetoldbit(o); /* may create a newer upval after this one */
|
||||
pp = &p->next;
|
||||
}
|
||||
/* not found: create a new one */
|
||||
@@ -143,6 +146,13 @@ void luaF_freeproto (lua_State *L, Proto *f) {
|
||||
}
|
||||
|
||||
|
||||
void luaF_freeclosure (lua_State *L, Closure *c) {
|
||||
int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
|
||||
sizeLclosure(c->l.nupvalues);
|
||||
luaM_freemem(L, c, size);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Look for n-th local variable at line `line' in function `func'.
|
||||
** Returns NULL if not found.
|
||||
|
||||
5
lfunc.h
5
lfunc.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lfunc.h,v 2.8 2012/05/08 13:53:33 roberto Exp $
|
||||
** $Id: lfunc.h,v 2.5 2010/03/26 20:58:11 roberto Exp roberto $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -20,11 +20,12 @@
|
||||
|
||||
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
|
||||
LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems);
|
||||
LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems);
|
||||
LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, Proto *p);
|
||||
LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
|
||||
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
|
||||
LUAI_FUNC void luaF_close (lua_State *L, StkId level);
|
||||
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
|
||||
LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);
|
||||
LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
|
||||
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
|
||||
int pc);
|
||||
|
||||
529
lgc.c
529
lgc.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 2.140.1.2 2013/04/26 18:22:05 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 2.115 2011/11/28 17:25:48 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -24,31 +24,34 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** cost of sweeping one element (the size of a small object divided
|
||||
** by some adjust for the sweep speed)
|
||||
*/
|
||||
#define GCSWEEPCOST ((sizeof(TString) + 4) / 4)
|
||||
/* how much to allocate before next GC step */
|
||||
#define GCSTEPSIZE 1024
|
||||
|
||||
/* maximum number of elements to sweep in each single step */
|
||||
#define GCSWEEPMAX (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))
|
||||
#define GCSWEEPMAX 40
|
||||
|
||||
/* cost of sweeping one element */
|
||||
#define GCSWEEPCOST 1
|
||||
|
||||
/* maximum number of finalizers to call in each GC step */
|
||||
#define GCFINALIZENUM 4
|
||||
|
||||
/* cost of marking the root set */
|
||||
#define GCROOTCOST 10
|
||||
|
||||
/*
|
||||
** macro to adjust 'stepmul': 'stepmul' is actually used like
|
||||
** 'stepmul / STEPMULADJ' (value chosen by tests)
|
||||
*/
|
||||
#define STEPMULADJ 200
|
||||
/* cost of atomic step */
|
||||
#define GCATOMICCOST 1000
|
||||
|
||||
/* basic cost to traverse one object (to be added to the links the
|
||||
object may have) */
|
||||
#define TRAVCOST 5
|
||||
|
||||
|
||||
/*
|
||||
** macro to adjust 'pause': 'pause' is actually used like
|
||||
** 'pause / PAUSEADJ' (value chosen by tests)
|
||||
** standard negative debt for GC; a reasonable "time" to wait before
|
||||
** starting a new cycle
|
||||
*/
|
||||
#define PAUSEADJ 100
|
||||
#define stddebt(g) (-cast(l_mem, gettotalbytes(g)/100) * g->gcpause)
|
||||
|
||||
|
||||
/*
|
||||
@@ -62,6 +65,8 @@
|
||||
#define white2gray(x) resetbits(gch(x)->marked, WHITEBITS)
|
||||
#define black2gray(x) resetbit(gch(x)->marked, BLACKBIT)
|
||||
|
||||
#define stringmark(s) ((void)((s) && resetbits((s)->tsv.marked, WHITEBITS)))
|
||||
|
||||
|
||||
#define isfinalized(x) testbit(gch(x)->marked, FINALIZEDBIT)
|
||||
|
||||
@@ -118,10 +123,10 @@ static void removeentry (Node *n) {
|
||||
** other objects: if really collected, cannot keep them; for objects
|
||||
** being finalized, keep them in keys, but not in values
|
||||
*/
|
||||
static int iscleared (global_State *g, const TValue *o) {
|
||||
static int iscleared (const TValue *o) {
|
||||
if (!iscollectable(o)) return 0;
|
||||
else if (ttisstring(o)) {
|
||||
markobject(g, rawtsvalue(o)); /* strings are `values', so are never weak */
|
||||
stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */
|
||||
return 0;
|
||||
}
|
||||
else return iswhite(gcvalue(o));
|
||||
@@ -135,9 +140,9 @@ static int iscleared (global_State *g, const TValue *o) {
|
||||
void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
|
||||
global_State *g = G(L);
|
||||
lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
|
||||
lua_assert(g->gcstate != GCSpause);
|
||||
lua_assert(isgenerational(g) || g->gcstate != GCSpause);
|
||||
lua_assert(gch(o)->tt != LUA_TTABLE);
|
||||
if (keepinvariantout(g)) /* must keep invariant? */
|
||||
if (keepinvariant(g)) /* must keep invariant? */
|
||||
reallymarkobject(g, v); /* restore invariant */
|
||||
else { /* sweep phase */
|
||||
lua_assert(issweepphase(g));
|
||||
@@ -212,8 +217,7 @@ void luaC_checkupvalcolor (global_State *g, UpVal *uv) {
|
||||
GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,
|
||||
int offset) {
|
||||
global_State *g = G(L);
|
||||
char *raw = cast(char *, luaM_newobject(L, novariant(tt), sz));
|
||||
GCObject *o = obj2gco(raw + offset);
|
||||
GCObject *o = obj2gco(cast(char *, luaM_newobject(L, tt, sz)) + offset);
|
||||
if (list == NULL)
|
||||
list = &g->allgc; /* standard list for collectable objects */
|
||||
gch(o)->marked = luaC_white(g);
|
||||
@@ -235,63 +239,54 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,
|
||||
|
||||
|
||||
/*
|
||||
** mark an object. Userdata, strings, and closed upvalues are visited
|
||||
** and turned black here. Other objects are marked gray and added
|
||||
** to appropriate list to be visited (and turned black) later. (Open
|
||||
** upvalues are already linked in 'headuv' list.)
|
||||
** mark an object. Userdata and closed upvalues are visited and turned
|
||||
** black here. Strings remain gray (it is the same as making them
|
||||
** black). Other objects are marked gray and added to appropriate list
|
||||
** to be visited (and turned black) later. (Open upvalues are already
|
||||
** linked in 'headuv' list.)
|
||||
*/
|
||||
static void reallymarkobject (global_State *g, GCObject *o) {
|
||||
lu_mem size;
|
||||
lua_assert(iswhite(o) && !isdead(g, o));
|
||||
white2gray(o);
|
||||
switch (gch(o)->tt) {
|
||||
case LUA_TSHRSTR:
|
||||
case LUA_TLNGSTR: {
|
||||
size = sizestring(gco2ts(o));
|
||||
break; /* nothing else to mark; make it black */
|
||||
case LUA_TSTRING: {
|
||||
return; /* for strings, gray is as good as black */
|
||||
}
|
||||
case LUA_TUSERDATA: {
|
||||
Table *mt = gco2u(o)->metatable;
|
||||
markobject(g, mt);
|
||||
markobject(g, gco2u(o)->env);
|
||||
size = sizeudata(gco2u(o));
|
||||
break;
|
||||
gray2black(o); /* all pointers marked */
|
||||
return;
|
||||
}
|
||||
case LUA_TUPVAL: {
|
||||
UpVal *uv = gco2uv(o);
|
||||
markvalue(g, uv->v);
|
||||
if (uv->v != &uv->u.value) /* open? */
|
||||
return; /* open upvalues remain gray */
|
||||
size = sizeof(UpVal);
|
||||
if (uv->v == &uv->u.value) /* closed? (open upvalues remain gray) */
|
||||
gray2black(o); /* make it black */
|
||||
return;
|
||||
}
|
||||
case LUA_TFUNCTION: {
|
||||
gco2cl(o)->c.gclist = g->gray;
|
||||
g->gray = o;
|
||||
break;
|
||||
}
|
||||
case LUA_TLCL: {
|
||||
gco2lcl(o)->gclist = g->gray;
|
||||
g->gray = o;
|
||||
return;
|
||||
}
|
||||
case LUA_TCCL: {
|
||||
gco2ccl(o)->gclist = g->gray;
|
||||
g->gray = o;
|
||||
return;
|
||||
}
|
||||
case LUA_TTABLE: {
|
||||
linktable(gco2t(o), &g->gray);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case LUA_TTHREAD: {
|
||||
gco2th(o)->gclist = g->gray;
|
||||
g->gray = o;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case LUA_TPROTO: {
|
||||
gco2p(o)->gclist = g->gray;
|
||||
g->gray = o;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
default: lua_assert(0); return;
|
||||
default: lua_assert(0);
|
||||
}
|
||||
gray2black(o);
|
||||
g->GCmemtrav += size;
|
||||
}
|
||||
|
||||
|
||||
@@ -334,7 +329,7 @@ static void remarkupvals (global_State *g) {
|
||||
** mark root set and reset all gray lists, to start a new
|
||||
** incremental (or full) collection
|
||||
*/
|
||||
static void restartcollection (global_State *g) {
|
||||
static void markroot (global_State *g) {
|
||||
g->gray = g->grayagain = NULL;
|
||||
g->weak = g->allweak = g->ephemeron = NULL;
|
||||
markobject(g, g->mainthread);
|
||||
@@ -364,7 +359,7 @@ static void traverseweakvalue (global_State *g, Table *h) {
|
||||
else {
|
||||
lua_assert(!ttisnil(gkey(n)));
|
||||
markvalue(g, gkey(n)); /* mark key */
|
||||
if (!hasclears && iscleared(g, gval(n))) /* is there a white value? */
|
||||
if (!hasclears && iscleared(gval(n))) /* is there a white value? */
|
||||
hasclears = 1; /* table will have to be cleared */
|
||||
}
|
||||
}
|
||||
@@ -393,7 +388,7 @@ static int traverseephemeron (global_State *g, Table *h) {
|
||||
checkdeadkey(n);
|
||||
if (ttisnil(gval(n))) /* entry is empty? */
|
||||
removeentry(n); /* remove it */
|
||||
else if (iscleared(g, gkey(n))) { /* key is not marked (yet)? */
|
||||
else if (iscleared(gkey(n))) { /* key is not marked (yet)? */
|
||||
hasclears = 1; /* table must be cleared */
|
||||
if (valiswhite(gval(n))) /* value not marked yet? */
|
||||
prop = 1; /* must propagate again */
|
||||
@@ -403,7 +398,7 @@ static int traverseephemeron (global_State *g, Table *h) {
|
||||
reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
|
||||
}
|
||||
}
|
||||
if (g->gcstate != GCSatomic || prop)
|
||||
if (prop)
|
||||
linktable(h, &g->ephemeron); /* have to propagate again */
|
||||
else if (hasclears) /* does table have white keys? */
|
||||
linktable(h, &g->allweak); /* may have to clean white keys */
|
||||
@@ -431,26 +426,30 @@ static void traversestrongtable (global_State *g, Table *h) {
|
||||
}
|
||||
|
||||
|
||||
static lu_mem traversetable (global_State *g, Table *h) {
|
||||
const char *weakkey, *weakvalue;
|
||||
static int traversetable (global_State *g, Table *h) {
|
||||
const TValue *mode = gfasttm(g, h->metatable, TM_MODE);
|
||||
markobject(g, h->metatable);
|
||||
if (mode && ttisstring(mode) && /* is there a weak mode? */
|
||||
((weakkey = strchr(svalue(mode), 'k')),
|
||||
(weakvalue = strchr(svalue(mode), 'v')),
|
||||
(weakkey || weakvalue))) { /* is really weak? */
|
||||
black2gray(obj2gco(h)); /* keep table gray */
|
||||
if (!weakkey) /* strong keys? */
|
||||
traverseweakvalue(g, h);
|
||||
else if (!weakvalue) /* strong values? */
|
||||
traverseephemeron(g, h);
|
||||
else /* all weak */
|
||||
linktable(h, &g->allweak); /* nothing to traverse now */
|
||||
if (mode && ttisstring(mode)) { /* is there a weak mode? */
|
||||
int weakkey = (strchr(svalue(mode), 'k') != NULL);
|
||||
int weakvalue = (strchr(svalue(mode), 'v') != NULL);
|
||||
if (weakkey || weakvalue) { /* is really weak? */
|
||||
black2gray(obj2gco(h)); /* keep table gray */
|
||||
if (!weakkey) { /* strong keys? */
|
||||
traverseweakvalue(g, h);
|
||||
return TRAVCOST + sizenode(h);
|
||||
}
|
||||
else if (!weakvalue) { /* strong values? */
|
||||
traverseephemeron(g, h);
|
||||
return TRAVCOST + h->sizearray + sizenode(h);
|
||||
}
|
||||
else {
|
||||
linktable(h, &g->allweak); /* nothing to traverse now */
|
||||
return TRAVCOST;
|
||||
}
|
||||
} /* else go through */
|
||||
}
|
||||
else /* not weak */
|
||||
traversestrongtable(g, h);
|
||||
return sizeof(Table) + sizeof(TValue) * h->sizearray +
|
||||
sizeof(Node) * cast(size_t, sizenode(h));
|
||||
traversestrongtable(g, h);
|
||||
return TRAVCOST + h->sizearray + (2 * sizenode(h));
|
||||
}
|
||||
|
||||
|
||||
@@ -458,108 +457,86 @@ static int traverseproto (global_State *g, Proto *f) {
|
||||
int i;
|
||||
if (f->cache && iswhite(obj2gco(f->cache)))
|
||||
f->cache = NULL; /* allow cache to be collected */
|
||||
markobject(g, f->source);
|
||||
stringmark(f->source);
|
||||
for (i = 0; i < f->sizek; i++) /* mark literals */
|
||||
markvalue(g, &f->k[i]);
|
||||
for (i = 0; i < f->sizeupvalues; i++) /* mark upvalue names */
|
||||
markobject(g, f->upvalues[i].name);
|
||||
stringmark(f->upvalues[i].name);
|
||||
for (i = 0; i < f->sizep; i++) /* mark nested protos */
|
||||
markobject(g, f->p[i]);
|
||||
for (i = 0; i < f->sizelocvars; i++) /* mark local-variable names */
|
||||
markobject(g, f->locvars[i].varname);
|
||||
return sizeof(Proto) + sizeof(Instruction) * f->sizecode +
|
||||
sizeof(Proto *) * f->sizep +
|
||||
sizeof(TValue) * f->sizek +
|
||||
sizeof(int) * f->sizelineinfo +
|
||||
sizeof(LocVar) * f->sizelocvars +
|
||||
sizeof(Upvaldesc) * f->sizeupvalues;
|
||||
stringmark(f->locvars[i].varname);
|
||||
return TRAVCOST + f->sizek + f->sizeupvalues + f->sizep + f->sizelocvars;
|
||||
}
|
||||
|
||||
|
||||
static lu_mem traverseCclosure (global_State *g, CClosure *cl) {
|
||||
int i;
|
||||
for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
|
||||
markvalue(g, &cl->upvalue[i]);
|
||||
return sizeCclosure(cl->nupvalues);
|
||||
}
|
||||
|
||||
static lu_mem traverseLclosure (global_State *g, LClosure *cl) {
|
||||
int i;
|
||||
markobject(g, cl->p); /* mark its prototype */
|
||||
for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
|
||||
markobject(g, cl->upvals[i]);
|
||||
return sizeLclosure(cl->nupvalues);
|
||||
static int traverseclosure (global_State *g, Closure *cl) {
|
||||
if (cl->c.isC) {
|
||||
int i;
|
||||
for (i=0; i<cl->c.nupvalues; i++) /* mark its upvalues */
|
||||
markvalue(g, &cl->c.upvalue[i]);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
|
||||
markobject(g, cl->l.p); /* mark its prototype */
|
||||
for (i=0; i<cl->l.nupvalues; i++) /* mark its upvalues */
|
||||
markobject(g, cl->l.upvals[i]);
|
||||
}
|
||||
return TRAVCOST + cl->c.nupvalues;
|
||||
}
|
||||
|
||||
|
||||
static lu_mem traversestack (global_State *g, lua_State *th) {
|
||||
int n = 0;
|
||||
StkId o = th->stack;
|
||||
static int traversestack (global_State *g, lua_State *L) {
|
||||
StkId o = L->stack;
|
||||
if (o == NULL)
|
||||
return 1; /* stack not completely built yet */
|
||||
for (; o < th->top; o++) /* mark live elements in the stack */
|
||||
for (; o < L->top; o++)
|
||||
markvalue(g, o);
|
||||
if (g->gcstate == GCSatomic) { /* final traversal? */
|
||||
StkId lim = th->stack + th->stacksize; /* real end of stack */
|
||||
StkId lim = L->stack + L->stacksize; /* real end of stack */
|
||||
for (; o < lim; o++) /* clear not-marked stack slice */
|
||||
setnilvalue(o);
|
||||
}
|
||||
else { /* count call infos to compute size */
|
||||
CallInfo *ci;
|
||||
for (ci = &th->base_ci; ci != th->ci; ci = ci->next)
|
||||
n++;
|
||||
}
|
||||
return sizeof(lua_State) + sizeof(TValue) * th->stacksize +
|
||||
sizeof(CallInfo) * n;
|
||||
return TRAVCOST + cast_int(o - L->stack);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** traverse one gray object, turning it to black (except for threads,
|
||||
** which are always gray).
|
||||
** Returns number of values traversed.
|
||||
*/
|
||||
static void propagatemark (global_State *g) {
|
||||
lu_mem size;
|
||||
static int propagatemark (global_State *g) {
|
||||
GCObject *o = g->gray;
|
||||
lua_assert(isgray(o));
|
||||
gray2black(o);
|
||||
switch (gch(o)->tt) {
|
||||
case LUA_TTABLE: {
|
||||
Table *h = gco2t(o);
|
||||
g->gray = h->gclist; /* remove from 'gray' list */
|
||||
size = traversetable(g, h);
|
||||
break;
|
||||
g->gray = h->gclist;
|
||||
return traversetable(g, h);
|
||||
}
|
||||
case LUA_TLCL: {
|
||||
LClosure *cl = gco2lcl(o);
|
||||
g->gray = cl->gclist; /* remove from 'gray' list */
|
||||
size = traverseLclosure(g, cl);
|
||||
break;
|
||||
}
|
||||
case LUA_TCCL: {
|
||||
CClosure *cl = gco2ccl(o);
|
||||
g->gray = cl->gclist; /* remove from 'gray' list */
|
||||
size = traverseCclosure(g, cl);
|
||||
break;
|
||||
case LUA_TFUNCTION: {
|
||||
Closure *cl = gco2cl(o);
|
||||
g->gray = cl->c.gclist;
|
||||
return traverseclosure(g, cl);
|
||||
}
|
||||
case LUA_TTHREAD: {
|
||||
lua_State *th = gco2th(o);
|
||||
g->gray = th->gclist; /* remove from 'gray' list */
|
||||
g->gray = th->gclist;
|
||||
th->gclist = g->grayagain;
|
||||
g->grayagain = o; /* insert into 'grayagain' list */
|
||||
g->grayagain = o;
|
||||
black2gray(o);
|
||||
size = traversestack(g, th);
|
||||
break;
|
||||
return traversestack(g, th);
|
||||
}
|
||||
case LUA_TPROTO: {
|
||||
Proto *p = gco2p(o);
|
||||
g->gray = p->gclist; /* remove from 'gray' list */
|
||||
size = traverseproto(g, p);
|
||||
break;
|
||||
g->gray = p->gclist;
|
||||
return traverseproto(g, p);
|
||||
}
|
||||
default: lua_assert(0); return;
|
||||
default: lua_assert(0); return 0;
|
||||
}
|
||||
g->GCmemtrav += size;
|
||||
}
|
||||
|
||||
|
||||
@@ -622,12 +599,12 @@ static void convergeephemerons (global_State *g) {
|
||||
** clear entries with unmarked keys from all weaktables in list 'l' up
|
||||
** to element 'f'
|
||||
*/
|
||||
static void clearkeys (global_State *g, GCObject *l, GCObject *f) {
|
||||
static void clearkeys (GCObject *l, GCObject *f) {
|
||||
for (; l != f; l = gco2t(l)->gclist) {
|
||||
Table *h = gco2t(l);
|
||||
Node *n, *limit = gnodelast(h);
|
||||
for (n = gnode(h, 0); n < limit; n++) {
|
||||
if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) {
|
||||
if (!ttisnil(gval(n)) && (iscleared(gkey(n)))) {
|
||||
setnilvalue(gval(n)); /* remove value ... */
|
||||
removeentry(n); /* and remove entry from table */
|
||||
}
|
||||
@@ -640,18 +617,18 @@ static void clearkeys (global_State *g, GCObject *l, GCObject *f) {
|
||||
** clear entries with unmarked values from all weaktables in list 'l' up
|
||||
** to element 'f'
|
||||
*/
|
||||
static void clearvalues (global_State *g, GCObject *l, GCObject *f) {
|
||||
static void clearvalues (GCObject *l, GCObject *f) {
|
||||
for (; l != f; l = gco2t(l)->gclist) {
|
||||
Table *h = gco2t(l);
|
||||
Node *n, *limit = gnodelast(h);
|
||||
int i;
|
||||
for (i = 0; i < h->sizearray; i++) {
|
||||
TValue *o = &h->array[i];
|
||||
if (iscleared(g, o)) /* value was collected? */
|
||||
if (iscleared(o)) /* value was collected? */
|
||||
setnilvalue(o); /* remove value */
|
||||
}
|
||||
for (n = gnode(h, 0); n < limit; n++) {
|
||||
if (!ttisnil(gval(n)) && iscleared(g, gval(n))) {
|
||||
if (!ttisnil(gval(n)) && iscleared(gval(n))) {
|
||||
setnilvalue(gval(n)); /* remove value ... */
|
||||
removeentry(n); /* and remove entry from table */
|
||||
}
|
||||
@@ -663,22 +640,13 @@ static void clearvalues (global_State *g, GCObject *l, GCObject *f) {
|
||||
static void freeobj (lua_State *L, GCObject *o) {
|
||||
switch (gch(o)->tt) {
|
||||
case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
|
||||
case LUA_TLCL: {
|
||||
luaM_freemem(L, o, sizeLclosure(gco2lcl(o)->nupvalues));
|
||||
break;
|
||||
}
|
||||
case LUA_TCCL: {
|
||||
luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));
|
||||
break;
|
||||
}
|
||||
case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;
|
||||
case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
|
||||
case LUA_TTABLE: luaH_free(L, gco2t(o)); break;
|
||||
case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;
|
||||
case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
|
||||
case LUA_TSHRSTR:
|
||||
case LUA_TSTRING: {
|
||||
G(L)->strt.nuse--;
|
||||
/* go through */
|
||||
case LUA_TLNGSTR: {
|
||||
luaM_freemem(L, o, sizestring(gco2ts(o)));
|
||||
break;
|
||||
}
|
||||
@@ -721,6 +689,7 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
|
||||
int ow = otherwhite(g);
|
||||
int toclear, toset; /* bits to clear and to set in all live objects */
|
||||
int tostop; /* stop sweep when this is true */
|
||||
l_mem debt = g->GCdebt; /* current debt */
|
||||
if (isgenerational(g)) { /* generational mode? */
|
||||
toclear = ~0; /* clear nothing */
|
||||
toset = bitmask(OLDBIT); /* set the old bit of all surviving objects */
|
||||
@@ -739,30 +708,19 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
|
||||
freeobj(L, curr); /* erase 'curr' */
|
||||
}
|
||||
else {
|
||||
if (testbits(marked, tostop))
|
||||
return NULL; /* stop sweeping this list */
|
||||
if (gch(curr)->tt == LUA_TTHREAD)
|
||||
sweepthread(L, gco2th(curr)); /* sweep thread's upvalues */
|
||||
if (testbits(marked, tostop)) {
|
||||
static GCObject *nullp = NULL;
|
||||
p = &nullp; /* stop sweeping this list */
|
||||
break;
|
||||
}
|
||||
/* update marks */
|
||||
gch(curr)->marked = cast_byte((marked & toclear) | toset);
|
||||
p = &gch(curr)->next; /* go to next element */
|
||||
}
|
||||
}
|
||||
return (*p == NULL) ? NULL : p;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** sweep a list until a live object (or end of list)
|
||||
*/
|
||||
static GCObject **sweeptolive (lua_State *L, GCObject **p, int *n) {
|
||||
GCObject ** old = p;
|
||||
int i = 0;
|
||||
do {
|
||||
i++;
|
||||
p = sweeplist(L, p, 1);
|
||||
} while (p == old);
|
||||
if (n) *n += i;
|
||||
luaE_setdebt(g, debt); /* sweeping should not change debt */
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -794,7 +752,7 @@ static GCObject *udata2finalize (global_State *g) {
|
||||
g->allgc = o;
|
||||
resetbit(gch(o)->marked, SEPARATED); /* mark that it is not in 'tobefnz' */
|
||||
lua_assert(!isold(o)); /* see MOVE OLD rule */
|
||||
if (!keepinvariantout(g)) /* not keeping invariant? */
|
||||
if (!keepinvariant(g)) /* not keeping invariant? */
|
||||
makewhite(g, o); /* "sweep" object */
|
||||
return o;
|
||||
}
|
||||
@@ -825,14 +783,12 @@ static void GCTM (lua_State *L, int propagateerrors) {
|
||||
L->allowhook = oldah; /* restore hooks */
|
||||
g->gcrunning = running; /* restore state */
|
||||
if (status != LUA_OK && propagateerrors) { /* error while running __gc? */
|
||||
if (status == LUA_ERRRUN) { /* is there an error object? */
|
||||
const char *msg = (ttisstring(L->top - 1))
|
||||
? svalue(L->top - 1)
|
||||
: "no message";
|
||||
luaO_pushfstring(L, "error in __gc metamethod (%s)", msg);
|
||||
if (status == LUA_ERRRUN) { /* is there an error msg.? */
|
||||
luaO_pushfstring(L, "error in __gc metamethod (%s)",
|
||||
lua_tostring(L, -1));
|
||||
status = LUA_ERRGCMM; /* error in __gc metamethod */
|
||||
}
|
||||
luaD_throw(L, status); /* re-throw error */
|
||||
luaD_throw(L, status); /* re-send error */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -853,7 +809,7 @@ static void separatetobefnz (lua_State *L, int all) {
|
||||
while ((curr = *p) != NULL) { /* traverse all finalizable objects */
|
||||
lua_assert(!isfinalized(curr));
|
||||
lua_assert(testbit(gch(curr)->marked, SEPARATED));
|
||||
if (!(iswhite(curr) || all)) /* not being collected? */
|
||||
if (!(all || iswhite(curr))) /* not being collected? */
|
||||
p = &gch(curr)->next; /* don't bother with it */
|
||||
else {
|
||||
l_setbit(gch(curr)->marked, FINALIZEDBIT); /* won't be finalized again */
|
||||
@@ -878,21 +834,12 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
|
||||
return; /* nothing to be done */
|
||||
else { /* move 'o' to 'finobj' list */
|
||||
GCObject **p;
|
||||
GCheader *ho = gch(o);
|
||||
if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */
|
||||
lua_assert(issweepphase(g));
|
||||
g->sweepgc = sweeptolive(L, g->sweepgc, NULL);
|
||||
}
|
||||
/* search for pointer pointing to 'o' */
|
||||
for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ }
|
||||
*p = ho->next; /* remove 'o' from root list */
|
||||
ho->next = g->finobj; /* link it in list 'finobj' */
|
||||
for (p = &g->allgc; *p != o; p = &gch(*p)->next) ;
|
||||
*p = gch(o)->next; /* remove 'o' from root list */
|
||||
gch(o)->next = g->finobj; /* link it in list 'finobj' */
|
||||
g->finobj = o;
|
||||
l_setbit(ho->marked, SEPARATED); /* mark it as such */
|
||||
if (!keepinvariantout(g)) /* not keeping invariant? */
|
||||
makewhite(g, o); /* "sweep" object */
|
||||
else
|
||||
resetoldbit(o); /* see MOVE OLD rule */
|
||||
l_setbit(gch(o)->marked, SEPARATED); /* mark it as such */
|
||||
resetoldbit(o); /* see MOVE OLD rule */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -906,46 +853,9 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** set a reasonable "time" to wait before starting a new GC cycle;
|
||||
** cycle will start when memory use hits threshold
|
||||
*/
|
||||
static void setpause (global_State *g, l_mem estimate) {
|
||||
l_mem debt, threshold;
|
||||
estimate = estimate / PAUSEADJ; /* adjust 'estimate' */
|
||||
threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */
|
||||
? estimate * g->gcpause /* no overflow */
|
||||
: MAX_LMEM; /* overflow; truncate to maximum */
|
||||
debt = -cast(l_mem, threshold - gettotalbytes(g));
|
||||
luaE_setdebt(g, debt);
|
||||
}
|
||||
|
||||
|
||||
#define sweepphases \
|
||||
(bitmask(GCSsweepstring) | bitmask(GCSsweepudata) | bitmask(GCSsweep))
|
||||
|
||||
|
||||
/*
|
||||
** enter first sweep phase (strings) and prepare pointers for other
|
||||
** sweep phases. The calls to 'sweeptolive' make pointers point to an
|
||||
** object inside the list (instead of to the header), so that the real
|
||||
** sweep do not need to skip objects created between "now" and the start
|
||||
** of the real sweep.
|
||||
** Returns how many objects it swept.
|
||||
*/
|
||||
static int entersweep (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
int n = 0;
|
||||
g->gcstate = GCSsweepstring;
|
||||
lua_assert(g->sweepgc == NULL && g->sweepfin == NULL);
|
||||
/* prepare to sweep strings, finalizable objects, and regular objects */
|
||||
g->sweepstrgc = 0;
|
||||
g->sweepfin = sweeptolive(L, &g->finobj, &n);
|
||||
g->sweepgc = sweeptolive(L, &g->allgc, &n);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** change GC mode
|
||||
*/
|
||||
@@ -955,14 +865,15 @@ void luaC_changemode (lua_State *L, int mode) {
|
||||
if (mode == KGC_GEN) { /* change to generational mode */
|
||||
/* make sure gray lists are consistent */
|
||||
luaC_runtilstate(L, bitmask(GCSpropagate));
|
||||
g->GCestimate = gettotalbytes(g);
|
||||
g->lastmajormem = gettotalbytes(g);
|
||||
g->gckind = KGC_GEN;
|
||||
}
|
||||
else { /* change to incremental mode */
|
||||
/* sweep all objects to turn them back to white
|
||||
(as white has not changed, nothing extra will be collected) */
|
||||
g->sweepstrgc = 0;
|
||||
g->gcstate = GCSsweepstring;
|
||||
g->gckind = KGC_NORMAL;
|
||||
entersweep(L);
|
||||
luaC_runtilstate(L, ~sweepphases);
|
||||
}
|
||||
}
|
||||
@@ -996,9 +907,8 @@ void luaC_freeallobjects (lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
static l_mem atomic (lua_State *L) {
|
||||
static void atomic (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
l_mem work = -cast(l_mem, g->GCmemtrav); /* start counting work */
|
||||
GCObject *origweak, *origall;
|
||||
lua_assert(!iswhite(obj2gco(g->mainthread)));
|
||||
markobject(g, L); /* mark running thread */
|
||||
@@ -1007,85 +917,77 @@ static l_mem atomic (lua_State *L) {
|
||||
markmt(g); /* mark basic metatables */
|
||||
/* remark occasional upvalues of (maybe) dead threads */
|
||||
remarkupvals(g);
|
||||
propagateall(g); /* propagate changes */
|
||||
work += g->GCmemtrav; /* stop counting (do not (re)count grays) */
|
||||
/* traverse objects caught by write barrier and by 'remarkupvals' */
|
||||
retraversegrays(g);
|
||||
work -= g->GCmemtrav; /* restart counting */
|
||||
convergeephemerons(g);
|
||||
/* at this point, all strongly accessible objects are marked. */
|
||||
/* clear values from weak tables, before checking finalizers */
|
||||
clearvalues(g, g->weak, NULL);
|
||||
clearvalues(g, g->allweak, NULL);
|
||||
clearvalues(g->weak, NULL);
|
||||
clearvalues(g->allweak, NULL);
|
||||
origweak = g->weak; origall = g->allweak;
|
||||
work += g->GCmemtrav; /* stop counting (objects being finalized) */
|
||||
separatetobefnz(L, 0); /* separate objects to be finalized */
|
||||
markbeingfnz(g); /* mark objects that will be finalized */
|
||||
markbeingfnz(g); /* mark userdata that will be finalized */
|
||||
propagateall(g); /* remark, to propagate `preserveness' */
|
||||
work -= g->GCmemtrav; /* restart counting */
|
||||
convergeephemerons(g);
|
||||
/* at this point, all resurrected objects are marked. */
|
||||
/* remove dead objects from weak tables */
|
||||
clearkeys(g, g->ephemeron, NULL); /* clear keys from all ephemeron tables */
|
||||
clearkeys(g, g->allweak, NULL); /* clear keys from all allweak tables */
|
||||
clearkeys(g->ephemeron, NULL); /* clear keys from all ephemeron tables */
|
||||
clearkeys(g->allweak, NULL); /* clear keys from all allweak tables */
|
||||
/* clear values from resurrected weak tables */
|
||||
clearvalues(g, g->weak, origweak);
|
||||
clearvalues(g, g->allweak, origall);
|
||||
clearvalues(g->weak, origweak);
|
||||
clearvalues(g->allweak, origall);
|
||||
g->sweepstrgc = 0; /* prepare to sweep strings */
|
||||
g->gcstate = GCSsweepstring;
|
||||
g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
|
||||
work += g->GCmemtrav; /* complete counting */
|
||||
return work; /* estimate of memory marked by 'atomic' */
|
||||
/*lua_checkmemory(L);*/
|
||||
}
|
||||
|
||||
|
||||
static lu_mem singlestep (lua_State *L) {
|
||||
static l_mem singlestep (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
switch (g->gcstate) {
|
||||
case GCSpause: {
|
||||
/* start to count memory traversed */
|
||||
g->GCmemtrav = g->strt.size * sizeof(GCObject*);
|
||||
lua_assert(!isgenerational(g));
|
||||
restartcollection(g);
|
||||
if (!isgenerational(g))
|
||||
markroot(g); /* start a new collection */
|
||||
/* in any case, root must be marked */
|
||||
lua_assert(!iswhite(obj2gco(g->mainthread))
|
||||
&& !iswhite(gcvalue(&g->l_registry)));
|
||||
g->gcstate = GCSpropagate;
|
||||
return g->GCmemtrav;
|
||||
return GCROOTCOST;
|
||||
}
|
||||
case GCSpropagate: {
|
||||
if (g->gray) {
|
||||
lu_mem oldtrav = g->GCmemtrav;
|
||||
propagatemark(g);
|
||||
return g->GCmemtrav - oldtrav; /* memory traversed in this step */
|
||||
}
|
||||
if (g->gray)
|
||||
return propagatemark(g);
|
||||
else { /* no more `gray' objects */
|
||||
lu_mem work;
|
||||
int sw;
|
||||
g->gcstate = GCSatomic; /* finish mark phase */
|
||||
g->GCestimate = g->GCmemtrav; /* save what was counted */;
|
||||
work = atomic(L); /* add what was traversed by 'atomic' */
|
||||
g->GCestimate += work; /* estimate of total memory traversed */
|
||||
sw = entersweep(L);
|
||||
return work + sw * GCSWEEPCOST;
|
||||
atomic(L);
|
||||
return GCATOMICCOST;
|
||||
}
|
||||
}
|
||||
case GCSsweepstring: {
|
||||
int i;
|
||||
for (i = 0; i < GCSWEEPMAX && g->sweepstrgc + i < g->strt.size; i++)
|
||||
sweepwholelist(L, &g->strt.hash[g->sweepstrgc + i]);
|
||||
g->sweepstrgc += i;
|
||||
if (g->sweepstrgc >= g->strt.size) /* no more strings to sweep? */
|
||||
g->gcstate = GCSsweepudata;
|
||||
return i * GCSWEEPCOST;
|
||||
}
|
||||
case GCSsweepudata: {
|
||||
if (g->sweepfin) {
|
||||
g->sweepfin = sweeplist(L, g->sweepfin, GCSWEEPMAX);
|
||||
return GCSWEEPMAX*GCSWEEPCOST;
|
||||
if (g->sweepstrgc < g->strt.size) {
|
||||
sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
|
||||
return GCSWEEPCOST;
|
||||
}
|
||||
else {
|
||||
g->gcstate = GCSsweep;
|
||||
else { /* no more strings to sweep */
|
||||
g->sweepgc = &g->finobj; /* prepare to sweep finalizable objects */
|
||||
g->gcstate = GCSsweepudata;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
case GCSsweepudata: {
|
||||
if (*g->sweepgc) {
|
||||
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
||||
return GCSWEEPMAX*GCSWEEPCOST;
|
||||
}
|
||||
else {
|
||||
g->sweepgc = &g->allgc; /* go to next phase */
|
||||
g->gcstate = GCSsweep;
|
||||
return GCSWEEPCOST;
|
||||
}
|
||||
}
|
||||
case GCSsweep: {
|
||||
if (g->sweepgc) {
|
||||
if (*g->sweepgc) {
|
||||
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
||||
return GCSWEEPMAX*GCSWEEPCOST;
|
||||
}
|
||||
@@ -1116,58 +1018,43 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
|
||||
|
||||
static void generationalcollection (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
lua_assert(g->gcstate == GCSpropagate);
|
||||
if (g->GCestimate == 0) { /* signal for another major collection? */
|
||||
if (g->lastmajormem == 0) { /* signal for another major collection? */
|
||||
luaC_fullgc(L, 0); /* perform a full regular collection */
|
||||
g->GCestimate = gettotalbytes(g); /* update control */
|
||||
g->lastmajormem = gettotalbytes(g); /* update control */
|
||||
}
|
||||
else {
|
||||
lu_mem estimate = g->GCestimate;
|
||||
luaC_runtilstate(L, bitmask(GCSpause)); /* run complete (minor) cycle */
|
||||
g->gcstate = GCSpropagate; /* skip restart */
|
||||
if (gettotalbytes(g) > (estimate / 100) * g->gcmajorinc)
|
||||
g->GCestimate = 0; /* signal for a major collection */
|
||||
else
|
||||
g->GCestimate = estimate; /* keep estimate from last major coll. */
|
||||
|
||||
luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
|
||||
luaC_runtilstate(L, bitmask(GCSpause));
|
||||
if (gettotalbytes(g) > g->lastmajormem/100 * g->gcmajorinc)
|
||||
g->lastmajormem = 0; /* signal for a major collection */
|
||||
}
|
||||
setpause(g, gettotalbytes(g));
|
||||
lua_assert(g->gcstate == GCSpropagate);
|
||||
luaE_setdebt(g, stddebt(g));
|
||||
}
|
||||
|
||||
|
||||
static void incstep (lua_State *L) {
|
||||
static void step (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
l_mem debt = g->GCdebt;
|
||||
int stepmul = g->gcstepmul;
|
||||
if (stepmul < 40) stepmul = 40; /* avoid ridiculous low values (and 0) */
|
||||
/* convert debt from Kb to 'work units' (avoid zero debt and overflows) */
|
||||
debt = (debt / STEPMULADJ) + 1;
|
||||
debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
|
||||
l_mem lim = g->gcstepmul; /* how much to work */
|
||||
do { /* always perform at least one single step */
|
||||
lu_mem work = singlestep(L); /* do some work */
|
||||
debt -= work;
|
||||
} while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
|
||||
if (g->gcstate == GCSpause)
|
||||
setpause(g, g->GCestimate); /* pause until next cycle */
|
||||
else {
|
||||
debt = (debt / stepmul) * STEPMULADJ; /* convert 'work units' to Kb */
|
||||
luaE_setdebt(g, debt);
|
||||
}
|
||||
lim -= singlestep(L);
|
||||
} while (lim > 0 && g->gcstate != GCSpause);
|
||||
if (g->gcstate != GCSpause)
|
||||
luaE_setdebt(g, g->GCdebt - GCSTEPSIZE);
|
||||
else
|
||||
luaE_setdebt(g, stddebt(g));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** performs a basic GC step
|
||||
** performs a basic GC step even if the collector is stopped
|
||||
*/
|
||||
void luaC_forcestep (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
int i;
|
||||
if (isgenerational(g)) generationalcollection(L);
|
||||
else incstep(L);
|
||||
/* run a few finalizers (or all of them at the end of a collect cycle) */
|
||||
for (i = 0; g->tobefnz && (i < GCFINALIZENUM || g->gcstate == GCSpause); i++)
|
||||
GCTM(L, 1); /* call one finalizer */
|
||||
else step(L);
|
||||
for (i = 0; i < GCFINALIZENUM && g->tobefnz; i++)
|
||||
GCTM(L, 1); /* Call a few pending finalizers */
|
||||
}
|
||||
|
||||
|
||||
@@ -1175,13 +1062,10 @@ void luaC_forcestep (lua_State *L) {
|
||||
** performs a basic GC step only if collector is running
|
||||
*/
|
||||
void luaC_step (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
if (g->gcrunning) luaC_forcestep(L);
|
||||
else luaE_setdebt(g, -GCSTEPSIZE); /* avoid being called too often */
|
||||
if (G(L)->gcrunning) luaC_forcestep(L);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** performs a full GC cycle; if "isemergency", does not call
|
||||
** finalizers (which could change stack positions)
|
||||
@@ -1190,27 +1074,26 @@ void luaC_fullgc (lua_State *L, int isemergency) {
|
||||
global_State *g = G(L);
|
||||
int origkind = g->gckind;
|
||||
lua_assert(origkind != KGC_EMERGENCY);
|
||||
if (isemergency) /* do not run finalizers during emergency GC */
|
||||
g->gckind = KGC_EMERGENCY;
|
||||
else {
|
||||
g->gckind = KGC_NORMAL;
|
||||
if (!isemergency) /* do not run finalizers during emergency GC */
|
||||
callallpendingfinalizers(L, 1);
|
||||
}
|
||||
if (keepinvariant(g)) { /* may there be some black objects? */
|
||||
if (keepinvariant(g)) { /* marking phase? */
|
||||
/* must sweep all objects to turn them back to white
|
||||
(as white has not changed, nothing will be collected) */
|
||||
entersweep(L);
|
||||
g->sweepstrgc = 0;
|
||||
g->gcstate = GCSsweepstring;
|
||||
}
|
||||
g->gckind = isemergency ? KGC_EMERGENCY : KGC_NORMAL;
|
||||
/* finish any pending sweep phase to start a new cycle */
|
||||
luaC_runtilstate(L, bitmask(GCSpause));
|
||||
luaC_runtilstate(L, ~bitmask(GCSpause)); /* start new collection */
|
||||
luaC_runtilstate(L, bitmask(GCSpause)); /* run entire collection */
|
||||
/* run entire collector */
|
||||
luaC_runtilstate(L, ~bitmask(GCSpause));
|
||||
luaC_runtilstate(L, bitmask(GCSpause));
|
||||
if (origkind == KGC_GEN) { /* generational mode? */
|
||||
/* generational mode must be kept in propagate phase */
|
||||
/* generational mode must always start in propagate phase */
|
||||
luaC_runtilstate(L, bitmask(GCSpropagate));
|
||||
}
|
||||
g->gckind = origkind;
|
||||
setpause(g, gettotalbytes(g));
|
||||
luaE_setdebt(g, stddebt(g));
|
||||
if (!isemergency) /* do not run finalizers during emergency GC */
|
||||
callallpendingfinalizers(L, 1);
|
||||
}
|
||||
|
||||
24
lgc.h
24
lgc.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.h,v 2.58 2012/09/11 12:53:08 roberto Exp $
|
||||
** $Id: lgc.h,v 2.51 2011/09/30 12:44:19 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -25,14 +25,6 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* how much to allocate before next GC step */
|
||||
#if !defined(GCSTEPSIZE)
|
||||
/* ~100 small strings */
|
||||
#define GCSTEPSIZE (cast_int(100 * sizeof(TString)))
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Possible states of the Garbage Collector
|
||||
*/
|
||||
@@ -50,24 +42,14 @@
|
||||
#define isgenerational(g) ((g)->gckind == KGC_GEN)
|
||||
|
||||
/*
|
||||
** macros to tell when main invariant (white objects cannot point to black
|
||||
** macro to tell when main invariant (white objects cannot point to black
|
||||
** ones) must be kept. During a non-generational collection, the sweep
|
||||
** phase may break the invariant, as objects turned white may point to
|
||||
** still-black objects. The invariant is restored when sweep ends and
|
||||
** all objects are white again. During a generational collection, the
|
||||
** invariant must be kept all times.
|
||||
*/
|
||||
|
||||
#define keepinvariant(g) (isgenerational(g) || g->gcstate <= GCSatomic)
|
||||
|
||||
|
||||
/*
|
||||
** Outside the collector, the state in generational mode is kept in
|
||||
** 'propagate', so 'keepinvariant' is always true.
|
||||
*/
|
||||
#define keepinvariantout(g) \
|
||||
check_exp(g->gcstate == GCSpropagate || !isgenerational(g), \
|
||||
g->gcstate <= GCSatomic)
|
||||
#define keepinvariant(g) (isgenerational(g) || g->gcstate <= GCSatomic)
|
||||
|
||||
|
||||
/*
|
||||
|
||||
2
linit.c
2
linit.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: linit.c,v 1.32 2011/04/08 19:17:36 roberto Exp $
|
||||
** $Id: linit.c,v 1.31 2011/01/26 16:30:02 roberto Exp roberto $
|
||||
** Initialization of libraries for lua.c and other clients
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
47
liolib.c
47
liolib.c
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
** $Id: liolib.c,v 2.112 2013/04/11 18:34:06 roberto Exp $
|
||||
** $Id: liolib.c,v 2.107 2011/11/14 16:55:35 roberto Exp roberto $
|
||||
** Standard I/O (and system) library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** POSIX idiosyncrasy!
|
||||
** This definition must come before the inclusion of 'stdio.h'; it
|
||||
** should not affect non-POSIX systems
|
||||
*/
|
||||
#if !defined(_FILE_OFFSET_BITS)
|
||||
#define _LARGEFILE_SOURCE 1
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,20 +29,6 @@
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
#if !defined(lua_checkmode)
|
||||
|
||||
/*
|
||||
** Check whether 'mode' matches '[rwa]%+?b?'.
|
||||
** Change this macro to accept other modes for 'fopen' besides
|
||||
** the standard ones.
|
||||
*/
|
||||
#define lua_checkmode(mode) \
|
||||
(*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
|
||||
(*mode != '+' || ++mode) && /* skip if char is '+' */ \
|
||||
(*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
|
||||
(*mode == '\0'))
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
@@ -80,37 +66,36 @@
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** lua_fseek: configuration for longer offsets
|
||||
** lua_fseek/lua_ftell: configuration for longer offsets
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
#if !defined(lua_fseek) && !defined(LUA_ANSI) /* { */
|
||||
#if !defined(lua_fseek) /* { */
|
||||
|
||||
#if defined(LUA_USE_POSIX) /* { */
|
||||
#if defined(LUA_USE_POSIX)
|
||||
|
||||
#define l_fseek(f,o,w) fseeko(f,o,w)
|
||||
#define l_ftell(f) ftello(f)
|
||||
#define l_seeknum off_t
|
||||
|
||||
#elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
|
||||
&& defined(_MSC_VER) && (_MSC_VER >= 1400) /* }{ */
|
||||
&& defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
/* Windows (but not DDK) and Visual C++ 2005 or higher */
|
||||
|
||||
#define l_fseek(f,o,w) _fseeki64(f,o,w)
|
||||
#define l_ftell(f) _ftelli64(f)
|
||||
#define l_seeknum __int64
|
||||
|
||||
#endif /* } */
|
||||
#else
|
||||
|
||||
#endif /* } */
|
||||
|
||||
|
||||
#if !defined(l_fseek) /* default definitions */
|
||||
#define l_fseek(f,o,w) fseek(f,o,w)
|
||||
#define l_ftell(f) ftell(f)
|
||||
#define l_seeknum long
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* } */
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
@@ -227,8 +212,14 @@ static int io_open (lua_State *L) {
|
||||
const char *filename = luaL_checkstring(L, 1);
|
||||
const char *mode = luaL_optstring(L, 2, "r");
|
||||
LStream *p = newfile(L);
|
||||
const char *md = mode; /* to traverse/check mode */
|
||||
luaL_argcheck(L, lua_checkmode(md), 2, "invalid mode");
|
||||
int i = 0;
|
||||
/* check whether 'mode' matches '[rwa]%+?b?' */
|
||||
if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
|
||||
(mode[i] != '+' || ++i) && /* skip if char is '+' */
|
||||
(mode[i] != 'b' || ++i) && /* skip if char is 'b' */
|
||||
(mode[i] == '\0')))
|
||||
return luaL_error(L, "invalid mode " LUA_QS
|
||||
" (should match " LUA_QL("[rwa]%%+?b?") ")", mode);
|
||||
p->f = fopen(filename, mode);
|
||||
return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
|
||||
}
|
||||
|
||||
40
llex.c
40
llex.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: llex.c,v 2.63.1.2 2013/08/30 15:49:41 roberto Exp roberto $
|
||||
** $Id: llex.c,v 2.58 2011/08/15 19:41:58 roberto Exp roberto $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -67,22 +67,22 @@ void luaX_init (lua_State *L) {
|
||||
for (i=0; i<NUM_RESERVED; i++) {
|
||||
TString *ts = luaS_new(L, luaX_tokens[i]);
|
||||
luaS_fix(ts); /* reserved words are never collected */
|
||||
ts->tsv.extra = cast_byte(i+1); /* reserved word */
|
||||
ts->tsv.reserved = cast_byte(i+1); /* reserved word */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const char *luaX_token2str (LexState *ls, int token) {
|
||||
if (token < FIRST_RESERVED) { /* single-byte symbols? */
|
||||
if (token < FIRST_RESERVED) {
|
||||
lua_assert(token == cast(unsigned char, token));
|
||||
return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) :
|
||||
luaO_pushfstring(ls->L, "char(%d)", token);
|
||||
}
|
||||
else {
|
||||
const char *s = luaX_tokens[token - FIRST_RESERVED];
|
||||
if (token < TK_EOS) /* fixed format (symbols and reserved words)? */
|
||||
if (token < TK_EOS)
|
||||
return luaO_pushfstring(ls->L, LUA_QS, s);
|
||||
else /* names, strings, and numerals */
|
||||
else
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -133,9 +133,6 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
|
||||
setbvalue(o, 1); /* t[string] = true */
|
||||
luaC_checkGC(L);
|
||||
}
|
||||
else { /* string already present */
|
||||
ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */
|
||||
}
|
||||
L->top--; /* remove string from stack */
|
||||
return ts;
|
||||
}
|
||||
@@ -152,7 +149,7 @@ static void inclinenumber (LexState *ls) {
|
||||
if (currIsNewline(ls) && ls->current != old)
|
||||
next(ls); /* skip `\n\r' or `\r\n' */
|
||||
if (++ls->linenumber >= MAX_INT)
|
||||
lexerror(ls, "chunk has too many lines", 0);
|
||||
luaX_syntaxerror(ls, "chunk has too many lines");
|
||||
}
|
||||
|
||||
|
||||
@@ -225,24 +222,13 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
|
||||
|
||||
|
||||
/* LUA_NUMBER */
|
||||
/*
|
||||
** this function is quite liberal in what it accepts, as 'luaO_str2d'
|
||||
** will reject ill-formed numerals.
|
||||
*/
|
||||
static void read_numeral (LexState *ls, SemInfo *seminfo) {
|
||||
const char *expo = "Ee";
|
||||
int first = ls->current;
|
||||
lua_assert(lisdigit(ls->current));
|
||||
save_and_next(ls);
|
||||
if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
|
||||
expo = "Pp";
|
||||
for (;;) {
|
||||
if (check_next(ls, expo)) /* exponent part? */
|
||||
do {
|
||||
save_and_next(ls);
|
||||
if (check_next(ls, "EePp")) /* exponent part? */
|
||||
check_next(ls, "+-"); /* optional exponent sign */
|
||||
if (lisxdigit(ls->current) || ls->current == '.')
|
||||
save_and_next(ls);
|
||||
else break;
|
||||
}
|
||||
} while (lislalnum(ls->current) || ls->current == '.');
|
||||
save(ls, '\0');
|
||||
buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
|
||||
if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
|
||||
@@ -316,7 +302,7 @@ static int readhexaesc (LexState *ls) {
|
||||
int c[3], i; /* keep input for error message */
|
||||
int r = 0; /* result accumulator */
|
||||
c[0] = 'x'; /* for error message */
|
||||
for (i = 1; i < 3; i++) { /* read two hexadecimal digits */
|
||||
for (i = 1; i < 3; i++) { /* read two hexa digits */
|
||||
c[i] = next(ls);
|
||||
if (!lisxdigit(c[i]))
|
||||
escerror(ls, c, i + 1, "hexadecimal digit expected");
|
||||
@@ -494,8 +480,8 @@ static int llex (LexState *ls, SemInfo *seminfo) {
|
||||
ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
|
||||
luaZ_bufflen(ls->buff));
|
||||
seminfo->ts = ts;
|
||||
if (isreserved(ts)) /* reserved word? */
|
||||
return ts->tsv.extra - 1 + FIRST_RESERVED;
|
||||
if (ts->tsv.reserved > 0) /* reserved word? */
|
||||
return ts->tsv.reserved - 1 + FIRST_RESERVED;
|
||||
else {
|
||||
return TK_NAME;
|
||||
}
|
||||
|
||||
2
llex.h
2
llex.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: llex.h,v 1.72 2011/11/30 12:43:51 roberto Exp $
|
||||
** $Id: llex.h,v 1.71 2011/06/20 16:52:48 roberto Exp roberto $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
23
llimits.h
23
llimits.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: llimits.h,v 1.103 2013/02/20 14:08:56 roberto Exp $
|
||||
** $Id: llimits.h,v 1.94 2011/11/29 15:39:48 roberto Exp roberto $
|
||||
** Limits, basic types, and some other `installation-dependent' definitions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -31,8 +31,6 @@ typedef unsigned char lu_byte;
|
||||
|
||||
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
|
||||
|
||||
#define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))
|
||||
|
||||
|
||||
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
|
||||
|
||||
@@ -200,7 +198,7 @@ typedef lu_int32 Instruction;
|
||||
** both small and large values (outside the range of integers).
|
||||
*/
|
||||
|
||||
#if defined(MS_ASMTRICK) || defined(LUA_MSASMTRICK) /* { */
|
||||
#if defined(MS_ASMTRICK) /* { */
|
||||
/* trick with Microsoft assembler for X86 */
|
||||
|
||||
#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
|
||||
@@ -211,35 +209,30 @@ typedef lu_int32 Instruction;
|
||||
|
||||
#elif defined(LUA_IEEE754TRICK) /* }{ */
|
||||
/* the next trick should work on any machine using IEEE754 with
|
||||
a 32-bit int type */
|
||||
a 32-bit integer type */
|
||||
|
||||
union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
|
||||
|
||||
#if !defined(LUA_IEEEENDIAN) /* { */
|
||||
#define LUAI_EXTRAIEEE \
|
||||
static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
|
||||
#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33)
|
||||
#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
|
||||
#else
|
||||
#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN
|
||||
#define LUAI_EXTRAIEEE /* empty */
|
||||
#endif /* } */
|
||||
|
||||
#define lua_number2int32(i,n,t) \
|
||||
{ LUAI_EXTRAIEEE \
|
||||
volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
|
||||
(i) = (t)u.l_p[LUA_IEEEENDIANLOC]; }
|
||||
(i) = (t)u.l_p[LUA_IEEEENDIAN]; }
|
||||
|
||||
#define luai_hashnum(i,n) \
|
||||
{ volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \
|
||||
(i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */
|
||||
|
||||
#define lua_number2int(i,n) lua_number2int32(i, n, int)
|
||||
#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
|
||||
|
||||
/* the trick can be expanded to lua_Integer when it is a 32-bit value */
|
||||
#if defined(LUA_IEEELL)
|
||||
#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
|
||||
#endif
|
||||
#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
|
||||
|
||||
#endif /* } */
|
||||
|
||||
@@ -256,7 +249,7 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
|
||||
|
||||
#if !defined(lua_number2unsigned) /* { */
|
||||
/* the following definition assures proper modulo behavior */
|
||||
#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_NUMBER_FLOAT)
|
||||
#if defined(LUA_NUMBER_DOUBLE)
|
||||
#include <math.h>
|
||||
#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
|
||||
#define lua_number2unsigned(i,n) \
|
||||
@@ -282,7 +275,7 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
|
||||
#include <math.h>
|
||||
|
||||
#define luai_hashnum(i,n) { int e; \
|
||||
n = l_mathop(frexp)(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
|
||||
n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
|
||||
lua_number2int(i, n); i += e; }
|
||||
|
||||
#endif
|
||||
|
||||
72
lmathlib.c
72
lmathlib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lmathlib.c,v 1.83 2013/03/07 18:21:32 roberto Exp $
|
||||
** $Id: lmathlib.c,v 1.79 2010/11/18 18:38:27 roberto Exp roberto $
|
||||
** Standard mathematical library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -18,100 +18,105 @@
|
||||
|
||||
|
||||
#undef PI
|
||||
#define PI ((lua_Number)(3.1415926535897932384626433832795))
|
||||
#define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0))
|
||||
#define PI (3.14159265358979323846)
|
||||
#define RADIANS_PER_DEGREE (PI/180.0)
|
||||
|
||||
|
||||
/* macro 'l_tg' allows the addition of an 'l' or 'f' to all math operations */
|
||||
#if !defined(l_tg)
|
||||
#define l_tg(x) (x)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static int math_abs (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(fabs)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_sin (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(sin)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_sinh (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(sinh)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_cos (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(cos)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_cosh (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(cosh)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_tan (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(tan)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_tanh (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(tanh)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_asin (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(asin)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_acos (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(acos)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_atan (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(atan)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(atan)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_atan2 (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(atan2)(luaL_checknumber(L, 1),
|
||||
lua_pushnumber(L, l_tg(atan2)(luaL_checknumber(L, 1),
|
||||
luaL_checknumber(L, 2)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_ceil (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(ceil)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(ceil)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_floor (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(floor)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(floor)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_fmod (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),
|
||||
lua_pushnumber(L, l_tg(fmod)(luaL_checknumber(L, 1),
|
||||
luaL_checknumber(L, 2)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_modf (lua_State *L) {
|
||||
lua_Number ip;
|
||||
lua_Number fp = l_mathop(modf)(luaL_checknumber(L, 1), &ip);
|
||||
lua_Number fp = l_tg(modf)(luaL_checknumber(L, 1), &ip);
|
||||
lua_pushnumber(L, ip);
|
||||
lua_pushnumber(L, fp);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int math_sqrt (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(sqrt)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int math_pow (lua_State *L) {
|
||||
lua_Number x = luaL_checknumber(L, 1);
|
||||
lua_Number y = luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, l_mathop(pow)(x, y));
|
||||
lua_pushnumber(L, l_tg(pow)(luaL_checknumber(L, 1),
|
||||
luaL_checknumber(L, 2)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -119,11 +124,11 @@ static int math_log (lua_State *L) {
|
||||
lua_Number x = luaL_checknumber(L, 1);
|
||||
lua_Number res;
|
||||
if (lua_isnoneornil(L, 2))
|
||||
res = l_mathop(log)(x);
|
||||
res = l_tg(log)(x);
|
||||
else {
|
||||
lua_Number base = luaL_checknumber(L, 2);
|
||||
if (base == (lua_Number)10.0) res = l_mathop(log10)(x);
|
||||
else res = l_mathop(log)(x)/l_mathop(log)(base);
|
||||
if (base == 10.0) res = l_tg(log10)(x);
|
||||
else res = l_tg(log)(x)/l_tg(log)(base);
|
||||
}
|
||||
lua_pushnumber(L, res);
|
||||
return 1;
|
||||
@@ -131,13 +136,13 @@ static int math_log (lua_State *L) {
|
||||
|
||||
#if defined(LUA_COMPAT_LOG10)
|
||||
static int math_log10 (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(log10)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int math_exp (lua_State *L) {
|
||||
lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1)));
|
||||
lua_pushnumber(L, l_tg(exp)(luaL_checknumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -153,15 +158,14 @@ static int math_rad (lua_State *L) {
|
||||
|
||||
static int math_frexp (lua_State *L) {
|
||||
int e;
|
||||
lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));
|
||||
lua_pushnumber(L, l_tg(frexp)(luaL_checknumber(L, 1), &e));
|
||||
lua_pushinteger(L, e);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int math_ldexp (lua_State *L) {
|
||||
lua_Number x = luaL_checknumber(L, 1);
|
||||
int ep = luaL_checkint(L, 2);
|
||||
lua_pushnumber(L, l_mathop(ldexp)(x, ep));
|
||||
lua_pushnumber(L, l_tg(ldexp)(luaL_checknumber(L, 1),
|
||||
luaL_checkint(L, 2)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -206,15 +210,15 @@ static int math_random (lua_State *L) {
|
||||
}
|
||||
case 1: { /* only upper limit */
|
||||
lua_Number u = luaL_checknumber(L, 1);
|
||||
luaL_argcheck(L, (lua_Number)1.0 <= u, 1, "interval is empty");
|
||||
lua_pushnumber(L, l_mathop(floor)(r*u) + (lua_Number)(1.0)); /* [1, u] */
|
||||
luaL_argcheck(L, 1.0 <= u, 1, "interval is empty");
|
||||
lua_pushnumber(L, l_tg(floor)(r*u) + 1.0); /* int in [1, u] */
|
||||
break;
|
||||
}
|
||||
case 2: { /* lower and upper limits */
|
||||
lua_Number l = luaL_checknumber(L, 1);
|
||||
lua_Number u = luaL_checknumber(L, 2);
|
||||
luaL_argcheck(L, l <= u, 2, "interval is empty");
|
||||
lua_pushnumber(L, l_mathop(floor)(r*(u-l+1)) + l); /* [l, u] */
|
||||
lua_pushnumber(L, l_tg(floor)(r*(u-l+1)) + l); /* int in [l, u] */
|
||||
break;
|
||||
}
|
||||
default: return luaL_error(L, "wrong number of arguments");
|
||||
|
||||
18
lmem.c
18
lmem.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lmem.c,v 1.84 2012/05/23 15:41:53 roberto Exp $
|
||||
** $Id: lmem.c,v 1.82 2011/09/20 19:25:23 roberto Exp roberto $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -94,6 +94,22 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
|
||||
}
|
||||
lua_assert((nsize == 0) == (newblock == NULL));
|
||||
g->GCdebt = (g->GCdebt + nsize) - realosize;
|
||||
#if defined(TRACEMEM)
|
||||
{ /* auxiliary patch to monitor garbage collection.
|
||||
** To plot, gnuplot with following command:
|
||||
** plot TRACEMEM using 1:2 with lines, TRACEMEM using 1:3 with lines
|
||||
*/
|
||||
static unsigned long total = 0; /* our "time" */
|
||||
static FILE *f = NULL; /* output file */
|
||||
total++; /* "time" always grows */
|
||||
if ((total % 200) == 0) {
|
||||
if (f == NULL) f = fopen(TRACEMEM, "w");
|
||||
fprintf(f, "%lu %u %d %d\n", total,
|
||||
gettotalbytes(g), g->GCdebt, g->gcstate * 10000);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return newblock;
|
||||
}
|
||||
|
||||
|
||||
15
lmem.h
15
lmem.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lmem.h,v 1.40 2013/02/20 14:08:21 roberto Exp $
|
||||
** $Id: lmem.h,v 1.37 2011/11/30 12:42:49 roberto Exp roberto $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -14,17 +14,10 @@
|
||||
#include "lua.h"
|
||||
|
||||
|
||||
/*
|
||||
** This macro avoids the runtime division MAX_SIZET/(e), as 'e' is
|
||||
** always constant.
|
||||
** The macro is somewhat complex to avoid warnings:
|
||||
** +1 avoids warnings of "comparison has constant result";
|
||||
** cast to 'void' avoids warnings of "value unused".
|
||||
*/
|
||||
#define luaM_reallocv(L,b,on,n,e) \
|
||||
(cast(void, \
|
||||
(cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \
|
||||
luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
|
||||
((cast(size_t, (n)+1) > MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
|
||||
(luaM_toobig(L), (void *)0) : \
|
||||
luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
|
||||
|
||||
#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
|
||||
#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
|
||||
|
||||
97
loadlib.c
97
loadlib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: loadlib.c,v 1.111 2012/05/30 12:33:44 roberto Exp $
|
||||
** $Id: loadlib.c,v 1.107 2011/11/30 12:58:57 roberto Exp roberto $
|
||||
** Dynamic library loader for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
**
|
||||
@@ -92,9 +92,9 @@
|
||||
#define LUA_OFSEP "_"
|
||||
|
||||
|
||||
/* table (in the registry) that keeps handles for all loaded C libraries */
|
||||
#define CLIBS "_CLIBS"
|
||||
#define LIBPREFIX "LOADLIB: "
|
||||
|
||||
#define POF LUA_POF
|
||||
#define LIB_FAIL "open"
|
||||
|
||||
|
||||
@@ -248,54 +248,48 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
|
||||
#endif
|
||||
|
||||
|
||||
static void *ll_checkclib (lua_State *L, const char *path) {
|
||||
void *plib;
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
|
||||
lua_getfield(L, -1, path);
|
||||
plib = lua_touserdata(L, -1); /* plib = CLIBS[path] */
|
||||
lua_pop(L, 2); /* pop CLIBS table and 'plib' */
|
||||
|
||||
static void **ll_register (lua_State *L, const char *path) {
|
||||
void **plib;
|
||||
lua_pushfstring(L, "%s%s", LIBPREFIX, path);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */
|
||||
if (!lua_isnil(L, -1)) /* is there an entry? */
|
||||
plib = (void **)lua_touserdata(L, -1);
|
||||
else { /* no entry yet; create one */
|
||||
lua_pop(L, 1); /* remove result from gettable */
|
||||
plib = (void **)lua_newuserdata(L, sizeof(const void *));
|
||||
*plib = NULL;
|
||||
luaL_setmetatable(L, "_LOADLIB");
|
||||
lua_pushfstring(L, "%s%s", LIBPREFIX, path);
|
||||
lua_pushvalue(L, -2);
|
||||
lua_settable(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
return plib;
|
||||
}
|
||||
|
||||
|
||||
static void ll_addtoclib (lua_State *L, const char *path, void *plib) {
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
|
||||
lua_pushlightuserdata(L, plib);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -3, path); /* CLIBS[path] = plib */
|
||||
lua_rawseti(L, -2, luaL_len(L, -2) + 1); /* CLIBS[#CLIBS + 1] = plib */
|
||||
lua_pop(L, 1); /* pop CLIBS table */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** __gc tag method for CLIBS table: calls 'll_unloadlib' for all lib
|
||||
** handles in list CLIBS
|
||||
** __gc tag method: calls library's `ll_unloadlib' function with the lib
|
||||
** handle
|
||||
*/
|
||||
static int gctm (lua_State *L) {
|
||||
int n = luaL_len(L, 1);
|
||||
for (; n >= 1; n--) { /* for each handle, in reverse order */
|
||||
lua_rawgeti(L, 1, n); /* get handle CLIBS[n] */
|
||||
ll_unloadlib(lua_touserdata(L, -1));
|
||||
lua_pop(L, 1); /* pop handle */
|
||||
}
|
||||
void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
|
||||
if (*lib) ll_unloadlib(*lib);
|
||||
*lib = NULL; /* mark library as closed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
|
||||
void *reg = ll_checkclib(L, path); /* check loaded C libraries */
|
||||
if (reg == NULL) { /* must load library? */
|
||||
reg = ll_load(L, path, *sym == '*');
|
||||
if (reg == NULL) return ERRLIB; /* unable to load library */
|
||||
ll_addtoclib(L, path, reg);
|
||||
}
|
||||
void **reg = ll_register(L, path);
|
||||
if (*reg == NULL) *reg = ll_load(L, path, *sym == '*');
|
||||
if (*reg == NULL) return ERRLIB; /* unable to load library */
|
||||
if (*sym == '*') { /* loading only library (no function)? */
|
||||
lua_pushboolean(L, 1); /* return 'true' */
|
||||
return 0; /* no errors */
|
||||
}
|
||||
else {
|
||||
lua_CFunction f = ll_sym(L, reg, sym);
|
||||
lua_CFunction f = ll_sym(L, *reg, sym);
|
||||
if (f == NULL)
|
||||
return ERRFUNC; /* unable to find function */
|
||||
lua_pushcfunction(L, f); /* else create new function */
|
||||
@@ -424,12 +418,12 @@ static int loadfunc (lua_State *L, const char *filename, const char *modname) {
|
||||
if (mark) {
|
||||
int stat;
|
||||
funcname = lua_pushlstring(L, modname, mark - modname);
|
||||
funcname = lua_pushfstring(L, LUA_POF"%s", funcname);
|
||||
funcname = lua_pushfstring(L, POF"%s", funcname);
|
||||
stat = ll_loadfunc(L, filename, funcname);
|
||||
if (stat != ERRFUNC) return stat;
|
||||
modname = mark + 1; /* else go ahead and try old-style name */
|
||||
}
|
||||
funcname = lua_pushfstring(L, LUA_POF"%s", modname);
|
||||
funcname = lua_pushfstring(L, POF"%s", modname);
|
||||
return ll_loadfunc(L, filename, funcname);
|
||||
}
|
||||
|
||||
@@ -482,9 +476,9 @@ static void findloader (lua_State *L, const char *name) {
|
||||
lua_getfield(L, lua_upvalueindex(1), "searchers"); /* will be at index 3 */
|
||||
if (!lua_istable(L, 3))
|
||||
luaL_error(L, LUA_QL("package.searchers") " must be a table");
|
||||
/* iterate over available searchers to find a loader */
|
||||
/* iterate over available seachers to find a loader */
|
||||
for (i = 1; ; i++) {
|
||||
lua_rawgeti(L, 3, i); /* get a searcher */
|
||||
lua_rawgeti(L, 3, i); /* get a seacher */
|
||||
if (lua_isnil(L, -1)) { /* no more searchers? */
|
||||
lua_pop(L, 1); /* remove nil */
|
||||
luaL_pushresult(&msg); /* create error message */
|
||||
@@ -672,10 +666,18 @@ static const luaL_Reg ll_funcs[] = {
|
||||
};
|
||||
|
||||
|
||||
static void createsearcherstable (lua_State *L) {
|
||||
static const lua_CFunction searchers[] =
|
||||
{searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};
|
||||
static const lua_CFunction searchers[] =
|
||||
{searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};
|
||||
|
||||
|
||||
LUAMOD_API int luaopen_package (lua_State *L) {
|
||||
int i;
|
||||
/* create new type _LOADLIB */
|
||||
luaL_newmetatable(L, "_LOADLIB");
|
||||
lua_pushcfunction(L, gctm);
|
||||
lua_setfield(L, -2, "__gc");
|
||||
/* create `package' table */
|
||||
luaL_newlib(L, pk_funcs);
|
||||
/* create 'searchers' table */
|
||||
lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);
|
||||
/* fill it with pre-defined searchers */
|
||||
@@ -684,19 +686,6 @@ static void createsearcherstable (lua_State *L) {
|
||||
lua_pushcclosure(L, searchers[i], 1);
|
||||
lua_rawseti(L, -2, i+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LUAMOD_API int luaopen_package (lua_State *L) {
|
||||
/* create table CLIBS to keep track of loaded C libraries */
|
||||
luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
|
||||
lua_createtable(L, 0, 1); /* metatable for CLIBS */
|
||||
lua_pushcfunction(L, gctm);
|
||||
lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */
|
||||
lua_setmetatable(L, -2);
|
||||
/* create `package' table */
|
||||
luaL_newlib(L, pk_funcs);
|
||||
createsearcherstable(L);
|
||||
#if defined(LUA_COMPAT_LOADERS)
|
||||
lua_pushvalue(L, -1); /* make a copy of 'searchers' table */
|
||||
lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */
|
||||
|
||||
20
lobject.c
20
lobject.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lobject.c,v 2.58 2013/02/20 14:08:56 roberto Exp $
|
||||
** $Id: lobject.c,v 2.54 2011/11/30 12:44:26 roberto Exp roberto $
|
||||
** Some generic functions over Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -104,7 +104,7 @@ static int isneg (const char **s) {
|
||||
|
||||
static lua_Number readhexa (const char **s, lua_Number r, int *count) {
|
||||
for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */
|
||||
r = (r * cast_num(16.0)) + cast_num(luaO_hexavalue(cast_uchar(**s)));
|
||||
r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(**s)));
|
||||
(*count)++;
|
||||
}
|
||||
return r;
|
||||
@@ -149,7 +149,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
|
||||
*endptr = cast(char *, s); /* valid up to here */
|
||||
ret:
|
||||
if (neg) r = -r;
|
||||
return l_mathop(ldexp)(r, e);
|
||||
return ldexp(r, e);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -171,7 +171,8 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) {
|
||||
|
||||
|
||||
static void pushstr (lua_State *L, const char *str, size_t l) {
|
||||
setsvalue2s(L, L->top++, luaS_newlstr(L, str, l));
|
||||
setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
|
||||
incr_top(L);
|
||||
}
|
||||
|
||||
|
||||
@@ -181,8 +182,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
||||
for (;;) {
|
||||
const char *e = strchr(fmt, '%');
|
||||
if (e == NULL) break;
|
||||
luaD_checkstack(L, 2); /* fmt + item */
|
||||
pushstr(L, fmt, e - fmt);
|
||||
setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
|
||||
incr_top(L);
|
||||
switch (*(e+1)) {
|
||||
case 's': {
|
||||
const char *s = va_arg(argp, char *);
|
||||
@@ -197,11 +198,13 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
setnvalue(L->top++, cast_num(va_arg(argp, int)));
|
||||
setnvalue(L->top, cast_num(va_arg(argp, int)));
|
||||
incr_top(L);
|
||||
break;
|
||||
}
|
||||
case 'f': {
|
||||
setnvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
|
||||
setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
|
||||
incr_top(L);
|
||||
break;
|
||||
}
|
||||
case 'p': {
|
||||
@@ -223,7 +226,6 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
||||
n += 2;
|
||||
fmt = e+2;
|
||||
}
|
||||
luaD_checkstack(L, 1);
|
||||
pushstr(L, fmt, strlen(fmt));
|
||||
if (n > 0) luaV_concat(L, n + 1);
|
||||
return svalue(L->top - 1);
|
||||
|
||||
80
lobject.h
80
lobject.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lobject.h,v 2.71.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** $Id: lobject.h,v 2.63 2011/10/17 14:46:13 roberto Exp roberto $
|
||||
** Type definitions for Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -36,9 +36,6 @@
|
||||
** bit 6: whether value is collectable
|
||||
*/
|
||||
|
||||
#define VARBITS (3 << 4)
|
||||
|
||||
|
||||
/*
|
||||
** LUA_TFUNCTION variants:
|
||||
** 0 - Lua function
|
||||
@@ -52,11 +49,6 @@
|
||||
#define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */
|
||||
|
||||
|
||||
/* Variant tags for strings */
|
||||
#define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */
|
||||
#define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */
|
||||
|
||||
|
||||
/* Bit mark for collectable types */
|
||||
#define BIT_ISCOLLECTABLE (1 << 6)
|
||||
|
||||
@@ -117,28 +109,23 @@ typedef struct lua_TValue TValue;
|
||||
/* raw type tag of a TValue */
|
||||
#define rttype(o) ((o)->tt_)
|
||||
|
||||
/* tag with no variants (bits 0-3) */
|
||||
#define novariant(x) ((x) & 0x0F)
|
||||
|
||||
/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
|
||||
#define ttype(o) (rttype(o) & 0x3F)
|
||||
|
||||
|
||||
/* type tag of a TValue with no variants (bits 0-3) */
|
||||
#define ttypenv(o) (novariant(rttype(o)))
|
||||
#define ttypenv(o) (rttype(o) & 0x0F)
|
||||
|
||||
|
||||
/* Macros to test type */
|
||||
#define checktag(o,t) (rttype(o) == (t))
|
||||
#define checktype(o,t) (ttypenv(o) == (t))
|
||||
#define ttisnumber(o) checktag((o), LUA_TNUMBER)
|
||||
#define ttisnil(o) checktag((o), LUA_TNIL)
|
||||
#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
|
||||
#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
|
||||
#define ttisstring(o) checktype((o), LUA_TSTRING)
|
||||
#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
|
||||
#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
|
||||
#define ttisstring(o) checktag((o), ctb(LUA_TSTRING))
|
||||
#define ttistable(o) checktag((o), ctb(LUA_TTABLE))
|
||||
#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
|
||||
#define ttisfunction(o) (ttypenv(o) == LUA_TFUNCTION)
|
||||
#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
|
||||
#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
|
||||
#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
|
||||
@@ -174,7 +161,7 @@ typedef struct lua_TValue TValue;
|
||||
|
||||
|
||||
/* Macros for internal tests */
|
||||
#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt)
|
||||
#define righttt(obj) (ttypenv(obj) == gcvalue(obj)->gch.tt)
|
||||
|
||||
#define checkliveness(g,obj) \
|
||||
lua_longassert(!iscollectable(obj) || \
|
||||
@@ -187,6 +174,8 @@ typedef struct lua_TValue TValue;
|
||||
#define setnvalue(obj,x) \
|
||||
{ TValue *io=(obj); num_(io)=(x); settt_(io, LUA_TNUMBER); }
|
||||
|
||||
#define changenvalue(o,x) check_exp(ttisnumber(o), num_(o)=(x))
|
||||
|
||||
#define setnilvalue(obj) settt_(obj, LUA_TNIL)
|
||||
|
||||
#define setfvalue(obj,x) \
|
||||
@@ -204,8 +193,7 @@ typedef struct lua_TValue TValue;
|
||||
|
||||
#define setsvalue(L,obj,x) \
|
||||
{ TValue *io=(obj); \
|
||||
TString *x_ = (x); \
|
||||
val_(io).gc=cast(GCObject *, x_); settt_(io, ctb(x_->tsv.tt)); \
|
||||
val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TSTRING)); \
|
||||
checkliveness(G(L),io); }
|
||||
|
||||
#define setuvalue(L,obj,x) \
|
||||
@@ -233,6 +221,11 @@ typedef struct lua_TValue TValue;
|
||||
val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \
|
||||
checkliveness(G(L),io); }
|
||||
|
||||
#define setptvalue(L,obj,x) \
|
||||
{ TValue *io=(obj); \
|
||||
val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TPROTO)); \
|
||||
checkliveness(G(L),io); }
|
||||
|
||||
#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
|
||||
|
||||
|
||||
@@ -263,8 +256,6 @@ typedef struct lua_TValue TValue;
|
||||
#define setsvalue2n setsvalue
|
||||
|
||||
|
||||
/* check whether a number is valid (useful only for NaN trick) */
|
||||
#define luai_checknum(L,o,c) { /* empty */ }
|
||||
|
||||
|
||||
/*
|
||||
@@ -272,7 +263,10 @@ typedef struct lua_TValue TValue;
|
||||
** NaN Trick
|
||||
** =======================================================
|
||||
*/
|
||||
#if defined(LUA_NANTRICK)
|
||||
|
||||
#if defined(LUA_NANTRICK) \
|
||||
|| defined(LUA_NANTRICK_LE) \
|
||||
|| defined(LUA_NANTRICK_BE)
|
||||
|
||||
/*
|
||||
** numbers are represented in the 'd_' field. All other values have the
|
||||
@@ -280,23 +274,15 @@ typedef struct lua_TValue TValue;
|
||||
** a "signaled NaN", which is never generated by regular operations by
|
||||
** the CPU (nor by 'strtod')
|
||||
*/
|
||||
|
||||
/* allows for external implementation for part of the trick */
|
||||
#if !defined(NNMARK) /* { */
|
||||
|
||||
|
||||
#if !defined(LUA_IEEEENDIAN)
|
||||
#error option 'LUA_NANTRICK' needs 'LUA_IEEEENDIAN'
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(NNMARK)
|
||||
#define NNMARK 0x7FF7A500
|
||||
#define NNMASK 0x7FFFFF00
|
||||
#endif
|
||||
|
||||
#undef TValuefields
|
||||
#undef NILCONSTANT
|
||||
|
||||
#if (LUA_IEEEENDIAN == 0) /* { */
|
||||
#if defined(LUA_NANTRICK_LE)
|
||||
|
||||
/* little endian */
|
||||
#define TValuefields \
|
||||
@@ -307,7 +293,7 @@ typedef struct lua_TValue TValue;
|
||||
#define d_(o) ((o)->u.d__)
|
||||
#define tt_(o) ((o)->u.i.tt__)
|
||||
|
||||
#else /* }{ */
|
||||
#elif defined(LUA_NANTRICK_BE)
|
||||
|
||||
/* big endian */
|
||||
#define TValuefields \
|
||||
@@ -318,9 +304,10 @@ typedef struct lua_TValue TValue;
|
||||
#define d_(o) ((o)->u.d__)
|
||||
#define tt_(o) ((o)->u.i.tt__)
|
||||
|
||||
#endif /* } */
|
||||
#elif !defined(TValuefields)
|
||||
#error option 'LUA_NANTRICK' needs declaration for 'TValuefields'
|
||||
|
||||
#endif /* } */
|
||||
#endif
|
||||
|
||||
|
||||
/* correspondence with standard representation */
|
||||
@@ -361,18 +348,21 @@ typedef struct lua_TValue TValue;
|
||||
*/
|
||||
|
||||
#undef checktag
|
||||
#undef checktype
|
||||
#define checktag(o,t) (tt_(o) == tag2tt(t))
|
||||
#define checktype(o,t) (ctb(tt_(o) | VARBITS) == ctb(tag2tt(t) | VARBITS))
|
||||
|
||||
#undef ttisequal
|
||||
#define ttisequal(o1,o2) \
|
||||
(ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2)))
|
||||
|
||||
|
||||
#undef luai_checknum
|
||||
|
||||
#define luai_checknum(L,o,c) { if (!ttisnumber(o)) c; }
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#define luai_checknum(L,o,c) { /* empty */ }
|
||||
|
||||
#endif
|
||||
/* }====================================================== */
|
||||
|
||||
@@ -411,7 +401,7 @@ typedef union TString {
|
||||
L_Umaxalign dummy; /* ensures maximum alignment for strings */
|
||||
struct {
|
||||
CommonHeader;
|
||||
lu_byte extra; /* reserved words for short strings; "has hash" for longs */
|
||||
lu_byte reserved;
|
||||
unsigned int hash;
|
||||
size_t len; /* number of characters in string */
|
||||
} tsv;
|
||||
@@ -511,7 +501,7 @@ typedef struct UpVal {
|
||||
*/
|
||||
|
||||
#define ClosureHeader \
|
||||
CommonHeader; lu_byte nupvalues; GCObject *gclist
|
||||
CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist
|
||||
|
||||
typedef struct CClosure {
|
||||
ClosureHeader;
|
||||
@@ -561,12 +551,12 @@ typedef struct Table {
|
||||
CommonHeader;
|
||||
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
|
||||
lu_byte lsizenode; /* log2 of size of `node' array */
|
||||
int sizearray; /* size of `array' array */
|
||||
struct Table *metatable;
|
||||
TValue *array; /* array part */
|
||||
Node *node;
|
||||
Node *lastfree; /* any free position is before this position */
|
||||
struct Table *metatable;
|
||||
GCObject *gclist;
|
||||
int sizearray; /* size of `array' array */
|
||||
} Table;
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.c,v 1.49 2012/05/14 13:34:18 roberto Exp $
|
||||
** Opcodes for Lua virtual machine
|
||||
** $Id: lopcodes.c,v 1.47 2011/04/12 17:27:35 roberto Exp roberto $
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.h,v 1.142.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** $Id: lopcodes.h,v 1.141 2011/04/19 16:22:13 roberto Exp roberto $
|
||||
** Opcodes for Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -196,7 +196,7 @@ OP_LEN,/* A B R(A) := length of R(B) */
|
||||
|
||||
OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
|
||||
|
||||
OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A - 1) */
|
||||
OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */
|
||||
OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
|
||||
OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
|
||||
OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
|
||||
|
||||
19
loslib.c
19
loslib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: loslib.c,v 1.40 2012/10/19 15:54:02 roberto Exp $
|
||||
** $Id: loslib.c,v 1.37 2011/11/29 17:15:42 roberto Exp roberto $
|
||||
** Standard Operating System library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -26,12 +26,11 @@
|
||||
#if !defined(LUA_STRFTIMEOPTIONS)
|
||||
|
||||
#if !defined(LUA_USE_POSIX)
|
||||
#define LUA_STRFTIMEOPTIONS { "aAbBcdHIjmMpSUwWxXyYz%", "" }
|
||||
#define LUA_STRFTIMEOPTIONS { "aAbBcdHIjmMpSUwWxXyYz%", "" }
|
||||
#else
|
||||
#define LUA_STRFTIMEOPTIONS \
|
||||
{ "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%", "" \
|
||||
"", "E", "cCxXyY", \
|
||||
"O", "deHImMSuUVwWy" }
|
||||
#define LUA_STRFTIMEOPTIONS { "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%", "", \
|
||||
"E", "cCxXyY", \
|
||||
"O", "deHImMSuUVwWy" }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -44,7 +43,7 @@
|
||||
*/
|
||||
#if defined(LUA_USE_MKSTEMP)
|
||||
#include <unistd.h>
|
||||
#define LUA_TMPNAMBUFSIZE 32
|
||||
#define LUA_TMPNAMBUFSIZE 32
|
||||
#define lua_tmpnam(b,e) { \
|
||||
strcpy(b, "/tmp/lua_XXXXXX"); \
|
||||
e = mkstemp(b); \
|
||||
@@ -53,8 +52,8 @@
|
||||
|
||||
#elif !defined(lua_tmpnam)
|
||||
|
||||
#define LUA_TMPNAMBUFSIZE L_tmpnam
|
||||
#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
|
||||
#define LUA_TMPNAMBUFSIZE L_tmpnam
|
||||
#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -98,7 +97,7 @@ static int os_remove (lua_State *L) {
|
||||
static int os_rename (lua_State *L) {
|
||||
const char *fromname = luaL_checkstring(L, 1);
|
||||
const char *toname = luaL_checkstring(L, 2);
|
||||
return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);
|
||||
return luaL_fileresult(L, rename(fromname, toname) == 0, fromname);
|
||||
}
|
||||
|
||||
|
||||
|
||||
160
lparser.c
160
lparser.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lparser.c,v 2.130 2013/02/06 13:37:39 roberto Exp $
|
||||
** $Id: lparser.c,v 2.123 2011/11/30 12:43:51 roberto Exp roberto $
|
||||
** Lua Parser
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -222,7 +222,7 @@ static int searchupvalue (FuncState *fs, TString *name) {
|
||||
int i;
|
||||
Upvaldesc *up = fs->f->upvalues;
|
||||
for (i = 0; i < fs->nups; i++) {
|
||||
if (luaS_eqstr(up[i].name, name)) return i;
|
||||
if (eqstr(up[i].name, name)) return i;
|
||||
}
|
||||
return -1; /* not found */
|
||||
}
|
||||
@@ -245,8 +245,8 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
|
||||
|
||||
static int searchvar (FuncState *fs, TString *n) {
|
||||
int i;
|
||||
for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {
|
||||
if (luaS_eqstr(n, getlocvar(fs, i)->varname))
|
||||
for (i=fs->nactvar-1; i >= 0; i--) {
|
||||
if (eqstr(n, getlocvar(fs, i)->varname))
|
||||
return i;
|
||||
}
|
||||
return -1; /* not found */
|
||||
@@ -342,7 +342,7 @@ static void closegoto (LexState *ls, int g, Labeldesc *label) {
|
||||
FuncState *fs = ls->fs;
|
||||
Labellist *gl = &ls->dyd->gt;
|
||||
Labeldesc *gt = &gl->arr[g];
|
||||
lua_assert(luaS_eqstr(gt->name, label->name));
|
||||
lua_assert(eqstr(gt->name, label->name));
|
||||
if (gt->nactvar < label->nactvar) {
|
||||
TString *vname = getlocvar(fs, gt->nactvar)->varname;
|
||||
const char *msg = luaO_pushfstring(ls->L,
|
||||
@@ -369,7 +369,7 @@ static int findlabel (LexState *ls, int g) {
|
||||
/* check labels in current block for a match */
|
||||
for (i = bl->firstlabel; i < dyd->label.n; i++) {
|
||||
Labeldesc *lb = &dyd->label.arr[i];
|
||||
if (luaS_eqstr(lb->name, gt->name)) { /* correct label? */
|
||||
if (eqstr(lb->name, gt->name)) { /* correct label? */
|
||||
if (gt->nactvar > lb->nactvar &&
|
||||
(bl->upval || dyd->label.n > bl->firstlabel))
|
||||
luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
|
||||
@@ -403,7 +403,7 @@ static void findgotos (LexState *ls, Labeldesc *lb) {
|
||||
Labellist *gl = &ls->dyd->gt;
|
||||
int i = ls->fs->bl->firstgoto;
|
||||
while (i < gl->n) {
|
||||
if (luaS_eqstr(gl->arr[i].name, lb->name))
|
||||
if (eqstr(gl->arr[i].name, lb->name))
|
||||
closegoto(ls, i, lb);
|
||||
else
|
||||
i++;
|
||||
@@ -461,7 +461,7 @@ static void breaklabel (LexState *ls) {
|
||||
** message when label name is a reserved word (which can only be 'break')
|
||||
*/
|
||||
static l_noret undefgoto (LexState *ls, Labeldesc *gt) {
|
||||
const char *msg = isreserved(gt->name)
|
||||
const char *msg = (gt->name->tsv.reserved > 0)
|
||||
? "<%s> at line %d not inside a loop"
|
||||
: "no visible label " LUA_QS " for <goto> at line %d";
|
||||
msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
|
||||
@@ -493,34 +493,22 @@ static void leaveblock (FuncState *fs) {
|
||||
|
||||
|
||||
/*
|
||||
** adds a new prototype into list of prototypes
|
||||
** adds prototype being created into its parent list of prototypes
|
||||
** and codes instruction to create new closure
|
||||
*/
|
||||
static Proto *addprototype (LexState *ls) {
|
||||
Proto *clp;
|
||||
lua_State *L = ls->L;
|
||||
FuncState *fs = ls->fs;
|
||||
Proto *f = fs->f; /* prototype of current function */
|
||||
static void codeclosure (LexState *ls, Proto *clp, expdesc *v) {
|
||||
FuncState *fs = ls->fs->prev;
|
||||
Proto *f = fs->f; /* prototype of function creating new closure */
|
||||
if (fs->np >= f->sizep) {
|
||||
int oldsize = f->sizep;
|
||||
luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions");
|
||||
luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
|
||||
MAXARG_Bx, "functions");
|
||||
while (oldsize < f->sizep) f->p[oldsize++] = NULL;
|
||||
}
|
||||
f->p[fs->np++] = clp = luaF_newproto(L);
|
||||
luaC_objbarrier(L, f, clp);
|
||||
return clp;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** codes instruction to create new closure in parent function.
|
||||
** The OP_CLOSURE instruction must use the last available register,
|
||||
** so that, if it invokes the GC, the GC knows which registers
|
||||
** are in use at that time.
|
||||
*/
|
||||
static void codeclosure (LexState *ls, expdesc *v) {
|
||||
FuncState *fs = ls->fs->prev;
|
||||
init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));
|
||||
luaK_exp2nextreg(fs, v); /* fix it at the last register */
|
||||
f->p[fs->np++] = clp;
|
||||
luaC_objbarrier(ls->L, f, clp);
|
||||
init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
|
||||
luaK_exp2nextreg(fs, v); /* fix it at stack top (for GC) */
|
||||
}
|
||||
|
||||
|
||||
@@ -541,9 +529,13 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
|
||||
fs->nactvar = 0;
|
||||
fs->firstlocal = ls->dyd->actvar.n;
|
||||
fs->bl = NULL;
|
||||
f = fs->f;
|
||||
f = luaF_newproto(L);
|
||||
fs->f = f;
|
||||
f->source = ls->source;
|
||||
f->maxstacksize = 2; /* registers 0/1 are always valid */
|
||||
/* anchor prototype (to avoid being collected) */
|
||||
setptvalue2s(L, L->top, f);
|
||||
incr_top(L);
|
||||
fs->h = luaH_new(L);
|
||||
/* anchor table of constants (to avoid being collected) */
|
||||
sethvalue2s(L, L->top, fs->h);
|
||||
@@ -576,6 +568,20 @@ static void close_func (LexState *ls) {
|
||||
anchor_token(ls);
|
||||
L->top--; /* pop table of constants */
|
||||
luaC_checkGC(L);
|
||||
L->top--; /* pop prototype (after possible collection) */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** opens the main function, which is a regular vararg function with an
|
||||
** upvalue named LUA_ENV
|
||||
*/
|
||||
static void open_mainfunc (LexState *ls, FuncState *fs, BlockCnt *bl) {
|
||||
expdesc v;
|
||||
open_func(ls, fs, bl);
|
||||
fs->f->is_vararg = 1; /* main function is always vararg */
|
||||
init_exp(&v, VLOCAL, 0);
|
||||
newupvalue(fs, ls->envn, &v); /* create environment upvalue */
|
||||
}
|
||||
|
||||
|
||||
@@ -789,9 +795,8 @@ static void body (LexState *ls, expdesc *e, int ismethod, int line) {
|
||||
/* body -> `(' parlist `)' block END */
|
||||
FuncState new_fs;
|
||||
BlockCnt bl;
|
||||
new_fs.f = addprototype(ls);
|
||||
new_fs.f->linedefined = line;
|
||||
open_func(ls, &new_fs, &bl);
|
||||
new_fs.f->linedefined = line;
|
||||
checknext(ls, '(');
|
||||
if (ismethod) {
|
||||
new_localvarliteral(ls, "self"); /* create 'self' parameter */
|
||||
@@ -802,7 +807,7 @@ static void body (LexState *ls, expdesc *e, int ismethod, int line) {
|
||||
statlist(ls);
|
||||
new_fs.f->lastlinedefined = ls->linenumber;
|
||||
check_match(ls, TK_END, TK_FUNCTION, line);
|
||||
codeclosure(ls, e);
|
||||
codeclosure(ls, new_fs.f, e);
|
||||
close_func(ls);
|
||||
}
|
||||
|
||||
@@ -874,8 +879,8 @@ static void funcargs (LexState *ls, expdesc *f, int line) {
|
||||
*/
|
||||
|
||||
|
||||
static void primaryexp (LexState *ls, expdesc *v) {
|
||||
/* primaryexp -> NAME | '(' expr ')' */
|
||||
static void prefixexp (LexState *ls, expdesc *v) {
|
||||
/* prefixexp -> NAME | '(' expr ')' */
|
||||
switch (ls->t.token) {
|
||||
case '(': {
|
||||
int line = ls->linenumber;
|
||||
@@ -896,12 +901,12 @@ static void primaryexp (LexState *ls, expdesc *v) {
|
||||
}
|
||||
|
||||
|
||||
static void suffixedexp (LexState *ls, expdesc *v) {
|
||||
/* suffixedexp ->
|
||||
primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
|
||||
static void primaryexp (LexState *ls, expdesc *v) {
|
||||
/* primaryexp ->
|
||||
prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
|
||||
FuncState *fs = ls->fs;
|
||||
int line = ls->linenumber;
|
||||
primaryexp(ls, v);
|
||||
prefixexp(ls, v);
|
||||
for (;;) {
|
||||
switch (ls->t.token) {
|
||||
case '.': { /* fieldsel */
|
||||
@@ -936,7 +941,7 @@ static void suffixedexp (LexState *ls, expdesc *v) {
|
||||
|
||||
static void simpleexp (LexState *ls, expdesc *v) {
|
||||
/* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
|
||||
constructor | FUNCTION body | suffixedexp */
|
||||
constructor | FUNCTION body | primaryexp */
|
||||
switch (ls->t.token) {
|
||||
case TK_NUMBER: {
|
||||
init_exp(v, VKNUM, 0);
|
||||
@@ -976,7 +981,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
suffixedexp(ls, v);
|
||||
primaryexp(ls, v);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1136,10 +1141,10 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
|
||||
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
|
||||
expdesc e;
|
||||
check_condition(ls, vkisvar(lh->v.k), "syntax error");
|
||||
if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
|
||||
if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */
|
||||
struct LHS_assign nv;
|
||||
nv.prev = lh;
|
||||
suffixedexp(ls, &nv.v);
|
||||
primaryexp(ls, &nv.v);
|
||||
if (nv.v.k != VINDEXED)
|
||||
check_conflict(ls, lh, &nv.v);
|
||||
checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,
|
||||
@@ -1195,7 +1200,7 @@ static void gotostat (LexState *ls, int pc) {
|
||||
static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {
|
||||
int i;
|
||||
for (i = fs->bl->firstlabel; i < ll->n; i++) {
|
||||
if (luaS_eqstr(label, ll->arr[i].name)) {
|
||||
if (eqstr(label, ll->arr[i].name)) {
|
||||
const char *msg = luaO_pushfstring(fs->ls->L,
|
||||
"label " LUA_QS " already defined on line %d",
|
||||
getstr(label), ll->arr[i].line);
|
||||
@@ -1205,13 +1210,6 @@ static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {
|
||||
}
|
||||
|
||||
|
||||
/* skip no-op statements */
|
||||
static void skipnoopstat (LexState *ls) {
|
||||
while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
|
||||
statement(ls);
|
||||
}
|
||||
|
||||
|
||||
static void labelstat (LexState *ls, TString *label, int line) {
|
||||
/* label -> '::' NAME '::' */
|
||||
FuncState *fs = ls->fs;
|
||||
@@ -1221,7 +1219,9 @@ static void labelstat (LexState *ls, TString *label, int line) {
|
||||
checknext(ls, TK_DBCOLON); /* skip double colon */
|
||||
/* create new entry for this label */
|
||||
l = newlabelentry(ls, ll, label, line, fs->pc);
|
||||
skipnoopstat(ls); /* skip other no-op statements */
|
||||
/* skip other no-op statements */
|
||||
while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
|
||||
statement(ls);
|
||||
if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
|
||||
/* assume that locals are already out of scope */
|
||||
ll->arr[l].nactvar = fs->bl->nactvar;
|
||||
@@ -1384,7 +1384,6 @@ static void test_then_block (LexState *ls, int *escapelist) {
|
||||
luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
|
||||
enterblock(fs, &bl, 0); /* must enter block before 'goto' */
|
||||
gotostat(ls, v.t); /* handle goto/break */
|
||||
skipnoopstat(ls); /* skip other no-op statements */
|
||||
if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
|
||||
leaveblock(fs);
|
||||
return; /* and that is it */
|
||||
@@ -1481,15 +1480,13 @@ static void exprstat (LexState *ls) {
|
||||
/* stat -> func | assignment */
|
||||
FuncState *fs = ls->fs;
|
||||
struct LHS_assign v;
|
||||
suffixedexp(ls, &v.v);
|
||||
if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
|
||||
primaryexp(ls, &v.v);
|
||||
if (v.v.k == VCALL) /* stat -> func */
|
||||
SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
|
||||
else { /* stat -> assignment */
|
||||
v.prev = NULL;
|
||||
assignment(ls, &v, 1);
|
||||
}
|
||||
else { /* stat -> func */
|
||||
check_condition(ls, v.v.k == VCALL, "syntax error");
|
||||
SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1597,42 +1594,27 @@ static void statement (LexState *ls) {
|
||||
/* }====================================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** compiles the main function, which is a regular vararg function with an
|
||||
** upvalue named LUA_ENV
|
||||
*/
|
||||
static void mainfunc (LexState *ls, FuncState *fs) {
|
||||
BlockCnt bl;
|
||||
expdesc v;
|
||||
open_func(ls, fs, &bl);
|
||||
fs->f->is_vararg = 1; /* main function is always vararg */
|
||||
init_exp(&v, VLOCAL, 0); /* create and... */
|
||||
newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
|
||||
luaX_next(ls); /* read first token */
|
||||
statlist(ls); /* parse main body */
|
||||
check(ls, TK_EOS);
|
||||
close_func(ls);
|
||||
}
|
||||
|
||||
|
||||
Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
|
||||
Dyndata *dyd, const char *name, int firstchar) {
|
||||
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
|
||||
Dyndata *dyd, const char *name, int firstchar) {
|
||||
LexState lexstate;
|
||||
FuncState funcstate;
|
||||
Closure *cl = luaF_newLclosure(L, 1); /* create main closure */
|
||||
/* anchor closure (to avoid being collected) */
|
||||
setclLvalue(L, L->top, cl);
|
||||
BlockCnt bl;
|
||||
TString *tname = luaS_new(L, name);
|
||||
setsvalue2s(L, L->top, tname); /* push name to protect it */
|
||||
incr_top(L);
|
||||
funcstate.f = cl->l.p = luaF_newproto(L);
|
||||
funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
|
||||
lexstate.buff = buff;
|
||||
lexstate.dyd = dyd;
|
||||
dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;
|
||||
luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);
|
||||
mainfunc(&lexstate, &funcstate);
|
||||
luaX_setinput(L, &lexstate, z, tname, firstchar);
|
||||
open_mainfunc(&lexstate, &funcstate, &bl);
|
||||
luaX_next(&lexstate); /* read first token */
|
||||
statlist(&lexstate); /* main body */
|
||||
check(&lexstate, TK_EOS);
|
||||
close_func(&lexstate);
|
||||
L->top--; /* pop name */
|
||||
lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
|
||||
/* all scopes should be correctly finished */
|
||||
lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
|
||||
return cl; /* it's on the stack too */
|
||||
return funcstate.f;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lparser.h,v 1.70 2012/05/08 13:53:33 roberto Exp $
|
||||
** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 roberto Exp roberto $
|
||||
** Lua Parser
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -112,8 +112,8 @@ typedef struct FuncState {
|
||||
} FuncState;
|
||||
|
||||
|
||||
LUAI_FUNC Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
|
||||
Dyndata *dyd, const char *name, int firstchar);
|
||||
LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
|
||||
Dyndata *dyd, const char *name, int firstchar);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
51
lstate.c
51
lstate.c
@@ -1,12 +1,11 @@
|
||||
/*
|
||||
** $Id: lstate.c,v 2.99.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** $Id: lstate.c,v 2.91 2011/08/23 17:24:34 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#define lstate_c
|
||||
#define LUA_CORE
|
||||
@@ -39,18 +38,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define MEMERRMSG "not enough memory"
|
||||
|
||||
|
||||
/*
|
||||
** a macro to help the creation of a unique random seed when a state is
|
||||
** created; the seed is used to randomize hashes.
|
||||
*/
|
||||
#if !defined(luai_makeseed)
|
||||
#include <time.h>
|
||||
#define luai_makeseed() cast(unsigned int, time(NULL))
|
||||
#endif
|
||||
|
||||
#define MEMERRMSG "not enough memory"
|
||||
|
||||
|
||||
/*
|
||||
@@ -77,28 +65,6 @@ typedef struct LG {
|
||||
#define fromstate(L) (cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))
|
||||
|
||||
|
||||
/*
|
||||
** Compute an initial seed as random as possible. In ANSI, rely on
|
||||
** Address Space Layout Randomization (if present) to increase
|
||||
** randomness..
|
||||
*/
|
||||
#define addbuff(b,p,e) \
|
||||
{ size_t t = cast(size_t, e); \
|
||||
memcpy(buff + p, &t, sizeof(t)); p += sizeof(t); }
|
||||
|
||||
static unsigned int makeseed (lua_State *L) {
|
||||
char buff[4 * sizeof(size_t)];
|
||||
unsigned int h = luai_makeseed();
|
||||
int p = 0;
|
||||
addbuff(buff, p, L); /* heap variable */
|
||||
addbuff(buff, p, &h); /* local variable */
|
||||
addbuff(buff, p, luaO_nilobject); /* global variable */
|
||||
addbuff(buff, p, &lua_newstate); /* public function */
|
||||
lua_assert(p == sizeof(buff));
|
||||
return luaS_hash(buff, p, h);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** set GCdebt to a new value keeping the value (totalbytes + GCdebt)
|
||||
** invariant
|
||||
@@ -192,8 +158,6 @@ static void f_luaopen (lua_State *L, void *ud) {
|
||||
g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
|
||||
luaS_fix(g->memerrmsg); /* it should never be collected */
|
||||
g->gcrunning = 1; /* allow gc */
|
||||
g->version = lua_version(NULL);
|
||||
luai_userstateopen(L);
|
||||
}
|
||||
|
||||
|
||||
@@ -224,8 +188,6 @@ static void close_state (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
luaF_close(L, L->stack); /* close all upvalues for this thread */
|
||||
luaC_freeallobjects(L); /* collect all objects */
|
||||
if (g->version) /* closing a fully built state? */
|
||||
luai_userstateclose(L);
|
||||
luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
|
||||
luaZ_freebuffer(L, &g->buff);
|
||||
freestack(L);
|
||||
@@ -280,23 +242,21 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
||||
g->frealloc = f;
|
||||
g->ud = ud;
|
||||
g->mainthread = L;
|
||||
g->seed = makeseed(L);
|
||||
g->uvhead.u.l.prev = &g->uvhead;
|
||||
g->uvhead.u.l.next = &g->uvhead;
|
||||
g->gcrunning = 0; /* no GC while building state */
|
||||
g->GCestimate = 0;
|
||||
g->lastmajormem = 0;
|
||||
g->strt.size = 0;
|
||||
g->strt.nuse = 0;
|
||||
g->strt.hash = NULL;
|
||||
setnilvalue(&g->l_registry);
|
||||
luaZ_initbuffer(L, &g->buff);
|
||||
g->panic = NULL;
|
||||
g->version = NULL;
|
||||
g->version = lua_version(NULL);
|
||||
g->gcstate = GCSpause;
|
||||
g->allgc = NULL;
|
||||
g->finobj = NULL;
|
||||
g->tobefnz = NULL;
|
||||
g->sweepgc = g->sweepfin = NULL;
|
||||
g->gray = g->grayagain = NULL;
|
||||
g->weak = g->ephemeron = g->allweak = NULL;
|
||||
g->totalbytes = sizeof(LG);
|
||||
@@ -310,6 +270,8 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
||||
close_state(L);
|
||||
L = NULL;
|
||||
}
|
||||
else
|
||||
luai_userstateopen(L);
|
||||
return L;
|
||||
}
|
||||
|
||||
@@ -317,6 +279,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
||||
LUA_API void lua_close (lua_State *L) {
|
||||
L = G(L)->mainthread; /* only the main thread can be closed */
|
||||
lua_lock(L);
|
||||
luai_userstateclose(L);
|
||||
close_state(L);
|
||||
}
|
||||
|
||||
|
||||
22
lstate.h
22
lstate.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.h,v 2.82 2012/07/02 13:37:04 roberto Exp $
|
||||
** $Id: lstate.h,v 2.73 2011/08/23 17:24:34 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -72,7 +72,6 @@ typedef struct CallInfo {
|
||||
struct CallInfo *previous, *next; /* dynamic call link */
|
||||
short nresults; /* expected number of results from this function */
|
||||
lu_byte callstatus;
|
||||
ptrdiff_t extra;
|
||||
union {
|
||||
struct { /* only for Lua functions */
|
||||
StkId base; /* base for this function */
|
||||
@@ -82,6 +81,7 @@ typedef struct CallInfo {
|
||||
int ctx; /* context info. in case of yields */
|
||||
lua_CFunction k; /* continuation in case of yields */
|
||||
ptrdiff_t old_errfunc;
|
||||
ptrdiff_t extra;
|
||||
lu_byte old_allowhook;
|
||||
lu_byte status;
|
||||
} c;
|
||||
@@ -100,7 +100,6 @@ typedef struct CallInfo {
|
||||
#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
|
||||
#define CIST_STAT (1<<5) /* call has an error status (pcall) */
|
||||
#define CIST_TAIL (1<<6) /* call was tail called */
|
||||
#define CIST_HOOKYIELD (1<<7) /* last hook called yielded */
|
||||
|
||||
|
||||
#define isLua(ci) ((ci)->callstatus & CIST_LUA)
|
||||
@@ -114,11 +113,9 @@ typedef struct global_State {
|
||||
void *ud; /* auxiliary data to `frealloc' */
|
||||
lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */
|
||||
l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
|
||||
lu_mem GCmemtrav; /* memory traversed by the GC */
|
||||
lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
|
||||
lu_mem lastmajormem; /* memory in use after last major collection */
|
||||
stringtable strt; /* hash table for strings */
|
||||
TValue l_registry;
|
||||
unsigned int seed; /* randomized seed for hashes */
|
||||
lu_byte currentwhite;
|
||||
lu_byte gcstate; /* state of garbage collector */
|
||||
lu_byte gckind; /* kind of GC running */
|
||||
@@ -126,8 +123,7 @@ typedef struct global_State {
|
||||
int sweepstrgc; /* position of sweep in `strt' */
|
||||
GCObject *allgc; /* list of all collectable objects */
|
||||
GCObject *finobj; /* list of collectable objects with finalizers */
|
||||
GCObject **sweepgc; /* current position of sweep in list 'allgc' */
|
||||
GCObject **sweepfin; /* current position of sweep in list 'finobj' */
|
||||
GCObject **sweepgc; /* current position of sweep */
|
||||
GCObject *gray; /* list of gray objects */
|
||||
GCObject *grayagain; /* list of objects to be traversed atomically */
|
||||
GCObject *weak; /* list of tables with weak values */
|
||||
@@ -137,7 +133,7 @@ typedef struct global_State {
|
||||
UpVal uvhead; /* head of double-linked list of all open upvalues */
|
||||
Mbuffer buff; /* temporary buffer for string concatenation */
|
||||
int gcpause; /* size of pause between successive GCs */
|
||||
int gcmajorinc; /* pause between major collections (only in gen. mode) */
|
||||
int gcmajorinc; /* how much to wait for a major GC (only in gen. mode) */
|
||||
int gcstepmul; /* GC `granularity' */
|
||||
lua_CFunction panic; /* to be called in unprotected errors */
|
||||
struct lua_State *mainthread;
|
||||
@@ -197,15 +193,11 @@ union GCObject {
|
||||
#define gch(o) (&(o)->gch)
|
||||
|
||||
/* macros to convert a GCObject into a specific value */
|
||||
#define rawgco2ts(o) \
|
||||
check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((o)->ts))
|
||||
#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
|
||||
#define gco2ts(o) (&rawgco2ts(o)->tsv)
|
||||
#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
|
||||
#define gco2u(o) (&rawgco2u(o)->uv)
|
||||
#define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l))
|
||||
#define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c))
|
||||
#define gco2cl(o) \
|
||||
check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl))
|
||||
#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
|
||||
#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
|
||||
#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
|
||||
#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
|
||||
|
||||
117
lstring.c
117
lstring.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstring.c,v 2.26 2013/01/08 13:50:10 roberto Exp $
|
||||
** $Id: lstring.c,v 2.18 2010/05/10 18:23:45 roberto Exp roberto $
|
||||
** String table (keeps all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -18,49 +18,7 @@
|
||||
#include "lstring.h"
|
||||
|
||||
|
||||
/*
|
||||
** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to
|
||||
** compute its hash
|
||||
*/
|
||||
#if !defined(LUAI_HASHLIMIT)
|
||||
#define LUAI_HASHLIMIT 5
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** equality for long strings
|
||||
*/
|
||||
int luaS_eqlngstr (TString *a, TString *b) {
|
||||
size_t len = a->tsv.len;
|
||||
lua_assert(a->tsv.tt == LUA_TLNGSTR && b->tsv.tt == LUA_TLNGSTR);
|
||||
return (a == b) || /* same instance or... */
|
||||
((len == b->tsv.len) && /* equal length and ... */
|
||||
(memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** equality for strings
|
||||
*/
|
||||
int luaS_eqstr (TString *a, TString *b) {
|
||||
return (a->tsv.tt == b->tsv.tt) &&
|
||||
(a->tsv.tt == LUA_TSHRSTR ? eqshrstr(a, b) : luaS_eqlngstr(a, b));
|
||||
}
|
||||
|
||||
|
||||
unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
|
||||
unsigned int h = seed ^ cast(unsigned int, l);
|
||||
size_t l1;
|
||||
size_t step = (l >> LUAI_HASHLIMIT) + 1;
|
||||
for (l1 = l; l1 >= step; l1 -= step)
|
||||
h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1]));
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** resizes the string table
|
||||
*/
|
||||
void luaS_resize (lua_State *L, int newsize) {
|
||||
int i;
|
||||
stringtable *tb = &G(L)->strt;
|
||||
@@ -92,81 +50,52 @@ void luaS_resize (lua_State *L, int newsize) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** creates a new string object
|
||||
*/
|
||||
static TString *createstrobj (lua_State *L, const char *str, size_t l,
|
||||
int tag, unsigned int h, GCObject **list) {
|
||||
TString *ts;
|
||||
static TString *newlstr (lua_State *L, const char *str, size_t l,
|
||||
unsigned int h) {
|
||||
size_t totalsize; /* total size of TString object */
|
||||
GCObject **list; /* (pointer to) list where it will be inserted */
|
||||
TString *ts;
|
||||
stringtable *tb = &G(L)->strt;
|
||||
if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
|
||||
luaM_toobig(L);
|
||||
if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
|
||||
luaS_resize(L, tb->size*2); /* too crowded */
|
||||
totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
|
||||
ts = &luaC_newobj(L, tag, totalsize, list, 0)->ts;
|
||||
list = &tb->hash[lmod(h, tb->size)];
|
||||
ts = &luaC_newobj(L, LUA_TSTRING, totalsize, list, 0)->ts;
|
||||
ts->tsv.len = l;
|
||||
ts->tsv.hash = h;
|
||||
ts->tsv.extra = 0;
|
||||
ts->tsv.reserved = 0;
|
||||
memcpy(ts+1, str, l*sizeof(char));
|
||||
((char *)(ts+1))[l] = '\0'; /* ending 0 */
|
||||
tb->nuse++;
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** creates a new short string, inserting it into string table
|
||||
*/
|
||||
static TString *newshrstr (lua_State *L, const char *str, size_t l,
|
||||
unsigned int h) {
|
||||
GCObject **list; /* (pointer to) list where it will be inserted */
|
||||
stringtable *tb = &G(L)->strt;
|
||||
TString *s;
|
||||
if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
|
||||
luaS_resize(L, tb->size*2); /* too crowded */
|
||||
list = &tb->hash[lmod(h, tb->size)];
|
||||
s = createstrobj(L, str, l, LUA_TSHRSTR, h, list);
|
||||
tb->nuse++;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** checks whether short string exists and reuses it or creates a new one
|
||||
*/
|
||||
static TString *internshrstr (lua_State *L, const char *str, size_t l) {
|
||||
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
||||
GCObject *o;
|
||||
global_State *g = G(L);
|
||||
unsigned int h = luaS_hash(str, l, g->seed);
|
||||
for (o = g->strt.hash[lmod(h, g->strt.size)];
|
||||
unsigned int h = cast(unsigned int, l); /* seed */
|
||||
size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
|
||||
size_t l1;
|
||||
for (l1=l; l1>=step; l1-=step) /* compute hash */
|
||||
h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
|
||||
for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
|
||||
o != NULL;
|
||||
o = gch(o)->next) {
|
||||
TString *ts = rawgco2ts(o);
|
||||
if (h == ts->tsv.hash &&
|
||||
l == ts->tsv.len &&
|
||||
ts->tsv.len == l &&
|
||||
(memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {
|
||||
if (isdead(G(L), o)) /* string is dead (but was not collected yet)? */
|
||||
changewhite(o); /* resurrect it */
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
return newshrstr(L, str, l, h); /* not found; create a new string */
|
||||
return newlstr(L, str, l, h); /* not found; create a new string */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** new string (with explicit length)
|
||||
*/
|
||||
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
||||
if (l <= LUAI_MAXSHORTLEN) /* short string? */
|
||||
return internshrstr(L, str, l);
|
||||
else {
|
||||
if (l + 1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
|
||||
luaM_toobig(L);
|
||||
return createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** new zero-terminated string
|
||||
*/
|
||||
TString *luaS_new (lua_State *L, const char *str) {
|
||||
return luaS_newlstr(L, str, strlen(str));
|
||||
}
|
||||
|
||||
17
lstring.h
17
lstring.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstring.h,v 1.49 2012/02/01 21:57:15 roberto Exp $
|
||||
** $Id: lstring.h,v 1.45 2010/04/03 20:24:18 roberto Exp roberto $
|
||||
** String table (keep all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -23,20 +23,11 @@
|
||||
|
||||
|
||||
/*
|
||||
** test whether a string is a reserved word
|
||||
** as all string are internalized, string equality becomes
|
||||
** pointer equality
|
||||
*/
|
||||
#define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0)
|
||||
#define eqstr(a,b) ((a) == (b))
|
||||
|
||||
|
||||
/*
|
||||
** equality for short strings, which are always internalized
|
||||
*/
|
||||
#define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b))
|
||||
|
||||
|
||||
LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
|
||||
LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
|
||||
LUAI_FUNC int luaS_eqstr (TString *a, TString *b);
|
||||
LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
|
||||
LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
|
||||
LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
|
||||
|
||||
240
lstrlib.c
240
lstrlib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstrlib.c,v 1.178 2012/08/14 18:12:34 roberto Exp $
|
||||
** $Id: lstrlib.c,v 1.172 2011/10/25 12:01:20 roberto Exp roberto $
|
||||
** Standard library for string operations and pattern-matching
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
|
||||
/* macro to `unsign' a character */
|
||||
#define uchar(c) ((unsigned char)(c))
|
||||
#define uchar(c) ((unsigned char)(c))
|
||||
|
||||
|
||||
|
||||
@@ -119,9 +119,7 @@ static int str_rep (lua_State *L) {
|
||||
char *p = luaL_buffinitsize(L, &b, totallen);
|
||||
while (n-- > 1) { /* first n-1 copies (followed by separator) */
|
||||
memcpy(p, s, l * sizeof(char)); p += l;
|
||||
if (lsep > 0) { /* avoid empty 'memcpy' (may be expensive) */
|
||||
memcpy(p, sep, lsep * sizeof(char)); p += lsep;
|
||||
}
|
||||
memcpy(p, sep, lsep * sizeof(char)); p += lsep;
|
||||
}
|
||||
memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */
|
||||
luaL_pushresultsize(&b, totallen);
|
||||
@@ -194,9 +192,7 @@ static int str_dump (lua_State *L) {
|
||||
#define CAP_UNFINISHED (-1)
|
||||
#define CAP_POSITION (-2)
|
||||
|
||||
|
||||
typedef struct MatchState {
|
||||
int matchdepth; /* control for recursive depth (to avoid C stack overflow) */
|
||||
const char *src_init; /* init of source string */
|
||||
const char *src_end; /* end ('\0') of source string */
|
||||
const char *p_end; /* end ('\0') of pattern */
|
||||
@@ -209,16 +205,6 @@ typedef struct MatchState {
|
||||
} MatchState;
|
||||
|
||||
|
||||
/* recursive function */
|
||||
static const char *match (MatchState *ms, const char *s, const char *p);
|
||||
|
||||
|
||||
/* maximum recursion depth for 'match' */
|
||||
#if !defined(MAXCCALLS)
|
||||
#define MAXCCALLS 200
|
||||
#endif
|
||||
|
||||
|
||||
#define L_ESC '%'
|
||||
#define SPECIALS "^$*+?.([%-"
|
||||
|
||||
@@ -306,22 +292,19 @@ static int matchbracketclass (int c, const char *p, const char *ec) {
|
||||
}
|
||||
|
||||
|
||||
static int singlematch (MatchState *ms, const char *s, const char *p,
|
||||
const char *ep) {
|
||||
if (s >= ms->src_end)
|
||||
return 0;
|
||||
else {
|
||||
int c = uchar(*s);
|
||||
switch (*p) {
|
||||
case '.': return 1; /* matches any char */
|
||||
case L_ESC: return match_class(c, uchar(*(p+1)));
|
||||
case '[': return matchbracketclass(c, p, ep-1);
|
||||
default: return (uchar(*p) == c);
|
||||
}
|
||||
static int singlematch (int c, const char *p, const char *ep) {
|
||||
switch (*p) {
|
||||
case '.': return 1; /* matches any char */
|
||||
case L_ESC: return match_class(c, uchar(*(p+1)));
|
||||
case '[': return matchbracketclass(c, p, ep-1);
|
||||
default: return (uchar(*p) == c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const char *match (MatchState *ms, const char *s, const char *p);
|
||||
|
||||
|
||||
static const char *matchbalance (MatchState *ms, const char *s,
|
||||
const char *p) {
|
||||
if (p >= ms->p_end - 1)
|
||||
@@ -346,7 +329,7 @@ static const char *matchbalance (MatchState *ms, const char *s,
|
||||
static const char *max_expand (MatchState *ms, const char *s,
|
||||
const char *p, const char *ep) {
|
||||
ptrdiff_t i = 0; /* counts maximum expand for item */
|
||||
while (singlematch(ms, s + i, p, ep))
|
||||
while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep))
|
||||
i++;
|
||||
/* keeps trying to match with the maximum repetitions */
|
||||
while (i>=0) {
|
||||
@@ -364,7 +347,7 @@ static const char *min_expand (MatchState *ms, const char *s,
|
||||
const char *res = match(ms, s, ep+1);
|
||||
if (res != NULL)
|
||||
return res;
|
||||
else if (singlematch(ms, s, p, ep))
|
||||
else if (s<ms->src_end && singlematch(uchar(*s), p, ep))
|
||||
s++; /* try with one more repetition */
|
||||
else return NULL;
|
||||
}
|
||||
@@ -408,105 +391,79 @@ static const char *match_capture (MatchState *ms, const char *s, int l) {
|
||||
|
||||
|
||||
static const char *match (MatchState *ms, const char *s, const char *p) {
|
||||
if (ms->matchdepth-- == 0)
|
||||
luaL_error(ms->L, "pattern too complex");
|
||||
init: /* using goto's to optimize tail recursion */
|
||||
if (p != ms->p_end) { /* end of pattern? */
|
||||
switch (*p) {
|
||||
case '(': { /* start capture */
|
||||
if (*(p + 1) == ')') /* position capture? */
|
||||
s = start_capture(ms, s, p + 2, CAP_POSITION);
|
||||
else
|
||||
s = start_capture(ms, s, p + 1, CAP_UNFINISHED);
|
||||
break;
|
||||
}
|
||||
case ')': { /* end capture */
|
||||
s = end_capture(ms, s, p + 1);
|
||||
break;
|
||||
}
|
||||
case '$': {
|
||||
if ((p + 1) != ms->p_end) /* is the `$' the last char in pattern? */
|
||||
goto dflt; /* no; go to default */
|
||||
s = (s == ms->src_end) ? s : NULL; /* check end of string */
|
||||
break;
|
||||
}
|
||||
case L_ESC: { /* escaped sequences not in the format class[*+?-]? */
|
||||
switch (*(p + 1)) {
|
||||
case 'b': { /* balanced string? */
|
||||
s = matchbalance(ms, s, p + 2);
|
||||
if (s != NULL) {
|
||||
p += 4; goto init; /* return match(ms, s, p + 4); */
|
||||
} /* else fail (s == NULL) */
|
||||
break;
|
||||
}
|
||||
case 'f': { /* frontier? */
|
||||
const char *ep; char previous;
|
||||
p += 2;
|
||||
if (*p != '[')
|
||||
luaL_error(ms->L, "missing " LUA_QL("[") " after "
|
||||
LUA_QL("%%f") " in pattern");
|
||||
ep = classend(ms, p); /* points to what is next */
|
||||
previous = (s == ms->src_init) ? '\0' : *(s - 1);
|
||||
if (!matchbracketclass(uchar(previous), p, ep - 1) &&
|
||||
matchbracketclass(uchar(*s), p, ep - 1)) {
|
||||
p = ep; goto init; /* return match(ms, s, ep); */
|
||||
}
|
||||
s = NULL; /* match failed */
|
||||
break;
|
||||
}
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
case '8': case '9': { /* capture results (%0-%9)? */
|
||||
s = match_capture(ms, s, uchar(*(p + 1)));
|
||||
if (s != NULL) {
|
||||
p += 2; goto init; /* return match(ms, s, p + 2) */
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: goto dflt;
|
||||
if (p == ms->p_end) /* end of pattern? */
|
||||
return s; /* match succeeded */
|
||||
switch (*p) {
|
||||
case '(': { /* start capture */
|
||||
if (*(p+1) == ')') /* position capture? */
|
||||
return start_capture(ms, s, p+2, CAP_POSITION);
|
||||
else
|
||||
return start_capture(ms, s, p+1, CAP_UNFINISHED);
|
||||
}
|
||||
case ')': { /* end capture */
|
||||
return end_capture(ms, s, p+1);
|
||||
}
|
||||
case '$': {
|
||||
if ((p+1) == ms->p_end) /* is the `$' the last char in pattern? */
|
||||
return (s == ms->src_end) ? s : NULL; /* check end of string */
|
||||
else goto dflt;
|
||||
}
|
||||
case L_ESC: { /* escaped sequences not in the format class[*+?-]? */
|
||||
switch (*(p+1)) {
|
||||
case 'b': { /* balanced string? */
|
||||
s = matchbalance(ms, s, p+2);
|
||||
if (s == NULL) return NULL;
|
||||
p+=4; goto init; /* else return match(ms, s, p+4); */
|
||||
}
|
||||
break;
|
||||
case 'f': { /* frontier? */
|
||||
const char *ep; char previous;
|
||||
p += 2;
|
||||
if (*p != '[')
|
||||
luaL_error(ms->L, "missing " LUA_QL("[") " after "
|
||||
LUA_QL("%%f") " in pattern");
|
||||
ep = classend(ms, p); /* points to what is next */
|
||||
previous = (s == ms->src_init) ? '\0' : *(s-1);
|
||||
if (matchbracketclass(uchar(previous), p, ep-1) ||
|
||||
!matchbracketclass(uchar(*s), p, ep-1)) return NULL;
|
||||
p=ep; goto init; /* else return match(ms, s, ep); */
|
||||
}
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
case '8': case '9': { /* capture results (%0-%9)? */
|
||||
s = match_capture(ms, s, uchar(*(p+1)));
|
||||
if (s == NULL) return NULL;
|
||||
p+=2; goto init; /* else return match(ms, s, p+2) */
|
||||
}
|
||||
default: goto dflt;
|
||||
}
|
||||
default: dflt: { /* pattern class plus optional suffix */
|
||||
const char *ep = classend(ms, p); /* points to optional suffix */
|
||||
/* does not match at least once? */
|
||||
if (!singlematch(ms, s, p, ep)) {
|
||||
if (*ep == '*' || *ep == '?' || *ep == '-') { /* accept empty? */
|
||||
p = ep + 1; goto init; /* return match(ms, s, ep + 1); */
|
||||
}
|
||||
else /* '+' or no suffix */
|
||||
s = NULL; /* fail */
|
||||
}
|
||||
default: dflt: { /* pattern class plus optional suffix */
|
||||
const char *ep = classend(ms, p); /* points to what is next */
|
||||
int m = s < ms->src_end && singlematch(uchar(*s), p, ep);
|
||||
switch (*ep) {
|
||||
case '?': { /* optional */
|
||||
const char *res;
|
||||
if (m && ((res=match(ms, s+1, ep+1)) != NULL))
|
||||
return res;
|
||||
p=ep+1; goto init; /* else return match(ms, s, ep+1); */
|
||||
}
|
||||
else { /* matched once */
|
||||
switch (*ep) { /* handle optional suffix */
|
||||
case '?': { /* optional */
|
||||
const char *res;
|
||||
if ((res = match(ms, s + 1, ep + 1)) != NULL)
|
||||
s = res;
|
||||
else {
|
||||
p = ep + 1; goto init; /* else return match(ms, s, ep + 1); */
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '+': /* 1 or more repetitions */
|
||||
s++; /* 1 match already done */
|
||||
/* go through */
|
||||
case '*': /* 0 or more repetitions */
|
||||
s = max_expand(ms, s, p, ep);
|
||||
break;
|
||||
case '-': /* 0 or more repetitions (minimum) */
|
||||
s = min_expand(ms, s, p, ep);
|
||||
break;
|
||||
default: /* no suffix */
|
||||
s++; p = ep; goto init; /* return match(ms, s + 1, ep); */
|
||||
}
|
||||
case '*': { /* 0 or more repetitions */
|
||||
return max_expand(ms, s, p, ep);
|
||||
}
|
||||
case '+': { /* 1 or more repetitions */
|
||||
return (m ? max_expand(ms, s+1, p, ep) : NULL);
|
||||
}
|
||||
case '-': { /* 0 or more repetitions (minimum) */
|
||||
return min_expand(ms, s, p, ep);
|
||||
}
|
||||
default: {
|
||||
if (!m) return NULL;
|
||||
s++; p=ep; goto init; /* else return match(ms, s+1, ep); */
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ms->matchdepth++;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -602,14 +559,12 @@ static int str_find_aux (lua_State *L, int find) {
|
||||
p++; lp--; /* skip anchor character */
|
||||
}
|
||||
ms.L = L;
|
||||
ms.matchdepth = MAXCCALLS;
|
||||
ms.src_init = s;
|
||||
ms.src_end = s + ls;
|
||||
ms.p_end = p + lp;
|
||||
do {
|
||||
const char *res;
|
||||
ms.level = 0;
|
||||
lua_assert(ms.matchdepth == MAXCCALLS);
|
||||
if ((res=match(&ms, s1, p)) != NULL) {
|
||||
if (find) {
|
||||
lua_pushinteger(L, s1 - s + 1); /* start */
|
||||
@@ -643,7 +598,6 @@ static int gmatch_aux (lua_State *L) {
|
||||
const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp);
|
||||
const char *src;
|
||||
ms.L = L;
|
||||
ms.matchdepth = MAXCCALLS;
|
||||
ms.src_init = s;
|
||||
ms.src_end = s+ls;
|
||||
ms.p_end = p + lp;
|
||||
@@ -652,7 +606,6 @@ static int gmatch_aux (lua_State *L) {
|
||||
src++) {
|
||||
const char *e;
|
||||
ms.level = 0;
|
||||
lua_assert(ms.matchdepth == MAXCCALLS);
|
||||
if ((e = match(&ms, src, p)) != NULL) {
|
||||
lua_Integer newstart = e-s;
|
||||
if (e == src) newstart++; /* empty match? go at least one position */
|
||||
@@ -750,14 +703,12 @@ static int str_gsub (lua_State *L) {
|
||||
p++; lp--; /* skip anchor character */
|
||||
}
|
||||
ms.L = L;
|
||||
ms.matchdepth = MAXCCALLS;
|
||||
ms.src_init = src;
|
||||
ms.src_end = src+srcl;
|
||||
ms.p_end = p + lp;
|
||||
while (n < max_s) {
|
||||
const char *e;
|
||||
ms.level = 0;
|
||||
lua_assert(ms.matchdepth == MAXCCALLS);
|
||||
e = match(&ms, src, p);
|
||||
if (e) {
|
||||
n++;
|
||||
@@ -794,17 +745,20 @@ static int str_gsub (lua_State *L) {
|
||||
#if !defined(LUA_INTFRMLEN) /* { */
|
||||
#if defined(LUA_USE_LONGLONG)
|
||||
|
||||
#define LUA_INTFRMLEN "ll"
|
||||
#define LUA_INTFRM_T long long
|
||||
#define LUA_INTFRMLEN "ll"
|
||||
#define LUA_INTFRM_T long long
|
||||
|
||||
#else
|
||||
|
||||
#define LUA_INTFRMLEN "l"
|
||||
#define LUA_INTFRM_T long
|
||||
#define LUA_INTFRMLEN "l"
|
||||
#define LUA_INTFRM_T long
|
||||
|
||||
#endif
|
||||
#endif /* } */
|
||||
|
||||
#define MAX_UINTFRM ((lua_Number)(~(unsigned LUA_INTFRM_T)0))
|
||||
#define MAX_INTFRM ((lua_Number)((~(unsigned LUA_INTFRM_T)0)/2))
|
||||
#define MIN_INTFRM (-(lua_Number)((~(unsigned LUA_INTFRM_T)0)/2) - 1)
|
||||
|
||||
/*
|
||||
** LUA_FLTFRMLEN is the length modifier for float conversions in
|
||||
@@ -813,8 +767,8 @@ static int str_gsub (lua_State *L) {
|
||||
*/
|
||||
#if !defined(LUA_FLTFRMLEN)
|
||||
|
||||
#define LUA_FLTFRMLEN ""
|
||||
#define LUA_FLTFRM_T double
|
||||
#define LUA_FLTFRMLEN ""
|
||||
#define LUA_FLTFRM_T double
|
||||
|
||||
#endif
|
||||
|
||||
@@ -914,27 +868,23 @@ static int str_format (lua_State *L) {
|
||||
nb = sprintf(buff, form, luaL_checkint(L, arg));
|
||||
break;
|
||||
}
|
||||
case 'd': case 'i': {
|
||||
case 'd': case 'i': {
|
||||
lua_Number n = luaL_checknumber(L, arg);
|
||||
LUA_INTFRM_T ni = (LUA_INTFRM_T)n;
|
||||
lua_Number diff = n - (lua_Number)ni;
|
||||
luaL_argcheck(L, -1 < diff && diff < 1, arg,
|
||||
luaL_argcheck(L, (MIN_INTFRM - 1) < n && n < (MAX_INTFRM + 1), arg,
|
||||
"not a number in proper range");
|
||||
addlenmod(form, LUA_INTFRMLEN);
|
||||
nb = sprintf(buff, form, ni);
|
||||
nb = sprintf(buff, form, (LUA_INTFRM_T)n);
|
||||
break;
|
||||
}
|
||||
case 'o': case 'u': case 'x': case 'X': {
|
||||
case 'o': case 'u': case 'x': case 'X': {
|
||||
lua_Number n = luaL_checknumber(L, arg);
|
||||
unsigned LUA_INTFRM_T ni = (unsigned LUA_INTFRM_T)n;
|
||||
lua_Number diff = n - (lua_Number)ni;
|
||||
luaL_argcheck(L, -1 < diff && diff < 1, arg,
|
||||
luaL_argcheck(L, 0 <= n && n < (MAX_UINTFRM + 1), arg,
|
||||
"not a non-negative number in proper range");
|
||||
addlenmod(form, LUA_INTFRMLEN);
|
||||
nb = sprintf(buff, form, ni);
|
||||
nb = sprintf(buff, form, (unsigned LUA_INTFRM_T)n);
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E': case 'f':
|
||||
case 'e': case 'E': case 'f':
|
||||
#if defined(LUA_USE_AFORMAT)
|
||||
case 'a': case 'A':
|
||||
#endif
|
||||
|
||||
29
ltable.c
29
ltable.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltable.c,v 2.72 2012/09/11 19:37:16 roberto Exp $
|
||||
** $Id: ltable.c,v 2.66 2011/11/28 17:25:48 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -48,10 +48,10 @@
|
||||
#define MAXASIZE (1 << MAXBITS)
|
||||
|
||||
|
||||
#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
|
||||
#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
|
||||
|
||||
#define hashstr(t,str) hashpow2(t, (str)->tsv.hash)
|
||||
#define hashboolean(t,p) hashpow2(t, p)
|
||||
#define hashstr(t,str) hashpow2(t, (str)->tsv.hash)
|
||||
#define hashboolean(t,p) hashpow2(t, p)
|
||||
|
||||
|
||||
/*
|
||||
@@ -98,15 +98,7 @@ static Node *mainposition (const Table *t, const TValue *key) {
|
||||
switch (ttype(key)) {
|
||||
case LUA_TNUMBER:
|
||||
return hashnum(t, nvalue(key));
|
||||
case LUA_TLNGSTR: {
|
||||
TString *s = rawtsvalue(key);
|
||||
if (s->tsv.extra == 0) { /* no hash? */
|
||||
s->tsv.hash = luaS_hash(getstr(s), s->tsv.len, s->tsv.hash);
|
||||
s->tsv.extra = 1; /* now it has its hash */
|
||||
}
|
||||
return hashstr(t, rawtsvalue(key));
|
||||
}
|
||||
case LUA_TSHRSTR:
|
||||
case LUA_TSTRING:
|
||||
return hashstr(t, rawtsvalue(key));
|
||||
case LUA_TBOOLEAN:
|
||||
return hashboolean(t, bvalue(key));
|
||||
@@ -461,13 +453,12 @@ const TValue *luaH_getint (Table *t, int key) {
|
||||
|
||||
|
||||
/*
|
||||
** search function for short strings
|
||||
** search function for strings
|
||||
*/
|
||||
const TValue *luaH_getstr (Table *t, TString *key) {
|
||||
Node *n = hashstr(t, key);
|
||||
lua_assert(key->tsv.tt == LUA_TSHRSTR);
|
||||
do { /* check whether `key' is somewhere in the chain */
|
||||
if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key))
|
||||
if (ttisstring(gkey(n)) && eqstr(rawtsvalue(gkey(n)), key))
|
||||
return gval(n); /* that's it */
|
||||
else n = gnext(n);
|
||||
} while (n);
|
||||
@@ -479,14 +470,14 @@ const TValue *luaH_getstr (Table *t, TString *key) {
|
||||
** main search function
|
||||
*/
|
||||
const TValue *luaH_get (Table *t, const TValue *key) {
|
||||
switch (ttype(key)) {
|
||||
case LUA_TSHRSTR: return luaH_getstr(t, rawtsvalue(key));
|
||||
switch (ttypenv(key)) {
|
||||
case LUA_TNIL: return luaO_nilobject;
|
||||
case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
|
||||
case LUA_TNUMBER: {
|
||||
int k;
|
||||
lua_Number n = nvalue(key);
|
||||
lua_number2int(k, n);
|
||||
if (luai_numeq(cast_num(k), n)) /* index is int? */
|
||||
if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
|
||||
return luaH_getint(t, k); /* use specialized version */
|
||||
/* else go through */
|
||||
}
|
||||
|
||||
6
ltable.h
6
ltable.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltable.h,v 2.16.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** $Id: ltable.h,v 2.15 2011/08/09 20:58:29 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -17,10 +17,6 @@
|
||||
|
||||
#define invalidateTMcache(t) ((t)->flags = 0)
|
||||
|
||||
/* returns the key, given the value of a table entry */
|
||||
#define keyfromval(v) \
|
||||
(gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
|
||||
|
||||
|
||||
LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
|
||||
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value);
|
||||
|
||||
28
ltablib.c
28
ltablib.c
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
** $Id: ltablib.c,v 1.65.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** $Id: ltablib.c,v 1.62 2011/09/30 12:45:45 roberto Exp roberto $
|
||||
** Library for Table Manipulation
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define ltablib_c
|
||||
@@ -17,8 +16,8 @@
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_len(L, n))
|
||||
|
||||
#define aux_getn(L,n) \
|
||||
(luaL_checktype(L, n, LUA_TTABLE), luaL_len(L, n))
|
||||
|
||||
|
||||
#if defined(LUA_COMPAT_MAXN)
|
||||
@@ -50,7 +49,7 @@ static int tinsert (lua_State *L) {
|
||||
case 3: {
|
||||
int i;
|
||||
pos = luaL_checkint(L, 2); /* 2nd argument is the position */
|
||||
luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds");
|
||||
if (pos > e) e = pos; /* `grow' array if necessary */
|
||||
for (i = e; i > pos; i--) { /* move up elements */
|
||||
lua_rawgeti(L, 1, i-1);
|
||||
lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
|
||||
@@ -67,17 +66,17 @@ static int tinsert (lua_State *L) {
|
||||
|
||||
|
||||
static int tremove (lua_State *L) {
|
||||
int size = aux_getn(L, 1);
|
||||
int pos = luaL_optint(L, 2, size);
|
||||
if (pos != size) /* validate 'pos' if given */
|
||||
luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds");
|
||||
int e = aux_getn(L, 1);
|
||||
int pos = luaL_optint(L, 2, e);
|
||||
if (!(1 <= pos && pos <= e)) /* position is outside bounds? */
|
||||
return 0; /* nothing to remove */
|
||||
lua_rawgeti(L, 1, pos); /* result = t[pos] */
|
||||
for ( ; pos < size; pos++) {
|
||||
for ( ;pos<e; pos++) {
|
||||
lua_rawgeti(L, 1, pos+1);
|
||||
lua_rawseti(L, 1, pos); /* t[pos] = t[pos+1] */
|
||||
}
|
||||
lua_pushnil(L);
|
||||
lua_rawseti(L, 1, pos); /* t[pos] = nil */
|
||||
lua_rawseti(L, 1, e); /* t[e] = nil */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -135,14 +134,13 @@ static int pack (lua_State *L) {
|
||||
|
||||
|
||||
static int unpack (lua_State *L) {
|
||||
int i, e;
|
||||
unsigned int n;
|
||||
int i, e, n;
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
i = luaL_optint(L, 2, 1);
|
||||
e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
|
||||
if (i > e) return 0; /* empty range */
|
||||
n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */
|
||||
if (n > (INT_MAX - 10) || !lua_checkstack(L, ++n))
|
||||
n = e - i + 1; /* number of elements */
|
||||
if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
|
||||
return luaL_error(L, "too many results to unpack");
|
||||
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
|
||||
while (i++ < e) /* push arg[i + 1...e] */
|
||||
|
||||
103
ltests.c
103
ltests.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltests.c,v 2.135 2013/03/16 21:10:18 roberto Exp $
|
||||
** $Id: ltests.c,v 2.123 2011/09/24 21:11:29 roberto Exp roberto $
|
||||
** Internal Module for Debugging of the Lua Implementation
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -182,23 +182,18 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) {
|
||||
|
||||
static int testobjref1 (global_State *g, GCObject *f, GCObject *t) {
|
||||
if (isdead(g,t)) return 0;
|
||||
if (!issweepphase(g))
|
||||
return !(isblack(f) && iswhite(t));
|
||||
if (isgenerational(g) || !issweepphase(g))
|
||||
return !isblack(f) || !iswhite(t);
|
||||
else return 1;
|
||||
}
|
||||
|
||||
|
||||
static void printobj (global_State *g, GCObject *o) {
|
||||
int i = 1;
|
||||
int i = 0;
|
||||
GCObject *p;
|
||||
for (p = g->allgc; p != o && p != NULL; p = gch(p)->next) i++;
|
||||
if (p == NULL) {
|
||||
i = 1;
|
||||
for (p = g->finobj; p != o && p != NULL; p = gch(p)->next) i++;
|
||||
if (p == NULL) i = 0; /* zero means 'not found' */
|
||||
else i = -i; /* negative means 'found in findobj list */
|
||||
}
|
||||
printf("||%d:%s(%p)-%c(%02X)||", i, ttypename(gch(o)->tt), (void *)o,
|
||||
if (p == NULL) i = -1;
|
||||
printf("%d:%s(%p)-%c(%02X)", i, ttypename(gch(o)->tt), (void *)o,
|
||||
isdead(g,o)?'d':isblack(o)?'b':iswhite(o)?'w':'g', gch(o)->marked);
|
||||
}
|
||||
|
||||
@@ -272,22 +267,22 @@ static void checkproto (global_State *g, Proto *f) {
|
||||
|
||||
|
||||
|
||||
static void checkCclosure (global_State *g, CClosure *cl) {
|
||||
static void checkclosure (global_State *g, Closure *cl) {
|
||||
GCObject *clgc = obj2gco(cl);
|
||||
int i;
|
||||
for (i = 0; i < cl->nupvalues; i++)
|
||||
checkvalref(g, clgc, &cl->upvalue[i]);
|
||||
}
|
||||
|
||||
|
||||
static void checkLclosure (global_State *g, LClosure *cl) {
|
||||
GCObject *clgc = obj2gco(cl);
|
||||
int i;
|
||||
if (cl->p) checkobjref(g, clgc, cl->p);
|
||||
for (i=0; i<cl->nupvalues; i++) {
|
||||
if (cl->upvals[i]) {
|
||||
lua_assert(cl->upvals[i]->tt == LUA_TUPVAL);
|
||||
checkobjref(g, clgc, cl->upvals[i]);
|
||||
if (cl->c.isC) {
|
||||
int i;
|
||||
for (i=0; i<cl->c.nupvalues; i++)
|
||||
checkvalref(g, clgc, &cl->c.upvalue[i]);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
|
||||
checkobjref(g, clgc, cl->l.p);
|
||||
for (i=0; i<cl->l.nupvalues; i++) {
|
||||
if (cl->l.upvals[i]) {
|
||||
lua_assert(cl->l.upvals[i]->tt == LUA_TUPVAL);
|
||||
checkobjref(g, clgc, cl->l.upvals[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,11 +320,11 @@ static void checkstack (global_State *g, lua_State *L1) {
|
||||
}
|
||||
|
||||
|
||||
static void checkobject (global_State *g, GCObject *o, int maybedead) {
|
||||
static void checkobject (global_State *g, GCObject *o) {
|
||||
if (isdead(g, o))
|
||||
lua_assert(maybedead);
|
||||
lua_assert(issweepphase(g));
|
||||
else {
|
||||
if (g->gcstate == GCSpause)
|
||||
if (g->gcstate == GCSpause && !isgenerational(g))
|
||||
lua_assert(iswhite(o));
|
||||
switch (gch(o)->tt) {
|
||||
case LUA_TUPVAL: {
|
||||
@@ -352,20 +347,15 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) {
|
||||
checkstack(g, gco2th(o));
|
||||
break;
|
||||
}
|
||||
case LUA_TLCL: {
|
||||
checkLclosure(g, gco2lcl(o));
|
||||
break;
|
||||
}
|
||||
case LUA_TCCL: {
|
||||
checkCclosure(g, gco2ccl(o));
|
||||
case LUA_TFUNCTION: {
|
||||
checkclosure(g, gco2cl(o));
|
||||
break;
|
||||
}
|
||||
case LUA_TPROTO: {
|
||||
checkproto(g, gco2p(o));
|
||||
break;
|
||||
}
|
||||
case LUA_TSHRSTR:
|
||||
case LUA_TLNGSTR: break;
|
||||
case LUA_TSTRING: break;
|
||||
default: lua_assert(0);
|
||||
}
|
||||
}
|
||||
@@ -381,8 +371,7 @@ static void checkgraylist (GCObject *l) {
|
||||
l_setbit(l->gch.marked, TESTGRAYBIT);
|
||||
switch (gch(l)->tt) {
|
||||
case LUA_TTABLE: l = gco2t(l)->gclist; break;
|
||||
case LUA_TLCL: l = gco2lcl(l)->gclist; break;
|
||||
case LUA_TCCL: l = gco2ccl(l)->gclist; break;
|
||||
case LUA_TFUNCTION: l = gco2cl(l)->c.gclist; break;
|
||||
case LUA_TTHREAD: l = gco2th(l)->gclist; break;
|
||||
case LUA_TPROTO: l = gco2p(l)->gclist; break;
|
||||
default: lua_assert(0); /* other objects cannot be gray */
|
||||
@@ -427,39 +416,32 @@ int lua_checkmemory (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
GCObject *o;
|
||||
UpVal *uv;
|
||||
int maybedead;
|
||||
if (keepinvariant(g)) {
|
||||
lua_assert(!iswhite(obj2gco(g->mainthread)));
|
||||
lua_assert(!iswhite(gcvalue(&g->l_registry)));
|
||||
}
|
||||
else /* generational mode keeps collector in 'propagate' state */
|
||||
lua_assert(!isgenerational(g));
|
||||
lua_assert(!isdead(g, gcvalue(&g->l_registry)));
|
||||
checkstack(g, g->mainthread);
|
||||
resetbit(g->mainthread->marked, TESTGRAYBIT);
|
||||
/* check 'allgc' list */
|
||||
markgrays(g);
|
||||
checkold(g, g->allgc);
|
||||
lua_assert(g->sweepgc == NULL || issweepphase(g));
|
||||
maybedead = 0;
|
||||
for (o = g->allgc; o != NULL; o = gch(o)->next) {
|
||||
if (g->sweepgc && o == *g->sweepgc)
|
||||
maybedead = 1; /* part of the list not yet swept */
|
||||
checkobject(g, o, maybedead);
|
||||
checkobject(g, o);
|
||||
lua_assert(!testbit(o->gch.marked, SEPARATED));
|
||||
}
|
||||
/* check 'finobj' list */
|
||||
checkold(g, g->finobj);
|
||||
for (o = g->finobj; o != NULL; o = gch(o)->next) {
|
||||
lua_assert(testbit(o->gch.marked, SEPARATED));
|
||||
lua_assert(!isdead(g, o) && testbit(o->gch.marked, SEPARATED));
|
||||
lua_assert(gch(o)->tt == LUA_TUSERDATA ||
|
||||
gch(o)->tt == LUA_TTABLE);
|
||||
checkobject(g, o, 0);
|
||||
checkobject(g, o);
|
||||
}
|
||||
/* check 'tobefnz' list */
|
||||
checkold(g, g->tobefnz);
|
||||
for (o = g->tobefnz; o != NULL; o = gch(o)->next) {
|
||||
lua_assert(!iswhite(o) || g->gcstate == GCSpause);
|
||||
lua_assert(!iswhite(o));
|
||||
lua_assert(!isdead(g, o) && testbit(o->gch.marked, SEPARATED));
|
||||
lua_assert(gch(o)->tt == LUA_TUSERDATA ||
|
||||
gch(o)->tt == LUA_TTABLE);
|
||||
@@ -469,7 +451,9 @@ int lua_checkmemory (lua_State *L) {
|
||||
lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
|
||||
lua_assert(uv->v != &uv->u.value); /* must be open */
|
||||
lua_assert(!isblack(obj2gco(uv))); /* open upvalues are never black */
|
||||
if (!isdead(g, obj2gco(uv)))
|
||||
if (isdead(g, obj2gco(uv)))
|
||||
lua_assert(issweepphase(g));
|
||||
else
|
||||
checkvalref(g, obj2gco(uv), uv->v);
|
||||
}
|
||||
return 0;
|
||||
@@ -520,12 +504,6 @@ void luaI_printcode (Proto *pt, int size) {
|
||||
}
|
||||
printf("-------\n");
|
||||
}
|
||||
|
||||
|
||||
void luaI_printinst (Proto *pt, int pc) {
|
||||
char buff[100];
|
||||
printf("%s\n", buildop(pt, pc, buff));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -663,15 +641,7 @@ static int gc_state (lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
global_State *g = G(L);
|
||||
if (g->gckind == KGC_GEN && option == GCSpause)
|
||||
luaL_error(L, "cannot go to 'pause' state in generational mode");
|
||||
lua_lock(L);
|
||||
if (option < g->gcstate) { /* must cross 'pause'? */
|
||||
luaC_runtilstate(L, bitmask(GCSpause)); /* run until pause */
|
||||
if (g->gckind == KGC_GEN)
|
||||
g->gcstate = GCSpropagate; /* skip pause in gen. mode */
|
||||
}
|
||||
luaC_runtilstate(L, bitmask(option));
|
||||
lua_assert(G(L)->gcstate == option);
|
||||
lua_unlock(L);
|
||||
@@ -751,7 +721,7 @@ static int string_query (lua_State *L) {
|
||||
int n = 0;
|
||||
for (ts = tb->hash[s]; ts; ts = gch(ts)->next) {
|
||||
setsvalue2s(L, L->top, rawgco2ts(ts));
|
||||
api_incr_top(L);
|
||||
incr_top(L);
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
@@ -879,7 +849,6 @@ static int loadlib (lua_State *L) {
|
||||
{"coroutine", luaopen_coroutine},
|
||||
{"debug", luaopen_debug},
|
||||
{"io", luaopen_io},
|
||||
{"os", luaopen_os},
|
||||
{"math", luaopen_math},
|
||||
{"string", luaopen_string},
|
||||
{"table", luaopen_table},
|
||||
|
||||
2
ltests.h
2
ltests.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltests.h,v 2.33 2010/07/28 15:51:59 roberto Exp $
|
||||
** $Id: ltests.h,v 2.32 2010/04/19 17:40:13 roberto Exp roberto $
|
||||
** Internal Header for Debugging of the Lua Implementation
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
2
ltm.c
2
ltm.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltm.c,v 2.14 2011/06/02 19:31:40 roberto Exp $
|
||||
** $Id: ltm.c,v 2.13 2011/02/28 17:32:10 roberto Exp roberto $
|
||||
** Tag methods
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
2
ltm.h
2
ltm.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltm.h,v 2.11 2011/02/28 17:32:10 roberto Exp $
|
||||
** $Id: ltm.h,v 2.10 2010/04/13 20:48:12 roberto Exp roberto $
|
||||
** Tag methods
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
36
lua.c
36
lua.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lua.c,v 1.206 2012/09/29 20:07:06 roberto Exp $
|
||||
** $Id: lua.c,v 1.202 2011/08/17 20:19:52 roberto Exp roberto $
|
||||
** Lua stand-alone interpreter
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -45,13 +45,13 @@
|
||||
*/
|
||||
#if defined(LUA_USE_ISATTY)
|
||||
#include <unistd.h>
|
||||
#define lua_stdin_is_tty() isatty(0)
|
||||
#define lua_stdin_is_tty() isatty(0)
|
||||
#elif defined(LUA_WIN)
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
|
||||
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
|
||||
#else
|
||||
#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
|
||||
#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
|
||||
#endif
|
||||
|
||||
|
||||
@@ -66,19 +66,19 @@
|
||||
#include <stdio.h>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
|
||||
#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
|
||||
#define lua_saveline(L,idx) \
|
||||
if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \
|
||||
add_history(lua_tostring(L, idx)); /* add it to history */
|
||||
#define lua_freeline(L,b) ((void)L, free(b))
|
||||
#define lua_freeline(L,b) ((void)L, free(b))
|
||||
|
||||
#elif !defined(lua_readline)
|
||||
|
||||
#define lua_readline(L,b,p) \
|
||||
#define lua_readline(L,b,p) \
|
||||
((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
|
||||
fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
|
||||
#define lua_saveline(L,idx) { (void)L; (void)idx; }
|
||||
#define lua_freeline(L,b) { (void)L; (void)b; }
|
||||
#define lua_saveline(L,idx) { (void)L; (void)idx; }
|
||||
#define lua_freeline(L,b) { (void)L; (void)b; }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -223,11 +223,16 @@ static int dostring (lua_State *L, const char *s, const char *name) {
|
||||
|
||||
static int dolibrary (lua_State *L, const char *name) {
|
||||
int status;
|
||||
lua_getglobal(L, "require");
|
||||
lua_pushglobaltable(L);
|
||||
lua_getfield(L, -1, "require");
|
||||
lua_pushstring(L, name);
|
||||
status = docall(L, 1, 1); /* call 'require(name)' */
|
||||
if (status == LUA_OK)
|
||||
lua_setglobal(L, name); /* global[name] = require return */
|
||||
status = docall(L, 1, 1);
|
||||
if (status == LUA_OK) {
|
||||
lua_setfield(L, -2, name); /* global[name] = require return */
|
||||
lua_pop(L, 1); /* remove global table */
|
||||
}
|
||||
else
|
||||
lua_remove(L, -2); /* remove global table (below error msg.) */
|
||||
return report(L, status);
|
||||
}
|
||||
|
||||
@@ -237,6 +242,7 @@ static const char *get_prompt (lua_State *L, int firstline) {
|
||||
lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
|
||||
p = lua_tostring(L, -1);
|
||||
if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
|
||||
lua_pop(L, 1); /* remove global */
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -262,9 +268,7 @@ static int pushline (lua_State *L, int firstline) {
|
||||
char *b = buffer;
|
||||
size_t l;
|
||||
const char *prmt = get_prompt(L, firstline);
|
||||
int readstatus = lua_readline(L, b, prmt);
|
||||
lua_pop(L, 1); /* remove result from 'get_prompt' */
|
||||
if (readstatus == 0)
|
||||
if (lua_readline(L, b, prmt) == 0)
|
||||
return 0; /* no input */
|
||||
l = strlen(b);
|
||||
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
|
||||
|
||||
13
lua.h
13
lua.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lua.h,v 1.285.1.3 2014/05/07 14:15:55 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.281 2011/10/24 16:53:05 roberto Exp roberto $
|
||||
** Lua - A Scripting Language
|
||||
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
|
||||
** See Copyright Notice at the end of this file
|
||||
@@ -19,11 +19,11 @@
|
||||
#define LUA_VERSION_MAJOR "5"
|
||||
#define LUA_VERSION_MINOR "2"
|
||||
#define LUA_VERSION_NUM 502
|
||||
#define LUA_VERSION_RELEASE "4"
|
||||
#define LUA_VERSION_RELEASE "0"
|
||||
|
||||
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
|
||||
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
|
||||
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
|
||||
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2011 Lua.org, PUC-Rio"
|
||||
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
|
||||
|
||||
|
||||
@@ -119,11 +119,6 @@ typedef LUA_UNSIGNED lua_Unsigned;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** RCS ident string
|
||||
*/
|
||||
extern const char lua_ident[];
|
||||
|
||||
|
||||
/*
|
||||
** state manipulation
|
||||
@@ -418,7 +413,7 @@ struct lua_Debug {
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright (C) 1994-2015 Lua.org, PUC-Rio.
|
||||
* Copyright (C) 1994-2011 Lua.org, PUC-Rio. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
|
||||
128
luaconf.h
128
luaconf.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: luaconf.h,v 1.176.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** $Id: luaconf.h,v 1.169 2011/11/30 12:35:05 roberto Exp roberto $
|
||||
** Configuration file for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -44,7 +44,7 @@
|
||||
#define LUA_USE_POSIX
|
||||
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
|
||||
#define LUA_USE_READLINE /* needs some extra libraries */
|
||||
#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
|
||||
#define LUA_USE_STRTODHEX /* assume 'strtod' handles hexa formats */
|
||||
#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
|
||||
#define LUA_USE_LONGLONG /* assume support for long long */
|
||||
#endif
|
||||
@@ -53,7 +53,7 @@
|
||||
#define LUA_USE_POSIX
|
||||
#define LUA_USE_DLOPEN /* does not need -ldl */
|
||||
#define LUA_USE_READLINE /* needs an extra library: -lreadline */
|
||||
#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
|
||||
#define LUA_USE_STRTODHEX /* assume 'strtod' handles hexa formats */
|
||||
#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
|
||||
#define LUA_USE_LONGLONG /* assume support for long long */
|
||||
#endif
|
||||
@@ -223,13 +223,6 @@
|
||||
(fprintf(stderr, (s), (p)), fflush(stderr))
|
||||
|
||||
|
||||
/*
|
||||
@@ LUAI_MAXSHORTLEN is the maximum length for short strings, that is,
|
||||
** strings that are internalized. (Cannot be smaller than reserved words
|
||||
** or tags for metamethods, as these strings must be internalized;
|
||||
** #("function") = 8, #("__newindex") = 10.)
|
||||
*/
|
||||
#define LUAI_MAXSHORTLEN 40
|
||||
|
||||
|
||||
|
||||
@@ -326,7 +319,7 @@
|
||||
|
||||
|
||||
/*
|
||||
@@ LUA_INT32 is a signed integer with exactly 32 bits.
|
||||
@@ LUA_INT32 is an signed integer with exactly 32 bits.
|
||||
@@ LUAI_UMEM is an unsigned integer big enough to count the total
|
||||
@* memory used by Lua.
|
||||
@@ LUAI_MEM is a signed integer big enough to count the total memory
|
||||
@@ -350,7 +343,7 @@
|
||||
/*
|
||||
@@ LUAI_MAXSTACK limits the size of the Lua stack.
|
||||
** CHANGE it if you need a different limit. This limit is arbitrary;
|
||||
** its only purpose is to stop Lua from consuming unlimited stack
|
||||
** its only purpose is to stop Lua to consume unlimited stack
|
||||
** space (and to reserve some numbers for pseudo-indices).
|
||||
*/
|
||||
#if LUAI_BITSINT >= 32
|
||||
@@ -405,16 +398,10 @@
|
||||
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
|
||||
|
||||
|
||||
/*
|
||||
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations
|
||||
*/
|
||||
#define l_mathop(x) (x)
|
||||
|
||||
|
||||
/*
|
||||
@@ lua_str2number converts a decimal numeric string to a number.
|
||||
@@ lua_strx2number converts an hexadecimal numeric string to a number.
|
||||
** In C99, 'strtod' does both conversions. C89, however, has no function
|
||||
** In C99, 'strtod' do both conversions. C89, however, has no function
|
||||
** to convert floating hexadecimal strings to numbers. For these
|
||||
** systems, you can leave 'lua_strx2number' undefined and Lua will
|
||||
** provide its own implementation.
|
||||
@@ -433,8 +420,8 @@
|
||||
/* the following operations need the math library */
|
||||
#if defined(lobject_c) || defined(lvm_c)
|
||||
#include <math.h>
|
||||
#define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b))
|
||||
#define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
|
||||
#define luai_nummod(L,a,b) ((a) - floor((a)/(b))*(b))
|
||||
#define luai_numpow(L,a,b) (pow(a,b))
|
||||
#endif
|
||||
|
||||
/* these are quite standard operations */
|
||||
@@ -466,76 +453,67 @@
|
||||
#define LUA_UNSIGNED unsigned LUA_INT32
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Some tricks with doubles
|
||||
*/
|
||||
#if defined(LUA_CORE) /* { */
|
||||
|
||||
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
|
||||
/*
|
||||
** The next definitions activate some tricks to speed up the
|
||||
** conversion from doubles to integer types, mainly to LUA_UNSIGNED.
|
||||
**
|
||||
@@ LUA_MSASMTRICK uses Microsoft assembler to avoid clashes with a
|
||||
** DirectX idiosyncrasy.
|
||||
**
|
||||
@@ LUA_IEEE754TRICK uses a trick that should work on any machine
|
||||
** using IEEE754 with a 32-bit integer type.
|
||||
**
|
||||
@@ LUA_IEEELL extends the trick to LUA_INTEGER; should only be
|
||||
** defined when LUA_INTEGER is a 32-bit integer.
|
||||
**
|
||||
@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
|
||||
** (0 for little endian, 1 for big endian); if not defined, Lua will
|
||||
** check it dynamically for LUA_IEEE754TRICK (but not for LUA_NANTRICK).
|
||||
**
|
||||
@@ LUA_NANTRICK controls the use of a trick to pack all types into
|
||||
** a single double value, using NaN values to represent non-number
|
||||
** values. The trick only works on 32-bit machines (ints and pointers
|
||||
** are 32-bit values) with numbers represented as IEEE 754-2008 doubles
|
||||
** with conventional endianess (12345678 or 87654321), in CPUs that do
|
||||
** not produce signaling NaN values (all NaNs are quiet).
|
||||
*/
|
||||
|
||||
/* Microsoft compiler on a Pentium (32 bit) ? */
|
||||
/* On a Microsoft compiler on a Pentium, use assembler to avoid clashes
|
||||
with a DirectX idiosyncrasy */
|
||||
#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
|
||||
|
||||
#define LUA_MSASMTRICK
|
||||
#define LUA_IEEEENDIAN 0
|
||||
#define LUA_NANTRICK
|
||||
#define MS_ASMTRICK
|
||||
|
||||
|
||||
/* pentium 32 bits? */
|
||||
#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */
|
||||
#else /* }{ */
|
||||
/* the next definition uses a trick that should work on any machine
|
||||
using IEEE754 with a 32-bit integer type */
|
||||
|
||||
#define LUA_IEEE754TRICK
|
||||
#define LUA_IEEELL
|
||||
#define LUA_IEEEENDIAN 0
|
||||
#define LUA_NANTRICK
|
||||
|
||||
/* pentium 64 bits? */
|
||||
#elif defined(__x86_64) /* }{ */
|
||||
/*
|
||||
@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
|
||||
** (0 for little endian, 1 for big endian); if not defined, Lua will
|
||||
** check it dynamically.
|
||||
*/
|
||||
/* check for known architectures */
|
||||
#if defined(__i386__) || defined(__i386) || defined(__X86__) || \
|
||||
defined (__x86_64)
|
||||
#define LUA_IEEEENDIAN 0
|
||||
#elif defined(__POWERPC__) || defined(__ppc__)
|
||||
#define LUA_IEEEENDIAN 1
|
||||
#endif
|
||||
|
||||
#define LUA_IEEE754TRICK
|
||||
#define LUA_IEEEENDIAN 0
|
||||
#endif /* } */
|
||||
|
||||
#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
|
||||
#endif /* } */
|
||||
|
||||
#define LUA_IEEE754TRICK
|
||||
#define LUA_IEEEENDIAN 1
|
||||
|
||||
#else /* }{ */
|
||||
|
||||
/* assume IEEE754 and a 32-bit integer type */
|
||||
#define LUA_IEEE754TRICK
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#endif /* } */
|
||||
#endif /* } */
|
||||
|
||||
/* }================================================================== */
|
||||
|
||||
|
||||
/*
|
||||
@@ LUA_NANTRICK_LE/LUA_NANTRICK_BE controls the use of a trick to
|
||||
** pack all types into a single double value, using NaN values to
|
||||
** represent non-number values. The trick only works on 32-bit machines
|
||||
** (ints and pointers are 32-bit values) with numbers represented as
|
||||
** IEEE 754-2008 doubles with conventional endianess (12345678 or
|
||||
** 87654321), in CPUs that do not produce signaling NaN values (all NaNs
|
||||
** are quiet).
|
||||
*/
|
||||
#if defined(LUA_CORE) && \
|
||||
defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
|
||||
|
||||
/* little-endian architectures that satisfy those conditions */
|
||||
#if defined(__i386__) || defined(__i386) || defined(__X86__) || \
|
||||
defined(_M_IX86)
|
||||
|
||||
#define LUA_NANTRICK_LE
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* } */
|
||||
|
||||
|
||||
|
||||
|
||||
/* =================================================================== */
|
||||
|
||||
2
lualib.h
2
lualib.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lualib.h,v 1.43 2011/12/08 12:11:37 roberto Exp $
|
||||
** $Id: lualib.h,v 1.42 2011/05/25 14:12:28 roberto Exp roberto $
|
||||
** Lua standard libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
38
lundump.c
38
lundump.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lundump.c,v 2.22 2012/05/08 13:53:33 roberto Exp $
|
||||
** $Id: lundump.c,v 1.71 2011/12/07 10:39:12 lhf Exp lhf $
|
||||
** load precompiled Lua chunks
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -27,7 +27,7 @@ typedef struct {
|
||||
const char* name;
|
||||
} LoadState;
|
||||
|
||||
static l_noret error(LoadState* S, const char* why)
|
||||
static void error(LoadState* S, const char* why)
|
||||
{
|
||||
luaO_pushfstring(S->L,"%s: %s precompiled chunk",S->name,why);
|
||||
luaD_throw(S->L,LUA_ERRSYNTAX);
|
||||
@@ -39,7 +39,7 @@ static l_noret error(LoadState* S, const char* why)
|
||||
#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
|
||||
|
||||
#if !defined(luai_verifycode)
|
||||
#define luai_verifycode(L,b,f) /* empty */
|
||||
#define luai_verifycode(L,b,f) (f)
|
||||
#endif
|
||||
|
||||
static void LoadBlock(LoadState* S, void* b, size_t size)
|
||||
@@ -91,7 +91,7 @@ static void LoadCode(LoadState* S, Proto* f)
|
||||
LoadVector(S,f->code,n,sizeof(Instruction));
|
||||
}
|
||||
|
||||
static void LoadFunction(LoadState* S, Proto* f);
|
||||
static Proto* LoadFunction(LoadState* S);
|
||||
|
||||
static void LoadConstants(LoadState* S, Proto* f)
|
||||
{
|
||||
@@ -118,18 +118,13 @@ static void LoadConstants(LoadState* S, Proto* f)
|
||||
case LUA_TSTRING:
|
||||
setsvalue2n(S->L,o,LoadString(S));
|
||||
break;
|
||||
default: lua_assert(0);
|
||||
}
|
||||
}
|
||||
n=LoadInt(S);
|
||||
f->p=luaM_newvector(S->L,n,Proto*);
|
||||
f->sizep=n;
|
||||
for (i=0; i<n; i++) f->p[i]=NULL;
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
f->p[i]=luaF_newproto(S->L);
|
||||
LoadFunction(S,f->p[i]);
|
||||
}
|
||||
for (i=0; i<n; i++) f->p[i]=LoadFunction(S);
|
||||
}
|
||||
|
||||
static void LoadUpvalues(LoadState* S, Proto* f)
|
||||
@@ -168,8 +163,10 @@ static void LoadDebug(LoadState* S, Proto* f)
|
||||
for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
|
||||
}
|
||||
|
||||
static void LoadFunction(LoadState* S, Proto* f)
|
||||
static Proto* LoadFunction(LoadState* S)
|
||||
{
|
||||
Proto* f=luaF_newproto(S->L);
|
||||
setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
|
||||
f->linedefined=LoadInt(S);
|
||||
f->lastlinedefined=LoadInt(S);
|
||||
f->numparams=LoadByte(S);
|
||||
@@ -179,6 +176,8 @@ static void LoadFunction(LoadState* S, Proto* f)
|
||||
LoadConstants(S,f);
|
||||
LoadUpvalues(S,f);
|
||||
LoadDebug(S,f);
|
||||
S->L->top--;
|
||||
return f;
|
||||
}
|
||||
|
||||
/* the code below must be consistent with the code in luaU_header */
|
||||
@@ -203,10 +202,9 @@ static void LoadHeader(LoadState* S)
|
||||
/*
|
||||
** load precompiled chunk
|
||||
*/
|
||||
Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
|
||||
Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
|
||||
{
|
||||
LoadState S;
|
||||
Closure* cl;
|
||||
if (*name=='@' || *name=='=')
|
||||
S.name=name+1;
|
||||
else if (*name==LUA_SIGNATURE[0])
|
||||
@@ -217,19 +215,7 @@ Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
|
||||
S.Z=Z;
|
||||
S.b=buff;
|
||||
LoadHeader(&S);
|
||||
cl=luaF_newLclosure(L,1);
|
||||
setclLvalue(L,L->top,cl); incr_top(L);
|
||||
cl->l.p=luaF_newproto(L);
|
||||
LoadFunction(&S,cl->l.p);
|
||||
if (cl->l.p->sizeupvalues != 1)
|
||||
{
|
||||
Proto* p=cl->l.p;
|
||||
cl=luaF_newLclosure(L,cl->l.p->sizeupvalues);
|
||||
cl->l.p=p;
|
||||
setclLvalue(L,L->top-1,cl);
|
||||
}
|
||||
luai_verifycode(L,buff,cl->l.p);
|
||||
return cl;
|
||||
return luai_verifycode(L,buff,LoadFunction(&S));
|
||||
}
|
||||
|
||||
#define MYINT(s) (s[0]-'0')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lundump.h,v 1.39 2012/05/08 13:53:33 roberto Exp $
|
||||
** $Id: lundump.h,v 1.44 2011/05/06 13:35:17 lhf Exp $
|
||||
** load precompiled Lua chunks
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "lzio.h"
|
||||
|
||||
/* load one chunk; from lundump.c */
|
||||
LUAI_FUNC Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
|
||||
LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
|
||||
|
||||
/* make header; from lundump.c */
|
||||
LUAI_FUNC void luaU_header (lu_byte* h);
|
||||
|
||||
53
lvm.c
53
lvm.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.c,v 2.155 2013/03/16 21:10:18 roberto Exp $
|
||||
** $Id: lvm.c,v 2.146 2011/11/29 15:54:38 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -60,15 +60,10 @@ int luaV_tostring (lua_State *L, StkId obj) {
|
||||
static void traceexec (lua_State *L) {
|
||||
CallInfo *ci = L->ci;
|
||||
lu_byte mask = L->hookmask;
|
||||
int counthook = ((mask & LUA_MASKCOUNT) && L->hookcount == 0);
|
||||
if (counthook)
|
||||
resethookcount(L); /* reset count */
|
||||
if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
|
||||
ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
|
||||
return; /* do not call hook again (VM yielded, so it did not move) */
|
||||
if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
|
||||
resethookcount(L);
|
||||
luaD_hook(L, LUA_HOOKCOUNT, -1);
|
||||
}
|
||||
if (counthook)
|
||||
luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */
|
||||
if (mask & LUA_MASKLINE) {
|
||||
Proto *p = ci_func(ci)->p;
|
||||
int npc = pcRel(ci->u.l.savedpc, p);
|
||||
@@ -76,15 +71,11 @@ static void traceexec (lua_State *L) {
|
||||
if (npc == 0 || /* call linehook when enter a new function, */
|
||||
ci->u.l.savedpc <= L->oldpc || /* when jump back (loop), or when */
|
||||
newline != getfuncline(p, pcRel(L->oldpc, p))) /* enter a new line */
|
||||
luaD_hook(L, LUA_HOOKLINE, newline); /* call line hook */
|
||||
luaD_hook(L, LUA_HOOKLINE, newline);
|
||||
}
|
||||
L->oldpc = ci->u.l.savedpc;
|
||||
if (L->status == LUA_YIELD) { /* did hook yield? */
|
||||
if (counthook)
|
||||
L->hookcount = 1; /* undo decrement to zero */
|
||||
ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
|
||||
ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
|
||||
ci->func = L->top - 1; /* protect stack below results */
|
||||
luaD_throw(L, LUA_YIELD);
|
||||
}
|
||||
}
|
||||
@@ -98,6 +89,7 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1,
|
||||
setobj2s(L, L->top++, p2); /* 2nd argument */
|
||||
if (!hasres) /* no result? 'p3' is third argument */
|
||||
setobj2s(L, L->top++, p3); /* 3rd argument */
|
||||
luaD_checkstack(L, 0);
|
||||
/* metamethod may yield only when called from Lua code */
|
||||
luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci));
|
||||
if (hasres) { /* if has result, move it to its place */
|
||||
@@ -266,8 +258,7 @@ int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) {
|
||||
case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
|
||||
case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
|
||||
case LUA_TLCF: return fvalue(t1) == fvalue(t2);
|
||||
case LUA_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2));
|
||||
case LUA_TLNGSTR: return luaS_eqlngstr(rawtsvalue(t1), rawtsvalue(t2));
|
||||
case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2));
|
||||
case LUA_TUSERDATA: {
|
||||
if (uvalue(t1) == uvalue(t2)) return 1;
|
||||
else if (L == NULL) return 0;
|
||||
@@ -302,7 +293,7 @@ void luaV_concat (lua_State *L, int total) {
|
||||
else if (tsvalue(top-1)->len == 0) /* second operand is empty? */
|
||||
(void)tostring(L, top - 2); /* result is first operand */
|
||||
else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) {
|
||||
setobjs2s(L, top - 2, top - 1); /* result is second op. */
|
||||
setsvalue2s(L, top-2, rawtsvalue(top-1)); /* result is second op. */
|
||||
}
|
||||
else {
|
||||
/* at least two non-empty string values; get as many as possible */
|
||||
@@ -403,8 +394,7 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
|
||||
int nup = p->sizeupvalues;
|
||||
Upvaldesc *uv = p->upvalues;
|
||||
int i;
|
||||
Closure *ncl = luaF_newLclosure(L, nup);
|
||||
ncl->l.p = p;
|
||||
Closure *ncl = luaF_newLclosure(L, p);
|
||||
setclLvalue(L, ra, ncl); /* anchor new closure in stack */
|
||||
for (i = 0; i < nup; i++) { /* fill in its upvalues */
|
||||
if (uv[i].instack) /* upvalue refers to local variable? */
|
||||
@@ -469,7 +459,7 @@ void luaV_finishOp (lua_State *L) {
|
||||
L->top = ci->top; /* adjust results */
|
||||
break;
|
||||
}
|
||||
case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
|
||||
case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
|
||||
break;
|
||||
default: lua_assert(0);
|
||||
}
|
||||
@@ -510,11 +500,7 @@ void luaV_finishOp (lua_State *L) {
|
||||
|
||||
#define Protect(x) { {x;}; base = ci->u.l.base; }
|
||||
|
||||
#define checkGC(L,c) \
|
||||
Protect( luaC_condGC(L,{L->top = (c); /* limit of live values */ \
|
||||
luaC_step(L); \
|
||||
L->top = ci->top;}) /* restore top */ \
|
||||
luai_threadyield(L); )
|
||||
#define checkGC(L,c) Protect(luaC_condGC(L, c); luai_threadyield(L);)
|
||||
|
||||
|
||||
#define arith_op(op,tm) { \
|
||||
@@ -607,7 +593,11 @@ void luaV_execute (lua_State *L) {
|
||||
sethvalue(L, ra, t);
|
||||
if (b != 0 || c != 0)
|
||||
luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));
|
||||
checkGC(L, ra + 1);
|
||||
checkGC(L,
|
||||
L->top = ra + 1; /* limit of live values */
|
||||
luaC_step(L);
|
||||
L->top = ci->top; /* restore top */
|
||||
)
|
||||
)
|
||||
vmcase(OP_SELF,
|
||||
StkId rb = RB(i);
|
||||
@@ -659,7 +649,10 @@ void luaV_execute (lua_State *L) {
|
||||
ra = RA(i); /* 'luav_concat' may invoke TMs and move the stack */
|
||||
rb = b + base;
|
||||
setobjs2s(L, ra, rb);
|
||||
checkGC(L, (ra >= rb ? ra + 1 : rb));
|
||||
checkGC(L,
|
||||
L->top = (ra >= rb ? ra + 1 : rb); /* limit of live values */
|
||||
luaC_step(L);
|
||||
)
|
||||
L->top = ci->top; /* restore top */
|
||||
)
|
||||
vmcase(OP_JMP,
|
||||
@@ -837,7 +830,11 @@ void luaV_execute (lua_State *L) {
|
||||
pushclosure(L, p, cl->upvals, base, ra); /* create a new one */
|
||||
else
|
||||
setclLvalue(L, ra, ncl); /* push cashed closure */
|
||||
checkGC(L, ra + 1);
|
||||
checkGC(L,
|
||||
L->top = ra + 1; /* limit of live values */
|
||||
luaC_step(L);
|
||||
L->top = ci->top; /* restore top */
|
||||
)
|
||||
)
|
||||
vmcase(OP_VARARG,
|
||||
int b = GETARG_B(i) - 1;
|
||||
|
||||
5
lvm.h
5
lvm.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.h,v 2.18 2013/01/08 14:06:55 roberto Exp $
|
||||
** $Id: lvm.h,v 2.16 2011/05/31 18:24:36 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -19,7 +19,8 @@
|
||||
|
||||
#define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalobj_(L, o1, o2))
|
||||
|
||||
#define luaV_rawequalobj(o1,o2) equalobj(NULL,o1,o2)
|
||||
#define luaV_rawequalobj(t1,t2) \
|
||||
(ttisequal(t1,t2) && luaV_equalobj_(NULL,t1,t2))
|
||||
|
||||
|
||||
/* not to called directly */
|
||||
|
||||
4
lzio.c
4
lzio.c
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
** $Id: lzio.c,v 1.35 2012/05/14 13:34:18 roberto Exp $
|
||||
** Buffered streams
|
||||
** $Id: lzio.c,v 1.33 2011/02/23 13:13:10 roberto Exp roberto $
|
||||
** a generic input stream interface
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
|
||||
2
lzio.h
2
lzio.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lzio.h,v 1.26 2011/07/15 12:48:03 roberto Exp $
|
||||
** $Id: lzio.h,v 1.25 2011/07/15 12:35:32 roberto Exp roberto $
|
||||
** Buffered streams
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
154
makefile
154
makefile
@@ -4,36 +4,60 @@
|
||||
|
||||
# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
|
||||
|
||||
CWARNS= -pedantic -Waggregate-return -Wcast-align \
|
||||
-Wmissing-prototypes -Wpointer-arith -Wshadow \
|
||||
-Wsign-compare -Wstrict-prototypes -Wundef -Wwrite-strings
|
||||
# -Wcast-qual
|
||||
CWARNSC=-pedantic -Wextra \
|
||||
-Waggregate-return \
|
||||
-Wcast-align \
|
||||
-Wdisabled-optimization \
|
||||
-Wpointer-arith \
|
||||
-Wshadow \
|
||||
-Wsign-compare \
|
||||
-Wundef \
|
||||
-Wwrite-strings \
|
||||
-Wredundant-decls \
|
||||
-Wdisabled-optimization \
|
||||
-Wstrict-aliasing \
|
||||
# the next warnings generate to much noise, so they are disabled
|
||||
# -Wlogical-op \
|
||||
# -Wstrict-overflow=2 \
|
||||
# -Wformat=2 \
|
||||
# -Wcast-qual \
|
||||
|
||||
# -DEXTERNMEMCHECK -DHARDSTACKTESTS
|
||||
# The next warnings are not valid for C++
|
||||
CWARNS= $(CWARNSC) \
|
||||
-Wdeclaration-after-statement \
|
||||
-Wmissing-prototypes \
|
||||
-Wnested-externs \
|
||||
-Wstrict-prototypes \
|
||||
-Wc++-compat \
|
||||
-Wold-style-definition \
|
||||
|
||||
|
||||
# -DEXTERNMEMCHECK -DHARDSTACKTESTS -DHARDMEMTESTS -DTRACEMEM='"tempmem"'
|
||||
# -g -DLUA_USER_H='"ltests.h"'
|
||||
# -fomit-frame-pointer #-pg -malign-double
|
||||
TESTS= -g -DLUA_USER_H='"ltests.h"'
|
||||
# -DLUA_USE_CTYPE -DLUA_USE_APICHECK
|
||||
TESTS= -DLUA_USER_H='"ltests.h"'
|
||||
|
||||
LOCAL = $(TESTS) $(CWARNS)
|
||||
# -mtune=native -fomit-frame-pointer
|
||||
LOCAL = $(TESTS) $(CWARNS) -g
|
||||
|
||||
|
||||
CC= gcc
|
||||
CFLAGS= -Wall $(MYCFLAGS) -O2
|
||||
AR= ar rcu
|
||||
RANLIB= ranlib
|
||||
RM= rm -f
|
||||
|
||||
MYCFLAGS= $(LOCAL)
|
||||
MYLDFLAGS=
|
||||
MYLIBS=
|
||||
|
||||
|
||||
# enable Linux goodies
|
||||
MYCFLAGS= $(LOCAL) -DLUA_USE_LINUX
|
||||
MYLDFLAGS= -Wl,-E
|
||||
MYCFLAGS= $(LOCAL) -DLUA_USE_LINUX -DLUA_COMPAT_ALL
|
||||
MYLDFLAGS= $(LOCAL) -Wl,-E
|
||||
MYLIBS= -ldl -lreadline -lhistory -lncurses
|
||||
|
||||
|
||||
CC= gcc
|
||||
CFLAGS= -Wall -O2 $(MYCFLAGS)
|
||||
# CC= ~lhf/sunstudio12/bin/cc
|
||||
# CFLAGS= -xO5 -v -Xc -native -xstrconst
|
||||
AR= ar rcu
|
||||
RANLIB= ranlib
|
||||
RM= rm -f
|
||||
|
||||
|
||||
|
||||
# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
|
||||
|
||||
@@ -41,18 +65,18 @@ MYLIBS= -ldl -lreadline -lhistory -lncurses
|
||||
LIBS = -lm
|
||||
|
||||
CORE_T= liblua.a
|
||||
CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
|
||||
lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
|
||||
lundump.o lvm.o lzio.o ltests.o
|
||||
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
|
||||
lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
|
||||
ltm.o lundump.o lvm.o lzio.o ltests.o
|
||||
AUX_O= lauxlib.o
|
||||
LIB_O= lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o \
|
||||
loadlib.o linit.o
|
||||
lbitlib.o loadlib.o lcorolib.o linit.o
|
||||
|
||||
LUA_T= lua
|
||||
LUA_O= lua.o
|
||||
|
||||
LUAC_T= luac
|
||||
LUAC_O= luac.o print.o
|
||||
# LUAC_T= luac
|
||||
# LUAC_O= luac.o print.o
|
||||
|
||||
ALL_T= $(CORE_T) $(LUA_T) $(LUAC_T)
|
||||
ALL_O= $(CORE_O) $(LUA_O) $(LUAC_O) $(AUX_O) $(LIB_O)
|
||||
@@ -92,64 +116,70 @@ echo:
|
||||
@echo "MYLIBS = $(MYLIBS)"
|
||||
@echo "DL = $(DL)"
|
||||
|
||||
# DO NOT DELETE
|
||||
$(ALL_O): makefile
|
||||
|
||||
lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \
|
||||
lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \
|
||||
lundump.h lvm.h
|
||||
# DO NOT DELETE
|
||||
# automatically made with 'gcc -MM'
|
||||
|
||||
lapi.o: lapi.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h ltm.h \
|
||||
lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h ltable.h lundump.h \
|
||||
lvm.h
|
||||
lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
|
||||
lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
|
||||
lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
|
||||
ldo.h lgc.h
|
||||
lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
|
||||
lstring.h ltable.h
|
||||
lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lctype.o: lctype.c lctype.h lua.h luaconf.h llimits.h
|
||||
ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \
|
||||
llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \
|
||||
ltm.h ldo.h lfunc.h lstring.h lgc.h lvm.h
|
||||
ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
|
||||
lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \
|
||||
lstring.h lundump.h lvm.h
|
||||
ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lopcodes.h lstate.h \
|
||||
ltm.h lzio.h lmem.h lundump.h
|
||||
lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
|
||||
lstate.h ltm.h lzio.h
|
||||
ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
|
||||
ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \
|
||||
lfunc.h lstring.h lgc.h ltable.h lvm.h
|
||||
ldo.o: ldo.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h ltm.h \
|
||||
lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h \
|
||||
lstring.h ltable.h lundump.h lvm.h
|
||||
ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
|
||||
lzio.h lmem.h lundump.h
|
||||
lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h \
|
||||
lstate.h ltm.h lzio.h lmem.h
|
||||
lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
|
||||
lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
|
||||
lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
|
||||
linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h
|
||||
liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \
|
||||
lzio.h lmem.h llex.h lparser.h ltable.h lstring.h lgc.h
|
||||
llex.o: llex.c lua.h luaconf.h lctype.h llimits.h ldo.h lobject.h \
|
||||
lstate.h ltm.h lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h
|
||||
lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
|
||||
ltm.h lzio.h lmem.h ldo.h
|
||||
ltm.h lzio.h lmem.h ldo.h lgc.h
|
||||
loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
|
||||
ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
|
||||
lopcodes.o: lopcodes.c lua.h luaconf.h lobject.h llimits.h lopcodes.h
|
||||
lobject.o: lobject.c lua.h luaconf.h lctype.h llimits.h ldebug.h lstate.h \
|
||||
lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h
|
||||
lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h
|
||||
loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
|
||||
lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
|
||||
ldo.h lfunc.h lstring.h lgc.h
|
||||
lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
|
||||
ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h
|
||||
lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lfunc.h \
|
||||
lstring.h lgc.h ltable.h
|
||||
lstate.o: lstate.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
|
||||
ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h lstring.h \
|
||||
ltable.h
|
||||
lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \
|
||||
ltm.h lzio.h lstring.h lgc.h
|
||||
ltm.h lzio.h lstring.h lgc.h
|
||||
lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
|
||||
ltm.h lzio.h lmem.h ldo.h lgc.h ltable.h
|
||||
ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h
|
||||
ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
ltests.o: ltests.c lua.h luaconf.h lapi.h lobject.h llimits.h lauxlib.h \
|
||||
lcode.h llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h \
|
||||
lstate.h ltm.h ldo.h lfunc.h lstring.h lgc.h lualib.h
|
||||
ltests.o: ltests.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \
|
||||
ltm.h lzio.h lmem.h lauxlib.h lcode.h llex.h lopcodes.h lparser.h \
|
||||
lctype.h ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lualib.h
|
||||
ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
|
||||
lmem.h lstring.h lgc.h ltable.h
|
||||
lmem.h lstring.h lgc.h ltable.h
|
||||
lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h
|
||||
lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
|
||||
llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h \
|
||||
lundump.h
|
||||
llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
|
||||
lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
|
||||
lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
|
||||
lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
|
||||
lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
|
||||
lzio.h
|
||||
lzio.h
|
||||
|
||||
# (end of Makefile)
|
||||
|
||||
Reference in New Issue
Block a user