lua-users home
lua-l archive

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

Roberto Ierusalimschy wrote:
> - declaration of globals: we introduced global declarations:
>     global a,b,c
>     global a,b,c in T

I'm just curious when the first people ask for an include statement
to import globals.

> It would be good to have some scheme to "pre-declare" some identifiers...

Oh, you are the first one ;-)

>     global in T        -- change the default

Just some clarifications: I assume that 'global in T' is a pure lexical
declaration and not the same as 'globals(T)'.  Right?

And the other one: is 'global in nil' detected at compile time and
gives errors for undeclared variables? (At least in this special form
where nil is explicitely given?)

Another possible feature that comes up is a variant that searches a
list of tables for a global (like 'global ... in T,U,V') but I think
that can easily be done with something like

  global ... in dictionary { T,U,V } -- [1]

so it's already possible and even pretty versatile.


I'm not sure if the global statement is the right thing.  It looks
nice for simple things but IMHO it does not help in bigger apps
where it would be mostly needed.  You _have_ to declare all globals
and doing that in each and every file could become annoying.  I guess
every file would start like this:

	global in nil
	global table, string, math, ...
	global require, error, assert, ...

	require "foo"	global foo
	require "bar"	global bar,bar2,bar3

I think, some day a combined 'require and global' (i.e. import) statement
is needed to make real use of it.  (like Modula?!?)

And at last: it doesn't make the lanugage easier...

Ciao, ET.

[1] with dictionary being:

local dict_meta = {
  __index = function(tbl, name)
    for i=1,getn(tbl)
      local val = tbl[i][name]
      if val then return val end

function dictionary(tbl)
  -- If a name is not present in tbl search for it in tbl[1..n].
  -- New names are stored in tbl itself.
  -- [Obbug: tbl.n]
  return metatable(tbl, dict_meta)