lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Coroutines once stated:
> On Mon, Apr 7, 2014 at 6:42 PM, Sean Conner <sean@conman.org> wrote:
> 
> > My concern about such a method---too many "imports" and you run out of
> > locals!  The limit for Lua 5.1, 5.2 and LuaJIT is 200 locals per scope
> > (I haven't tried Lua 5.3).  And it's not a simple change of the codebase
> > to increase the number of locals.
> >
> >   Which is why I think doing work to get what you want, however you
> > want, as a "proof-of-concept" is important.  It gives people something
> > to work with, to try out (much like Roberto & Co. is doing with Lua 5.3)
> > and possibly even break with stupid ideas like including 200 modules
> > into a single code base.  It could also lead to other questions, such
> > as, "why only into locals? What if I want some of the imports to be
> > global?"
> >
> 1) I belive the 'local limit' is 256.

  Did you not see where I said I didn't try it with Lua 5.3?  I took the
time to create code [1] that had a large number of locals and I got the
following:

Lua 5.1:

nil     [string "local x1 = 1..."]:201: main function has more than 200 local variables

Lua 5.2:

nil     [string "local x1 = 1..."]:201: too many local variables (limit is 200) in main function near '='

LuaJIT 2.0.3

nil     [string "local x1 = 1..."]:201: main function has more than 200 local variables

  And just to be pedantic:

Lua 5.3.0-work2:

nil     [string "local x1 = 1..."]:201: too many local variables (limit is 200) in main function near '='

  I know the limit is 200.

> 2) Locals have faster access over globals.

  I know that, and I never argued against using locals.  I just expressed
concern that importing a large number of modules might impact local usage. 
And while 200 locals might be considered "large enough" for normal usage,
not everybody is going to do normal things.

> 3) I linked my prototype a few replies ago, at least for creating globals:
> https://github.com/Pogs/lua-snippets/blob/master/import.lua

  And you did. So there is that.

  -spc

[1]	list = {}
	for i = 1 , 16384 do
	  list[#list + 1] = string.format("local x%d = %d",i,i)
	end

	list[#list + 1] = "print(x16384)"

	srccode = table.concat(list,"\n")
	print(loadstring(srccode))