Difference between revisions of "MinetestWiki:Style Guide"

From Minetest Developer Wiki
Jump to navigation Jump to search
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Indent source code either with 2/4 spaces or tab character.  
+
== Normal prose ==
 +
 
 +
Use paragraphs, represented in MediaWiki by two line breaks (i.e. hit enter twice), as opposed to single line breaks to separate text.
 +
 
 +
Don't put line breaks in the middle of a line in the source code. It might make it easier to read momentarily, but it has no real semantic meaning to the wiki, so there's no reason to do it.
 +
 
 +
== Links and article names ==
 +
 
 +
Articles' names shouldn't all be capitalized. These aren't research papers or book titles, they're just pages to let people know what's happening in the project.
 +
 
 +
== Source code ==
 +
 
 +
Indent source code with tab character.  
  
 
Put spaces before and after binary operators, don't put spaces after unary operators  (<source enclose="none">local b = -a + 3 * (c - a) / 2</source>)
 
Put spaces before and after binary operators, don't put spaces after unary operators  (<source enclose="none">local b = -a + 3 * (c - a) / 2</source>)
Line 52: Line 64:
  
 
== Description ==
 
== Description ==
 +
* <code>variable</code> — the most important variable in call
 +
 
Do something.
 
Do something.
  
Line 59: Line 73:
 
</source>
 
</source>
  
[[Category:Methods]]
 
 
</pre>
 
</pre>

Latest revision as of 20:13, 18 June 2020

Normal prose

Use paragraphs, represented in MediaWiki by two line breaks (i.e. hit enter twice), as opposed to single line breaks to separate text.

Don't put line breaks in the middle of a line in the source code. It might make it easier to read momentarily, but it has no real semantic meaning to the wiki, so there's no reason to do it.

Links and article names

Articles' names shouldn't all be capitalized. These aren't research papers or book titles, they're just pages to let people know what's happening in the project.

Source code

Indent source code with tab character.

Put spaces before and after binary operators, don't put spaces after unary operators (local b = -a + 3 * (c - a) / 2)

Syntax highlighting

<source>
-- Some code
function minetest.string_to_privs(str, delim)
	assert(type(str) == "string")
	delim = delim or ','
	privs = {}
	for _, priv in pairs(string.split(str, delim)) do
		privs[priv:trim()] = true
	end
	return privs
end
</source>
-- Some code
function minetest.string_to_privs(str, delim)
	assert(type(str) == "string")
	delim = delim or ','
	privs = {}
	for _, priv in pairs(string.split(str, delim)) do
		privs[priv:trim()] = true
	end
	return privs
end
<source enclose="none">assert(type(str) == "string")</source>

assert(type(str) == "string")

[casting]

add_item("listname", stack)

add_item("listname", stack) (link points to EnvRef:add_item)

[InvRef]add_item("listname", stack)

[InvRef]add_item("listname", stack) (link is made to point to InvRef:add_item)

You should use casting for those methods:

  • add_item
  • get_inventory
  • is_empty
  • to_table

Method template

{{DISPLAYTITLE:minetest.new_awesome_method}}
== Syntax ==
<source>minetest.new_awesome_method("string", {table}, variable)</source>

== Description ==
* <code>variable</code> — the most important variable in call

Do something.

== Example ==
<source>
minetest.new_awesome_method("lol", {wtf}, 42)
</source>