[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: disabling global definitions within function blocks
- From: "xenarcher <nickl@...>" <nickl@...>
- Date: Mon, 06 Jan 2003 22:25:03 -0000
Consider the following Lua code:
SomeVariable = 1
SomeVariabl = 0 -- NOTE THE TYPO!
If the user accidentally writes the above code, typo and all, I want
to be able to catch this as a bug. However, the default
implementation of Lua allows global variables to be defined anywhere.
As such, the above code is quite valid and simply creates a second
global variable, "SomeVariabl", alongside the original
My question is: is there an easy way to modify the Lua source to only
allow global variable definitions at the top level? (i.e.: outside
all code blocks, like C/C++) How would one go about doing this? There
must be some way to determine in the parser how many levels deep you
are. Even a simple assert to disallow the above code would be fine
for my purposes.