can i check all project files?
how to output the check result to the console?
which tool is best for this?
how to check for errors in the syntax of scripts for love2d?
Re: how to check for errors in the syntax of scripts for love2d?
Yes, when you use require/loadscript/dofile the Lua interpreter checks for syntax errors. All you have to do is "require" all of your files.can i check all project files?
By using the --console option: "love.exe mygame.love --console"how to output the check result to the console?
My SUPERSTRICT tool finds undefined variables and other mistakes which the Lua interpreter ignores:which tool is best for this?
https://love2d.org/forums/viewtopic.php?f=5&t=90074
-
- Party member
- Posts: 563
- Joined: Wed Oct 05, 2016 11:53 am
Re: how to check for errors in the syntax of scripts for love2d?
To add to ivan's response, you could also use Luacheck.
Re: how to check for errors in the syntax of scripts for love2d?
I read the super strict git hub page but don't know where to start. Do I run it as a separate script? Do I REQUIRE it from my own project and it magically works? Sorry for the dumb questions. It just seems I am currently below the assumed level of knowledge.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Re: how to check for errors in the syntax of scripts for love2d?
Yes, but do it at the start. It doesn't check files that have already been loaded.
Re: how to check for errors in the syntax of scripts for love2d?
Well, I gotta say, I did the
as instructed and nothing happened. Thinking I was the goose for not understanding this, I didn't think about it and moved on.
Today, after perhaps a week, I added a 5 year old module I found on an old github (dabutton gui library) and all of a sudden sstrict has gone bonkers and forcing runtime errors on bad code.
It was working all along, but my code passed all the tests so I thought it wasn't working. lolz.
Thanks for this one! I'm a bit of a junkie with this sort of thing so it will be a part of my staple from now on.
Any way to make it check main.lua?
Code: Select all
require "sstrict.sstrict"
Today, after perhaps a week, I added a 5 year old module I found on an old github (dabutton gui library) and all of a sudden sstrict has gone bonkers and forcing runtime errors on bad code.
It was working all along, but my code passed all the tests so I thought it wasn't working. lolz.
Thanks for this one! I'm a bit of a junkie with this sort of thing so it will be a part of my staple from now on.
Any way to make it check main.lua?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Re: how to check for errors in the syntax of scripts for love2d?
AFTER you require superstrict it will intercept and check every following call to: require/dofile/loadfile/loadstring
That's why you have to include superstrict at the beginning of your code, before including any other files.
Don't forget to turn it off in production code because it's slow.
For an old file that you DON'T want to check just add the "--!strict" comment at the top.sstrict has gone bonkers and forcing runtime errors on bad code.
Also, make sure you get the latest version on bitbucket because I pushed some updates yesterday.
The easiest way is to just require main twice:Any way to make it check main.lua?
Code: Select all
require("sstrict")
require("main")
Code: Select all
for k,v in pairs(arg) do
if v == "--strict" then
require("sstrict")
break
end
end
Code: Select all
love mygamefolder --console --strict
The best way is to just iterate all the files in your game folder and run them through superstrict.
Code: Select all
require('sstrict').panic = false
Re: how to check for errors in the syntax of scripts for love2d?
The module I added had a global variable declared on the very first line:
Button = {}
sstrict doesn't like this. I can change the library to declare it LOCAL so sstrict is happy, but the module breaks (because BUTTON is now local).
Would the correct way to do this is to add
local button = {}
In main.lua? That would satisfy sstrict and still enable the module to function.
Thoughts? (Remember the module is 5 year old freeware).
Button = {}
sstrict doesn't like this. I can change the library to declare it LOCAL so sstrict is happy, but the module breaks (because BUTTON is now local).
Would the correct way to do this is to add
local button = {}
In main.lua? That would satisfy sstrict and still enable the module to function.
Thoughts? (Remember the module is 5 year old freeware).
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Re: how to check for errors in the syntax of scripts for love2d?
The whole point of superstrict is that it doesn't allow assigning globals.
You don't want to be assigning and changing globals from everywhere because it makes the code hard to follow and debug.
If this is not your code and you don't want to check it, just add the following line at the top of the problematic file:
Generally speaking you have to declare your globals before including superstrict:
The "standard" way of writing modules is to use a local and then return it at the end:
You don't want to be assigning and changing globals from everywhere because it makes the code hard to follow and debug.
If this is not your code and you don't want to check it, just add the following line at the top of the problematic file:
Code: Select all
--!strict
Code: Select all
Button = {}
require("sstrict")
Code: Select all
local Button = {}
...
return Button
Who is online
Users browsing this forum: No registered users and 4 guests