Difference between revisions of "MinetestWiki:Style Guide"

From Minetest Developer Wiki
Jump to navigation Jump to search
Line 2: Line 2:
  
 
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>)
 +
 +
== Syntax highlighting ==
 +
<pre><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></pre>
 +
 +
<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>
 +
 +
<pre><source enclose="none">assert(type(str) == "string")</source></pre>
 +
 +
<source enclose="none">assert(type(str) == "string")</source>
  
 
== [casting] ==
 
== [casting] ==

Revision as of 14:25, 1 December 2012

Indent source code either with 2/4 spaces or 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)

Method template

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

== Description ==
Do something.

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

[[Category:Methods]]