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 Steve Litt once stated:
> On Fri, 26 Apr 2013 13:13:33 +0200
> Thomas Jericke <tjericke@indel.ch> wrote:
> 
> > To me there are still some problems regarding scoping with this,
> > consider:
> > 
> > if someboolean then
> >      global myvar = 0
> > end
> > 
> > print(myvar) -- Is this valid?
> 
> Why in the world would anyone do this? I can't think of any reason for a
> global variable's existence to be conditional.

  While not completely condition (it exists, or it doesn't), I do have the
following real code I use at work:

	module("picture",package.seeall)

	if pcall(require,"gd") then

	  function generate(picid,name,number)
	    -- code to generate a JPEG using the GD bindings
	    -- and return it with the picid
	  end

	else

	  function generate(picid,name,number)
	    -- code to return a copy of a JPEG
	    -- with the picid
	  end

	end

  Not all the systems I run this on have the GD bindings, and in those
cases, the actual picture is immaterial (for those, it's enough that *a*
picture with the given id exists than it does for it to be a particular
image).

  Yes, it's a weird requirement, but this is part of a regression test that
runs on several different platforms.

  -spc (Any more information about this, and I would have to kill you all 8-P