This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lua_conventions [2015/02/04 20:24] dean4devil Lua Hightlighting! \o/ |
lua_conventions [2019/08/06 00:02] (current) payonel |
||
---|---|---|---|
Line 9: | Line 9: | ||
* Name variables for what they are, don't include type markers in them, i.e. do not use Hungarian notation. | * Name variables for what they are, don't include type markers in them, i.e. do not use Hungarian notation. | ||
* Nice to have: sort your requires alphabetically (OCD!) | * Nice to have: sort your requires alphabetically (OCD!) | ||
- | * Only comment if it's something complicated/non obvious. Keep in mind that comments increase file size, which increases the amount of RAM required to run your program! | + | * Feel free to comment your code. Any additional memory needed to load your file due to heavy use of comments is released soon after loading is complete. |
* If you have to validate arguments, use the built-in checkArg method. Homogenous error messages are a good thing! Its usage is checkArg(n, value, type1, ...), where n is the number of the argument, value is the value of the argument and type1 and so on are the allowed types for the argument, as retrieved via type(value). The number is used in the error message like so: "bad argument #n (type1 expected, got type(value))". So for example, to require the first argument to be a number you'd do checkArg(1, arg, "number"). | * If you have to validate arguments, use the built-in checkArg method. Homogenous error messages are a good thing! Its usage is checkArg(n, value, type1, ...), where n is the number of the argument, value is the value of the argument and type1 and so on are the allowed types for the argument, as retrieved via type(value). The number is used in the error message like so: "bad argument #n (type1 expected, got type(value))". So for example, to require the first argument to be a number you'd do checkArg(1, arg, "number"). | ||
Line 42: | Line 42: | ||
end | end | ||
</code> | </code> | ||
+ | |||
+ | Contents | ||
+ | ----------- | ||
+ | {{page>:contents&noheader&noeditbutton&nouser&nofooter}} |