@@ -232,7 +232,7 @@ local ListFinishMap = {
232232 [' while' ] = true ,
233233}
234234
235- local State , Lua , Line , LineOffset , Chunk , Tokens , Index , LastTokenFinish , Mode , LocalCount
235+ local State , Lua , Line , LineOffset , Chunk , Tokens , Index , LastTokenFinish , Mode , LocalCount , LocalLimited
236236
237237local LocalLimit = 200
238238
@@ -728,7 +728,8 @@ local function createLocal(obj, attrs)
728728 end
729729 locals [# locals + 1 ] = obj
730730 LocalCount = LocalCount + 1
731- if LocalCount > LocalLimit then
731+ if not LocalLimited and LocalCount > LocalLimit then
732+ LocalLimited = true
732733 pushError {
733734 type = ' LOCAL_LIMIT' ,
734735 start = obj .start ,
@@ -2252,8 +2253,6 @@ local function parseFunction(isLocal, isAction)
22522253 },
22532254 }
22542255 Index = Index + 2
2255- local LastLocalCount = LocalCount
2256- LocalCount = 0
22572256 skipSpace (true )
22582257 local hasLeftParen = Tokens [Index + 1 ] == ' ('
22592258 if not hasLeftParen then
@@ -2289,6 +2288,8 @@ local function parseFunction(isLocal, isAction)
22892288 hasLeftParen = Tokens [Index + 1 ] == ' ('
22902289 end
22912290 end
2291+ local LastLocalCount = LocalCount
2292+ LocalCount = 0
22922293 pushChunk (func )
22932294 local params
22942295 if func .name and func .name .type == ' getmethod' then
@@ -2870,6 +2871,8 @@ local function compileExpAsAction(exp)
28702871 local isLocal
28712872 if exp .type == ' getlocal' and exp [1 ] == State .ENVMode then
28722873 exp .special = nil
2874+ -- TODO: need + 1 at the end
2875+ LocalCount = LocalCount - 1
28732876 local loc = createLocal (exp , parseLocalAttrs ())
28742877 loc .locPos = exp .start
28752878 loc .effect = maxinteger
@@ -3375,6 +3378,7 @@ local function parseFor()
33753378 missName ()
33763379 end
33773380 skipSpace ()
3381+ local forStateVars
33783382 -- for i =
33793383 if expectAssign () then
33803384 action .type = ' loop'
@@ -3389,6 +3393,9 @@ local function parseFor()
33893393 name = nameOrList [1 ]
33903394 end
33913395 end
3396+ -- for x in ... uses 4 variables
3397+ forStateVars = 3
3398+ LocalCount = LocalCount + forStateVars
33923399 if name then
33933400 local loc = createLocal (name )
33943401 loc .parent = action
@@ -3480,6 +3487,13 @@ local function parseFor()
34803487 missExp ()
34813488 end
34823489
3490+ if State .version == ' Lua 5.4' then
3491+ forStateVars = 4
3492+ else
3493+ forStateVars = 3
3494+ end
3495+ LocalCount = LocalCount + forStateVars
3496+
34833497 if list then
34843498 local lastName = list [# list ]
34853499 list .range = lastName and lastName .range or inRight
@@ -3541,6 +3555,9 @@ local function parseFor()
35413555 if action .locals then
35423556 LocalCount = LocalCount - # action .locals
35433557 end
3558+ if forStateVars then
3559+ LocalCount = LocalCount - forStateVars
3560+ end
35443561
35453562 return action
35463563end
@@ -3868,6 +3885,7 @@ local function initState(lua, version, options)
38683885 LineOffset = 1
38693886 LastTokenFinish = 0
38703887 LocalCount = 0
3888+ LocalLimited = false
38713889 Chunk = {}
38723890 Tokens = tokens (lua )
38733891 Index = 1
0 commit comments