Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jan 5, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 23
Lua Style Guide
Gareth YR edited this page Aug 21, 2020
·
6 revisions
localvar="hi" ❌
localvar="hi"; -- ✅2. Local Variable Names - camelCase
localVar-- ❌localvar-- ✅localsomevar-- ❌localSomeVar-- ❌localsomeVar-- ✅self.someothervar-- ❌self.SomeOtherVar-- ❌self.someOtherVar-- ✅3. Global Variable Names - PascalCase
var-- ❌Var-- ✅someVar-- ❌somevar-- ❌Somevar-- ❌SomeVar-- ✅4. Function Names - PascalCase
functionsomeFunction() -- ❌functionSomefunction() -- ❌functionsomefunction() -- ❌functionsome_function() -- ❌functionSomeFunction() -- ✅Some IDEs have an option to replace tabs with spaces and vice-versa.
Make sure that you are really creating a Tab character when pressing the Tab key!
x=y+z; -- ❌x=y+z; -- ✅x=y-z; -- ❌x=y-z; -- ✅x=y*z; -- ❌x=y*z; -- ✅x=y/z; -- ❌x=y/z; -- ✅x=y^z; -- ❌x=y^z; -- ✅x=a*(y+z); -- ❌x=a* (y+z); -- ✅x=y; -- ❌x=y; -- ✅function(p1,p2,p3); -- ❌function(p1, p2, p3); -- ✅7. Long and Informative Variable Names - as opposed to tons of comments explaining every little thing
toAdd=5; --This is the number of objects to add per interval -- ❌numberOfObjectsToAddPerInterval=5; -- ✅Comments longer than a few words should be on their own line above the line of code.
localv=5; -- the v stands for variable -- ❌localv=5; --The v stands for variable -- ✅localv=5; --The v stands for variable because that's what it is, it's a variable and it's useful to vary things -- ❌--The v below stands for variable because that's what it is, it's a variable and it's useful to vary things -- ✅localv=5;