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 Soni L. once stated:
> 
> So in other words you want explicit upvalue syntax? Upvalues as part of 
> function signatures? Yeah me too! But I want it with defined order so my 
> loadx lib[1] becomes more useful.

  This would get quite annoying real quick.  Just as a test:

	local function foo(a,b)
	  return 3 * a + b 
	end

	local function bar(x)
	  print("debug")
	  return x * foo(3,2)
	end

	print(debug.getupvalue(bar,1))
	print(debug.getupvalue(bar,2))

		_ENV	table: 0x7fa971403c20
		foo	function: 0x7fa9714071d0

So, assuming some extention, say "@" for marking upvalues, this would have
to be written:

	local function foo(a,b)
	  return 3 * a + b
	end

	local function bar(x)@(_ENV,bar)
	  print("debug")
	  return x * foo(3,2)
	end

Then the code is changed a bit:

	local function snafu() ... end
	local function foo(a,b) ... end

	local function bar(x)@(_ENV,bar)
	  return snafu(x * foo(3,2)
	end

and you get an error because snafu is not declared for bar(), and you are
now pointlessly including a local no longer needed.

  -spc (Just my two zorkmids worth)