I really love Lua as a programming language BUT, it bugs me unbelievably to have to constantly type "local
" for all my local variables.
It just makes my code look more cluttered.
So I am wondering, can I create a Domain Specific Language (DSL) on top of Lua to simply have the following variable naming convention.
- If a variable name is in ALL CAPITAL LETTERS, then it's a global variable
- Else, the variable is a
local
variable
Question: Would this work - Yes or no?
In other words:
-- In Lua 5.2
isGlobalinLua = "is global in default Lua"
GLOBALVAR = "is global var in default Lua"
local localvar = "is local var in default Lua"
-- In my DSL Lua language
isLocalinDSLLua = "is local in DSL Lua" -- translates to: local isLocalinDSLLua = ...
GLOBALVAR = "is global DSL Lua"
localvar = "is local var in DSL Lua" -- translates to: local localvar = ...
So now, the following code in default Lua:
myglobal = 10
local a = 1
if a > 1 then
local b = 2
print b
else
local c = 3
print c + myglobal
end
With my DSL Lua:
MYGLOBAL = 10
a = 1
if a > 1 then
b = 2
print b
else
c = 3
print c + MYGLOBAL
end
UPDATE:
What about local functions?
How would the following code work?
myfunc = function (...) -- local myfunc = function (...)
I'm not certain I'd want to make every global function in all caps.
Maybe I just ignore functions and require the 'local
' identifier ... thoughts?