Skip to content

GLua eradication - #1253

Closed
oldmud0 wants to merge 16 commits into
wiremod:masterfrom
oldmud0:glua-eradication
Closed

GLua eradication#1253
oldmud0 wants to merge 16 commits into
wiremod:masterfrom
oldmud0:glua-eradication

Conversation

@oldmud0

@oldmud0 oldmud0 commented Nov 4, 2016

Copy link
Copy Markdown

The purpose of this PR is to eradicate all occurrences of unofficial Lua syntax. All of it. This is an ongoing PR, and it will not merge until luacheck passes with no syntax errors across the entire source code.

// -> --, != -> ~=, ! -> not
s/if\s*?\(\s*(.*?)\s*\)\s*?then/if \1 then/ (removes extra parentheses in if-then)
# Conflicts:
#	lua/entities/gmod_wire_hudindicator/init.lua
#	lua/weapons/gmod_tool/stools/wire_namer.lua
@Divran

Divran commented Nov 4, 2016

Copy link
Copy Markdown
Contributor

I see you're even erasing brackets around if statements. That's not unofficial lua syntax, just sayin

EDIT: you merged "master" into glua-eradication? was that intentional?

Comment thread lua/wire/wireshared.lua Outdated
Very useful for searching algorithms
Used by custom spawn menu search & gate tool search, for example
Credits go to: http://lua-users.org/lists/lua-l/2009-07/msg00461.html
Credits go to: http:-- lua-users.org/lists/lua-l/2009-07/msg00461.html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this and any other instances of incorrect replacements.

@oldmud0

oldmud0 commented Nov 4, 2016

Copy link
Copy Markdown
Author

The parentheses thing I considered part of the "unofficial syntax" because Lua neither requires nor condones parentheses around the entire condition. It's annoying, it's not part of the manual of style, and it's not in new code.

I had to merge against master to fix a conflict with master branch that would not have allowed merging (like that's going to happen anytime soon).

I was expecting someone to point out some mistakes I inevitably made trying to fix literally everything. Thank you for reviewing.

Comment thread lua/entities/gmod_wire_button.lua Outdated
self.BaseClass.Think(self)

if ( self:GetOn() ) then
if self:GetOn() then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are extra spaces here

Comment thread lua/entities/gmod_wire_cd_lock.lua Outdated
self.BaseClass.Think(self)

// If we were undiskged, reset the disk and socket to accept new ones.
-- If we were undiskged, reset the disk and socket to accept new ones.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "undiskged"

if not self.Disk then return end
local disk = self.Disk
if (self.Command[8] ~= 0) then
if self.Command[8] ~= 0 then

@TomyLobo TomyLobo Nov 5, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow someone should really replace those numbers by constants with telling names

not as part of this PR, of course

@TomyLobo TomyLobo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pointed out a number of things that need to change abefore we can accept this PR as well as some things that might be interesting as part of separate PRs.

For some of the required changes, I wrote a script while doing the review. I'll post a PR on your branch as soon as I flesh out that script.

The comments corresponding to those changes should start disappearing as soon as you accept that PR.

if (self.Memory[2047] ~= 0) && (self.CharX >= 0) && (self.CharX < 30) &&
(self.CharY >= 0) && (self.CharY < 18) then
if (self.Memory[2047] ~= 0) and (self.CharX >= 0) and (self.CharX < 30) and
(self.CharY >= 0) and (self.CharY < 18) then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation seems off here. might as well fix it.

Comment thread lua/entities/gmod_wire_datasocket.lua Outdated
// If we have no plug in us
if (not self.MyPlug) or (not self.MyPlug:IsValid()) then
-- If we have no plug in us
if not self.MyPlug) or (not self.MyPlug:IsValid() then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm....

Comment thread lua/entities/gmod_wire_datasocket.lua Outdated
// If we find a plug, try to attach it to us
if ( plug:IsValid() && plug:GetClass() == "gmod_wire_dataplug" ) then
-- If we find a plug, try to attach it to us
if plug:IsValid() && plug:GetClass() == "gmod_wire_dataplug" then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are extra spaces here

end
end
elseif Address == 1048575 then -- CLK
-- elseif Address == 1048575 then -- CLK

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentional?

@oldmud0 oldmud0 Nov 6, 2016

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not. I tested the comments find/replace well and it never did this. Yes, this is intentional. Leaving this elseif triggers an error in luacheck. See the following line.

SetMaterial( Mat )
elseif isentity(Mat) then
if (!Mat:IsValid() or !Mat.GPU or !Mat.GPU.RT) then NoTexture() return end
if not (Mat:IsValid() and Mat.GPU and Mat.GPU.RT) then NoTexture() return end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


for k, v in pairs(WIREENT) do
if ((Entity[k] == nil) or (k == "_Overrides_WireMapInterfaceEnt") or (k == "_Added_WireMapInterfaceEnt") or (k == "_Settings_WireMapInterfaceEnt")) then
if Entity[k] == nil) or (k == "_Overrides_WireMapInterfaceEnt") or (k == "_Added_WireMapInterfaceEnt") or (k == "_Settings_WireMapInterfaceEnt" then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm #3

Comment thread lua/wire/beam_netvars.lua Outdated
--Msg("========BeamVars leaving NormalOpMode | "..DelayedUpdatesNum.."\n")
NormalOpMode = false
elseif (!NormalOpMode) and (DelayedUpdatesNum < 50) then
elseif (not NormalOpMode) and (DelayedUpdatesNum < 50) then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are exta spaces here

Comment thread lua/wire/stools/clutch.lua Outdated


/*---------------------------------------------------------
--[[---------------------------------------------------------

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra dashes here and further down a couple of times

if ent:GetClass() == "gmod_wire_trigger" then

-- http:--youtu.be/RTR1ny0O_io
-- http://youtu.be/RTR1ny0O_io

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another broken url

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant to fix this, but you beat me to it.

Comment thread lua/wire/tool_loader.lua Outdated
-- s_mode: Tool_mode, same as the old tool lua file name, minus the "wire_" part
-- s_name: Proper name for the tool
-- s_class: For tools that make a device. Should begin with "gmod_wire_". Can be nil if not using WireToolObj.LeftClick or WireToolSetup.BaseLang
-- f_toolmakeent: Server side function for making the tools device. Can be nil if not using WireToolObj.LeftClick

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you undo this change? I think the extra indentation here had a purpose.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see the previous occurrence of this, you will see that the in-comment indentation is a bit inconsistent. This one only has space of indentation whereas the previous one had two.

@TomyLobo

TomyLobo commented Nov 5, 2016

Copy link
Copy Markdown
Contributor

still working on the script.
turns out determining the difference between code and prose is hard.

EDIT:
Done, oldmud0#1

@TomyLobo TomyLobo mentioned this pull request Nov 5, 2016
@oldmud0

oldmud0 commented Nov 6, 2016

Copy link
Copy Markdown
Author

Thanks for your contributions. I wanted to do some things too but it looks like you have beat me to them. I'll do the second pass now.

UPDATE: We have a somewhat significant problem. continue is also part of GLua syntax but the fix is nontrivial.

@oldmud0 oldmud0 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the whitespace fixes: This is purely to try to get the build to pass, not because I am actually some sort of whitespace purist.

Unnecessary parentheses in if statements were not removed.

local string = string -- optimization

/******************************************************************************/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe reinstate those as lines of dashes?

@oldmud0 oldmud0 Nov 7, 2016

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, but it looks like I accidentally didn't push it

end

/* --- File Read --- */
--[[ --- File Read --- ]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could have just removed the /* */ :D

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that would have looked a lot neater.

@oldmud0

oldmud0 commented Nov 7, 2016

Copy link
Copy Markdown
Author

Okay, so I have found another problem. When e2functions are defined, the declaration is considered an error by luacheck, so basically any file defining any E2 functions is an error (afaik luacheck stops at the first error on a file).

@TomyLobo

TomyLobo commented Nov 7, 2016

Copy link
Copy Markdown
Contributor

re e2function: Can you maybe preprocess them with a regex before piping them into luacheck?
I could give you a sed script that turns e2functions into regular functions, probably even with all the parameter names intact.

re continue: maybe you can do the same here... replace it by break.

@oldmud0

oldmud0 commented Nov 11, 2017

Copy link
Copy Markdown
Author

As a conclusion, the effort was noble, but is not easily doable because it involves touching some really old code that is known to work and also reflowing code that depends on continue.

If I wanted to do the eradication, I'd probably just start over, scout for common style problems, do the heavy lifting purely with regex/awk, and then do the final pass by hand. I made too many mistakes trying to do this with semi-manual regex, most especially just missing things by going too fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants