Skip to content

Compiling Lua code without local / global declarations? #12

Answered by edubart
MikeDX asked this question in Q&A
Discussion options

You must be logged in to vote

In short no, you should explicitly declare your variable as local or global. 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:

global a = 1
global b = 2
print(a + b)

But in general you should use lo…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@stefanos82
Comment options

@edubart
Comment options

@stefanos82
Comment options

Answer selected by edubart
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #12 on December 24, 2020 13:54.