lua-users home
lua-l archive

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


>How hard would it be to modify Lua source code
>to add "global" keyword for explicit declaration 
>of global variables and make all variables local
>by default?

Not very hard. But the main point is, do you really want to do this?
This has been discussed before; check the lua-l archives.

The main point is the following:
If all variables are local by default, then you have to declare all functions
as global. For instance:

global read,write,process

while 1 do
 local s=read()
 if s==nil then return end
 s=process(s)
 write(s)
end

Also, as Russ Webb noted, you can set tag methods do warn about unintentional
uses of globals (of course, this will only happen at run time).
Another possibility is to run luac -l and see what globals are used.
See etc/globals.lua.

>Current implementation of Lua uses opposite
>approach, but that approach is problematic
>for us because our scripters are not
>programmers and it seems there is no force
>which makes them remember that they always
>have to declare their variables as local.

Would they prefer to write global declarations for all functions??
--lhf