lua-users home
lua-l archive

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


--- In lua-l@yahoogroups.com, "xenarcher <nickl@v...>" <nickl@v...> 
wrote:
> When foo() is called, no error occurs. Is there a way to propagate 
> "read-only globals" to all function calls (at any level 
> of nesting) following the setglobals() call?

Actually, I just figured out a way to do this, though it's a little 
hacky... I loop over all variables defined in the global table, and 
called setglobals() on each variable that is a function (*). This 
seems to work well.

Now there's one remaining problem I'd like to solve. Say you have the 
following:

SomeVariable = 1
AnotherVariable = 0

function SetAnotherVariable()
  AnotherVariable = SomeVariabl  -- NOTE THE TYPO!
end

The default behavior is to return nil for the undefined global. Is 
there a way I could flag this as an error instead?

(*) Trying to call setglobals() on a C function raises an error, 
since setglobals() may only be called on Lua functions. 
Unfortunately, there doesn't appear to be a built-in method of 
distinguishing C functions from Lua functions, so I had to provide my 
own custom method of doing so through the C API.