From 682054920ddc434fd4a7f8cc78027dbb03f47f00 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 21 Mar 2019 16:01:55 -0300 Subject: Details in the implementation of the integer 'for' loop Changed some implementation details; in particular, it is back using an internal variable to keep the index, with the control variable being only a copy of that internal variable. (The direct use of the control variable demands a check of its type for each access, which offsets the gains from the use of a single variable.) --- testes/nextvar.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'testes') diff --git a/testes/nextvar.lua b/testes/nextvar.lua index e769ccdd..87a6bfa8 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua @@ -544,6 +544,12 @@ do a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1) end +do -- changing the control variable + local a + a = 0; for i = 1, 10 do a = a + 1; i = "x" end; assert(a == 10) + a = 0; for i = 10.0, 1, -1 do a = a + 1; i = "x" end; assert(a == 10) +end + -- conversion a = 0; for i="10","1","-2" do a=a+1 end; assert(a==5) -- cgit v1.2.3-55-g6feb