#GLua Standard
1 messages · Page 1 of 1 (latest)
My opinions:
- You should never use
\\or*\, use--and--[[ - All local variables should be camelCase, even if it's a function
- Lua file names should have a prefix that stands for what realm(s) it will be loaded in (sv_, cl_, or sh_)
Other than that, I agree with everything here. By the way, syntax error on the 4th one
4 is arguing with gmod's default, your PRs would not be accepted with this standard
2.2 calling a file autorun_* inside the lua/autorun folder..
I know, was pointing this out lol
Use 4 spaces for indentation, you probably mean "use tab" not 4 actual spaces, I will rdm you
Oh yeah I forgot to comment on that, that's redundant to add lol
11, use dot with a space (can't), must use ["the key"] and I prefer it
what I haven't mentioned I do agree with though
Also, preferably, the base Lua operators should always be used. Although, I do know that some people like to use !=
I do agree that != is better tho not sure why Lua changes it to ~=
It's just easier to type imo, only reason I use != is musclememoru
if name != nil then is not always bad. Sometimes you need to defer between false and nil. E.g. for optional parameters being true by default.
function bla(optionalbool)
if optionalbool == nil then
optionalbool = true
end
-- whatever
print("optionalbool", optionalbool)
end
bla() -- optionalbool true
bla(false) -- optionalbool false
bla(true) -- optionalbool true
type checking use case specific yeah
You can steal stuff from here if you'd like:
https://github.com/CFC-Servers/cfc_glua_style_guidelines
This is my preferred standard
The concept is that there is no need to clog the autorun folder with multiple files. Instead, you can create your own folder, which will contain ALL your scripts of a certain theme/addon. This way harmony is preserved
Conditionally:
lua/autorun/myeventsystem_autorun.lua
lua/myeventsystem/cl_hud.lua
lua/myeventsystem/sh_net.ua
A convenient thing, even **GmodStore ** adheres to this concept when accepting content on its platform
You can indent either using direct tabs or using spaces. Usually literate people use 4 spaces, and in the same GitHub the difference is visually noticeable
I agree with you, I think this is already at the request of users. I use it !=, although in the same basic Lua, the important standard is the ~= method
Deleted it, it was an accident 😂
is much more in depth i prefer this
Sometimes there is a need for non-standard options, so there is no strict decree "just like that". Just an indication that in the conditions these two things are identical
And even your case with the code, you can use the if !optionalbool then
Thanks ❤️
Added new things