├── .gitignore
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2021 Project Error
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
19 | OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 | FiveM Style Guide for Lua
5 |
6 |
7 |
8 | A mostly reasonable style & convention guide for FiveM's Lua ScRT
9 |
10 |
11 |
12 |
13 |
14 | [](https://github.com/project-error/pe-utils/master/LICENSE)
15 | 
16 |
17 |
18 | ## Intro
19 | Unlike a language like JavaScript, Lua does not have a widely accepted styling across
20 | implementations. This style guide aims to ensure that styling is consistent across all
21 | Project Error Lua files.
22 |
23 | Much of this style guide is based off popular JS/TS conventions.
24 |
25 | ## Identation
26 | I.1 - Always use `spaces` as target indentation
27 | > Primarily for code readability on GitHub as tabs are displayed as 8 spaces by default
28 |
29 | I.2 - Use two spaces for indent spacing
30 | > Opionated carryover from JS/TS conventions.
31 |
32 | ## Events & Exports
33 | E.1 - Non-net cross resource communication should use exports
34 | > Why? Although exports are simple wrappers around events, they offer
35 | > caching.
36 |
37 | E.2 - NetEventHandlers on the Server should use `RegisterServerEvent`
38 | > Under the hood this is an alias to `RegisterNetEvent`. `RegisterServerEvent`
39 | > is preferred for easy identification of Server Side handlers. (i.e Searching through
40 | > a resource)
41 |
42 | E.3 - Always use the optional callback argument for RegisterNetEvent
43 | > Increased readability and more concise
44 | ```lua
45 | -- Good
46 | RegisterNetEvent('netEvent', handlerFunc)
47 |
48 | -- Bad
49 | RegisterNetEvent('netEvent')
50 | AddEventHandler('netEvent', handlerFunc)
51 | ```
52 |
53 | ## Casing
54 | C.1 - Constants should use upper case snakecase
55 | ```lua
56 | -- Good
57 | local INTERVAL_TIME = 50
58 |
59 | -- Bad
60 | local intervalTime = 50
61 | ```
62 |
63 | C.2 - Local variables or functions should use camelCase
64 | ```lua
65 | local myVar = {}
66 |
67 | local function myLocalFunction() end
68 | ```
69 |
70 | C.3 - Global variables or functions should use upper camelcase
71 | ```lua
72 | MyGlobalVar = 'nice'
73 |
74 | function MyGlobalFunction() end
75 | ```
76 |
77 | ## Misc
78 | M.1 - Where possible, avoid using the Citizen prefix for the `Citizen` table of functions
79 | > The most commonly used citizen table functions are aliased to work with removing the prefix. This
80 | > appears more concise.
81 | ```lua
82 | -- Bad
83 | Citizen.CreateThread(fn)
84 |
85 | -- Good
86 | CreateThread(fn)
87 | ```
88 | > List of aliased functions:
89 | ```lua
90 | SetTimeout
91 | Wait
92 | CreateThread
93 | RconPrint -- Citizen.Trace
94 | ```
95 |
--------------------------------------------------------------------------------