Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
a1db83e9
Commit
a1db83e9
authored
10 years ago
by
ShadowNinja
Browse files
Options
Downloads
Patches
Plain Diff
Make duplicate warning checks file and line specific
parent
0dcc4b25
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
builtin/common/strict.lua
+12
-6
12 additions, 6 deletions
builtin/common/strict.lua
with
12 additions
and
6 deletions
builtin/common/strict.lua
+
12
−
6
View file @
a1db83e9
...
...
@@ -11,16 +11,21 @@ end
local
meta
=
{}
local
declared
=
{}
local
alreadywarned
=
{}
-- Key is source file, line, and variable name; seperated by NULs
local
warned
=
{}
function
meta
:
__newindex
(
name
,
value
)
local
info
=
debug.getinfo
(
2
,
"Sl"
)
local
desc
=
(
"%s:%d"
):
format
(
info
.
short_src
,
info
.
currentline
)
if
not
declared
[
name
]
then
if
info
.
what
~=
"main"
and
info
.
what
~=
"C"
then
warn
((
"Assignment to undeclared global %q inside"
..
" a function at %s."
)
local
warn_key
=
(
"%s\0%d\0%s"
):
format
(
info
.
source
,
info
.
currentline
,
name
)
if
not
warned
[
warn_key
]
and
info
.
what
~=
"main"
and
info
.
what
~=
"C"
then
minetest
.
log
(
"error"
,
(
"Assignment to undeclared "
..
"global %q inside a function at %s."
)
:
format
(
name
,
desc
))
warned
[
warn_key
]
=
true
end
declared
[
name
]
=
true
end
...
...
@@ -36,10 +41,11 @@ end
function
meta
:
__index
(
name
)
local
info
=
debug.getinfo
(
2
,
"Sl"
)
if
not
declared
[
name
]
and
info
.
what
~=
"C"
and
not
alreadywarned
[
name
]
then
local
warn_key
=
(
"%s\0%d\0%s"
):
format
(
info
.
source
,
info
.
currentline
,
name
)
if
not
declared
[
name
]
and
not
warned
[
warn_key
]
and
info
.
what
~=
"C"
then
warn
((
"Undeclared global variable %q accessed at %s:%s"
)
:
format
(
name
,
info
.
short_src
,
info
.
currentline
))
alreadywarned
[
name
]
=
true
warned
[
warn_key
]
=
true
end
return
rawget
(
self
,
name
)
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment