mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-01 23:33:46 +01:00
Add back function declaration guideline, provide examples for code style guidelines
parent
a80438d58e
commit
6466061796
@ -161,15 +161,78 @@ issue.
|
|||||||
|
|
||||||
### Code Guidelines
|
### Code Guidelines
|
||||||
* Each mod must provide `mod.conf`.
|
* Each mod must provide `mod.conf`.
|
||||||
* Mod names are snake case, and newly added mods start with `mcl_`
|
* Mod names are snake case, and newly added mods start with `mcl_`, e.g.
|
||||||
* Each mod which add API functions should store functions inside a
|
`mcl_core`, `mcl_farming`, `mcl_monster_eggs`
|
||||||
global table named like the mod.
|
* To export functions, store them inside a global table named like the
|
||||||
|
mod, e.g.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
mcl_example = {}
|
||||||
|
|
||||||
|
function mcl_example.do_something()
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
* Public functions should not use self references but rather just access
|
* Public functions should not use self references but rather just access
|
||||||
the table directly.
|
the table directly, e.g.
|
||||||
* Use modern Minetest API
|
|
||||||
* Tabs should be used for indent, spaces for alignment
|
```lua
|
||||||
* Use double quotes for strings
|
-- bad
|
||||||
* Use snake_case rather than CamelCase
|
function mcl_example:do_something()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- good
|
||||||
|
function mcl_example.do_something()
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
* Use modern Minetest API, e.g. no usage of `minetest.env`
|
||||||
|
* Tabs should be used for indent, spaces for alignment, e.g.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
|
||||||
|
-- use tabs for indent
|
||||||
|
|
||||||
|
for i = 1, 10 do
|
||||||
|
if i % 3 == 0 then
|
||||||
|
print(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- use tabs for indent and spaces to align things
|
||||||
|
|
||||||
|
some_table = {
|
||||||
|
{"a string", 5},
|
||||||
|
{"a very much longer string", 10},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* Use double quotes for strings, e.g. `"asdf"` rather than `'asdf'`
|
||||||
|
* Use snake_case rather than CamelCase, e.g. `my_function` rather than
|
||||||
|
`MyFunction`
|
||||||
|
* Dont declare functions as an assignment, e.g.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- bad
|
||||||
|
local some_local_func = function()
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
|
my_mod.some_func = function()
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
|
-- good
|
||||||
|
local function some_local_func()
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
|
function my_mod.some_func()
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Changes to Gameplay
|
### Changes to Gameplay
|
||||||
Pull Requests that change gameplay have to be properly researched and
|
Pull Requests that change gameplay have to be properly researched and
|
||||||
|
Loading…
Reference in New Issue
Block a user