lua-users home
lua-l archive

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

On Friday, June 1, 2001, at 06:54 PM, Edgar Toernig wrote:
Use this to catch assignments to undefined globals (=nil) instead:

	settagmethod(tag(nil), "setglobal", function(n,v) error(...) end)

Ah, thanks.
So would be a reasonable solution to the locals problem?:

settagmethod(tag(nil), "setglobal", function(i, v)
  local c = strsub(i, 1)
  local t = type(i)
  -- perform if function or class assignment
  if t == "function" or (c == strupper(c) and t == "table") then
    globals()[i] = v
  -- otherwise, raise error
  print("no such local variable: '"..i.."'")