mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-08-03 02:56:53 -04:00
Page:
CodeConventions
Pages
API Colors
API Component
API Computer
API Event
API Filesystem
API Internet
API Keyboard
API Note
API Process
API Robot
API Serialization
API Shell
API Sides
API Term
API Text
API Unicode
APIs
Blocks
CodeConventions
Component Abstract Bus
Component CommandBlock
Component Computer
Component Crafting
Component GPU
Component Generator
Component Hologram
Component Internet
Component Modem
Component Navigation
Component NoteBlock
Component Redstone
Component RedstoneInMotion
Component Sign
ComponentAccess
Components
ComputerCraft
ComputerUsers
Detailed filesystem.mounts ()
Home
Items
NonStandardLuaLibs
OneThree
Signals
Tutorial BasicComputer
Tutorial HardDrives
Tutorial WritingCode
Tutorials
Clone
5
CodeConventions
Vexatos edited this page 2014-07-13 05:29:35 -07:00
Table of Contents
For those that don't like images: the wiki has moved to a new place, http://ocdoc.cil.li/.
This wiki will no longer be updated.
If you'd like to contribute code and save me the work of reformatting stuff (which will also make it more likely for it to be pulled!) please try to stick with the following conventions:
Lua
- Be consistent.
- Indent using spaces, two wide. Do indent properly.
- Try to limit width of the code to 80 chars.
- Don't add spaces between braces/brackets and what's in them.
- Do use brackets in functions calls even if it's not necessary.
- 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!)
- 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!
- If you have to validate arguments, use the built-in
checkArg
method. Homogenous error messages are a good thing! Its usage ischeckArg(n, value, type1, ...)
, wheren
is the number of the argument,value
is the value of the argument andtype1
and so on are the allowed types for the argument, as retrieved viatype(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 docheckArg(1, arg, "number")
.
Bad:
function f(sArg1 , ... )
assert(type(sArg1)== "string", "me wants a strign!")
if sArg1 then
local nResult = 1
--do some more stuff
return nResult
end
end
if f ( "a" ) ==1 then
print"asd"
end
Good:
function f(name, ...)
checkArg(1, name, "string")
if name then
local result = 1
-- We extrapolate the b-spline of the non-euclidean space to
-- determine the fraction of potential failures encountered.
return result
end
end
if f("a") == 1 then
print("asd")
end