-
Is there a command line option, or a workaround to use nelua on simple code like: a = 1
b = 2
print(a + b) rather than local a = 1
local b = 1
print(a + b) I know issues arent a wishing well, and this really isn't an issue per se, but at this point I don't know a better place to ask :) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
In short no, you should explicitly declare your variable as So the equivalent Nelua code for your Lua example is: global a = 1
global b = 2
print(a + b) But in general you should use local, like in Lua people usually do, unless you really want the variable accessible across modules.
You can ask more questions in the discord chat, the link is on the chat badge in the github home page. |
Beta Was this translation helpful? Give feedback.
-
Thanks @edubart that makes sense. I'll join the discord since I'm very keen on the project! Feel free to close the issue. |
Beta Was this translation helpful? Give feedback.
-
The invite link for discord server is invalid @edubart |
Beta Was this translation helpful? Give feedback.
-
@MetlHedd Thanks for notifying, I've fixed. |
Beta Was this translation helpful? Give feedback.
In short no, you should explicitly declare your variable as
local
orglobal
. This was supported before but I concluded that it did more harm than good for the users, because it hides away many possible errors that could be caught at compile time and this leads to bad experiences while coding. I know this is possible in Lua, but not in Nelua, furthermore many people consider bad practice and dangerous doing that even in Lua. In the future there is the possibility to revisit this feature if I decide to implement the global_G
table like in Lua, but would be optional.So the equivalent Nelua code for your Lua example is:
But in general you should use lo…