lua-users home
lua-l archive

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


On Mon, Apr 07, 2014 at 09:42:07PM -0400, Sean Conner wrote:
>   Now, my impression is that a statment like
> 
> 	import "math"
> 
> creates all the entries in the math module as locals (thus, the code
> presented), all to avoid (in my opinion) some typing.  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.

That could easily be avoided by having the import go to globals and having a
local variant. For example,

	import module1
	local import module2

And the same for getting sub-modules

  import func1, func2 from module4
	local import func3, func4 from module5

As has been pointed out, this could probably be done with a little bit of 
syntatic sugar, such as:

	import module1       == module1 = require("module1")
	local import module2 == local module2 = require("module2")

and for the sub-modules

	import func1, func2 from module3       == do
						      														local _ = require("module3")
									      											func1 = _.func1
												      								func2 = _.func2
															      				end
  
	local import func3, func4 from module4 == local func3, func4
																						do
						      														local _ = require("module4")
									      											func1 = _.func3
												      								func2 = _.func4
																						end

Aliasing the imports could also probably be handled easily with syntatic sugar.

-- 
Christopher Berardi
May grace and peace be yours in abundance.