1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Code style fixes.

This commit is contained in:
SFENCE 2024-09-04 19:15:39 +02:00 committed by sfence
parent 24e9db07ec
commit af3f696423
43 changed files with 493 additions and 484 deletions

View file

@ -34,7 +34,16 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
# Line endings are already ensured by .gitattributes # Line endings are already ensured by .gitattributes
- name: Check trailing whitespaces - name: Check trailing whitespaces
run: if git ls-files | grep -E '\.txt$|\.md$|\.[ch]$|\.cpp$|\.hpp$|\.sh$|\.cmake$|\.glsl$' | xargs grep -n '\s$'; then echo -e "\033[0;31mFound trailing whitespace"; (exit 1); else (exit 0); fi run: |
if git ls-files |\
grep -E '\.txt$|\.md$|\.[ch]$|\.cpp$|\.hpp$|\.sh$|\.cmake$|\.glsl$' |\
xargs grep -n '\s$';\
then\
echo -e "\033[0;31mFound trailing whitespace";\
(exit 1);\
else\
(exit 0);\
fi
indent_spaces: indent_spaces:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -46,21 +55,51 @@ jobs:
# So lines like: "/* */ /*" or "*/ a = 5; /*" will result in error # So lines like: "/* */ /*" or "*/ a = 5; /*" will result in error
- name: Check for unsupported multiline comments - name: Check for unsupported multiline comments
run: | run: |
if git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' | xargs grep -n '\*/.*/\*'; then echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line."; (exit 1); else (exit 0); fi if git ls-files |\
if git ls-files | grep -E '\.lua$' | xargs grep -n -e '\]\].*--\[\['; then echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line."; (exit 1); else (exit 0); fi grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
xargs grep -n '\*/.*/\*';\
then
echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line.";\
(exit 1);\
else\
(exit 0);\
fi
if git ls-files |\
grep -E '\.lua$' |\
xargs grep -n -e '\]\].*--\[\[';\
then
echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line.";\
(exit 1);\
else\
(exit 0);\
fi
# This prepare files for final check # This prepare files for final check
# See python script ./util/ci/indent_tab_preprocess.py for details. # See python script ./util/ci/indent_tab_preprocess.py for details.
- name: Preprocess files - name: Preprocess files
run: | run: |
git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' | xargs -L 1 -P $(($(nproc) + 1)) python3 ./util/ci/indent_tab_preprocess.py "/*" "*/" git ls-files |\
git ls-files | grep -E '\.lua$' | xargs -L 1 -P $(($(nproc) + 1)) python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]" grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
xargs -L 1 -P $(($(nproc) + 1)) \
python3 ./util/ci/indent_tab_preprocess.py "/*" "*/"
git ls-files |\
grep -E '\.lua$' |\
xargs -L 1 -P $(($(nproc) + 1)) \
python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]"
# Check for bad indent. # Check for bad indent.
# This runs over preprocessed files. # This runs over preprocessed files.
# If there is any remaining space on line beginning or after tab, # If there is any remaining space on line beginning or after tab,
# error is generated # error is generated
- name: Check indent spaces - name: Check indent spaces
run: | run: |
if git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$|\.lua' | xargs grep -n -P '^\t*[ ]'; then echo -e "\033[0;31mFound incorrect indent whitespaces"; (exit 1); else (exit 0); fi if git ls-files |\
grep -E '^src/.*\.cpp$|^src/.*\.[ch]$|\.lua' |\
xargs grep -n -P '^\t*[ ]';\
then\
echo -e "\033[0;31mFound incorrect indent whitespaces";\
(exit 1);\
else\
(exit 0);\
fi
tabs_lua_api_files: tabs_lua_api_files:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -68,6 +107,12 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
# Some files should not contain tabs # Some files should not contain tabs
- name: Check tabs in Lua API files - name: Check tabs in Lua API files
run: if grep -n $'\t' doc/lua_api.md doc/client_lua_api.md; then echo -e "\033[0;31mFound tab in markdown file"; (exit 1); else (exit 0); fi run: |
if grep -n $'\t' doc/lua_api.md doc/client_lua_api.md;\
then\
echo -e "\033[0;31mFound tab in markdown file";\
(exit 1);\
else\
(exit 0);\
fi

View file

@ -12,7 +12,8 @@ core.register_node("tiled:tiled", {
}) })
core.register_node("tiled:tiled_rooted", { core.register_node("tiled:tiled_rooted", {
description = "Tiled 'plantlike_rooted' Node (world-aligned)".."\n".. description =
"Tiled 'plantlike_rooted' Node (world-aligned)".."\n"..
"Base node texture spans over a space of 8×8 nodes".."\n".. "Base node texture spans over a space of 8×8 nodes".."\n"..
"A plantlike thing grows on top", "A plantlike thing grows on top",
paramtype = "light", paramtype = "light",

View file

@ -62,30 +62,22 @@ extern struct EnumString es_TileAnimationType[];
extern const std::array<const char *, 33> object_property_keys; extern const std::array<const char *, 33> object_property_keys;
void read_content_features (lua_State *L, ContentFeatures &f, void read_content_features(lua_State *L, ContentFeatures &f, int index);
int index); void push_content_features(lua_State *L, const ContentFeatures &c);
void push_content_features (lua_State *L,
const ContentFeatures &c);
void push_nodebox (lua_State *L, void push_nodebox(lua_State *L, const NodeBox &box);
const NodeBox &box); void push_palette(lua_State *L, const std::vector<video::SColor> *palette);
void push_palette (lua_State *L,
const std::vector<video::SColor> *palette);
TileDef read_tiledef (lua_State *L, int index, TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special);
u8 drawtype, bool special);
void read_simplesoundspec (lua_State *L, int index, void read_simplesoundspec(lua_State *L, int index, SoundSpec &spec);
SoundSpec &spec);
NodeBox read_nodebox(lua_State *L, int index); NodeBox read_nodebox(lua_State *L, int index);
void read_server_sound_params(lua_State *L, int index, void read_server_sound_params(lua_State *L, int index,
ServerPlayingSound &params); ServerPlayingSound &params);
void push_dig_params (lua_State *L, void push_dig_params(lua_State *L, const DigParams &params);
const DigParams &params); void push_hit_params(lua_State *L, const HitParams &params);
void push_hit_params (lua_State *L,
const HitParams &params);
ItemStack read_item(lua_State *L, int index, IItemDefManager *idef); ItemStack read_item(lua_State *L, int index, IItemDefManager *idef);
@ -97,31 +89,24 @@ void push_pointability_type (lua_State *L, PointabilityType poi
void push_pointabilities(lua_State *L, const Pointabilities &pointabilities); void push_pointabilities(lua_State *L, const Pointabilities &pointabilities);
ToolCapabilities read_tool_capabilities(lua_State *L, int table); ToolCapabilities read_tool_capabilities(lua_State *L, int table);
void push_tool_capabilities (lua_State *L, void push_tool_capabilities(lua_State *L, const ToolCapabilities &prop);
const ToolCapabilities &prop);
WearBarParams read_wear_bar_params(lua_State *L, int table); WearBarParams read_wear_bar_params(lua_State *L, int table);
void push_wear_bar_params (lua_State *L, void push_wear_bar_params(lua_State *L, const WearBarParams &prop);
const WearBarParams &prop);
void read_item_definition (lua_State *L, int index, const ItemDefinition &default_def, void read_item_definition(lua_State *L, int index,
ItemDefinition &def); const ItemDefinition &default_def, ItemDefinition &def);
void push_item_definition (lua_State *L, void push_item_definition(lua_State *L, const ItemDefinition &i);
const ItemDefinition &i); void push_item_definition_full(lua_State *L, const ItemDefinition &i);
void push_item_definition_full (lua_State *L,
const ItemDefinition &i);
void read_object_properties(lua_State *L, int index, void read_object_properties(lua_State *L, int index,
ServerActiveObject *sao, ServerActiveObject *sao,
ObjectProperties *prop, ObjectProperties *prop,
IItemDefManager *idef); IItemDefManager *idef);
void push_object_properties (lua_State *L, void push_object_properties(lua_State *L, const ObjectProperties *prop);
const ObjectProperties *prop);
void push_inventory_list (lua_State *L, void push_inventory_list(lua_State *L, const InventoryList &invlist);
const InventoryList &invlist); void push_inventory_lists(lua_State *L, const Inventory &inv);
void push_inventory_lists (lua_State *L,
const Inventory &inv);
void read_inventory_list(lua_State *L, int tableindex, void read_inventory_list(lua_State *L, int tableindex,
Inventory *inv, const char *name, Inventory *inv, const char *name,
IGameDef *gdef, int forcesize=-1); IGameDef *gdef, int forcesize=-1);
@ -130,25 +115,18 @@ MapNode readnode (lua_State *L, int index);
void pushnode(lua_State *L, const MapNode &n); void pushnode(lua_State *L, const MapNode &n);
void read_groups (lua_State *L, int index, void read_groups(lua_State *L, int index, ItemGroupList &result);
ItemGroupList &result);
void push_groups (lua_State *L, void push_groups(lua_State *L, const ItemGroupList &groups);
const ItemGroupList &groups);
//TODO rename to "read_enum_field" //TODO rename to "read_enum_field"
int getenumfield (lua_State *L, int table, int getenumfield(lua_State *L, int table, const char *fieldname,
const char *fieldname, const EnumString *spec, int default_);
const EnumString *spec,
int default_);
bool getflagsfield (lua_State *L, int table, bool getflagsfield(lua_State *L, int table, const char *fieldname,
const char *fieldname, FlagDesc *flagdesc, u32 *flags, u32 *flagmask);
FlagDesc *flagdesc,
u32 *flags, u32 *flagmask);
bool read_flags (lua_State *L, int index, bool read_flags(lua_State *L, int index, FlagDesc *flagdesc,
FlagDesc *flagdesc,
u32 *flags, u32 *flagmask); u32 *flags, u32 *flagmask);
void push_flags_string(lua_State *L, FlagDesc *flagdesc, void push_flags_string(lua_State *L, FlagDesc *flagdesc,
@ -157,35 +135,25 @@ void push_flags_string (lua_State *L, FlagDesc *flagdesc,
u32 read_flags_table(lua_State *L, int table, u32 read_flags_table(lua_State *L, int table,
FlagDesc *flagdesc, u32 *flagmask); FlagDesc *flagdesc, u32 *flagmask);
void push_items (lua_State *L, void push_items(lua_State *L, const std::vector<ItemStack> &items);
const std::vector<ItemStack> &items);
std::vector<ItemStack> read_items (lua_State *L, std::vector<ItemStack> read_items(lua_State *L, int index, IGameDef* gdef);
int index,
IGameDef* gdef);
void push_simplesoundspec (lua_State *L, void push_simplesoundspec(lua_State *L, const SoundSpec &spec);
const SoundSpec &spec);
bool string_to_enum(const EnumString *spec, bool string_to_enum(const EnumString *spec,
int &result, int &result, const std::string &str);
const std::string &str);
bool read_noiseparams (lua_State *L, int index, bool read_noiseparams(lua_State *L, int index, NoiseParams *np);
NoiseParams *np);
void push_noiseparams(lua_State *L, NoiseParams *np); void push_noiseparams(lua_State *L, NoiseParams *np);
bool read_tree_def(lua_State *L, int idx, bool read_tree_def(lua_State *L, int idx,
const NodeDefManager *ndef, const NodeDefManager *ndef, treegen::TreeDef &tree_def);
treegen::TreeDef &tree_def);
void luaentity_get(lua_State *L,u16 id); void luaentity_get(lua_State *L,u16 id);
bool push_json_value (lua_State *L, bool push_json_value(lua_State *L, const Json::Value &value, int nullindex);
const Json::Value &value, void read_json_value(lua_State *L, Json::Value &root, int index, u16 max_depth);
int nullindex);
void read_json_value (lua_State *L, Json::Value &root,
int index, u16 max_depth);
/*! /*!
* Pushes a Lua `pointed_thing` to the given Lua stack. * Pushes a Lua `pointed_thing` to the given Lua stack.

View file

@ -33,8 +33,7 @@ int getintfield_default(lua_State *L, int table,
bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname); bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname);
template<typename T> template<typename T>
bool getintfield(lua_State *L, int table, bool getintfield(lua_State *L, int table, const char *fieldname, T &result)
const char *fieldname, T &result)
{ {
lua_getfield(L, table, fieldname); lua_getfield(L, table, fieldname);
bool got = false; bool got = false;
@ -55,8 +54,7 @@ bool getstringfield(lua_State *L, int table,
bool getstringfield(lua_State *L, int table, bool getstringfield(lua_State *L, int table,
const char *fieldname, std::string_view &result); const char *fieldname, std::string_view &result);
size_t getstringlistfield(lua_State *L, int table, size_t getstringlistfield(lua_State *L, int table,
const char *fieldname, const char *fieldname, std::vector<std::string> *result);
std::vector<std::string> *result);
bool getboolfield(lua_State *L, int table, bool getboolfield(lua_State *L, int table,
const char *fieldname, bool &result); const char *fieldname, bool &result);
bool getfloatfield(lua_State *L, int table, bool getfloatfield(lua_State *L, int table,
@ -81,8 +79,7 @@ v2f read_v2f (lua_State *L, int index);
v2s16 read_v2s16(lua_State *L, int index); v2s16 read_v2s16(lua_State *L, int index);
v2s32 read_v2s32(lua_State *L, int index); v2s32 read_v2s32(lua_State *L, int index);
video::SColor read_ARGB8(lua_State *L, int index); video::SColor read_ARGB8(lua_State *L, int index);
bool read_color (lua_State *L, int index, bool read_color(lua_State *L, int index, video::SColor *color);
video::SColor *color);
bool is_color_table (lua_State *L, int index); bool is_color_table (lua_State *L, int index);
/** /**
@ -115,10 +112,8 @@ void push_v2f (lua_State *L, v2f p);
void push_aabb3f_vector(lua_State *L, const std::vector<aabb3f> &boxes, void push_aabb3f_vector(lua_State *L, const std::vector<aabb3f> &boxes,
f32 divisor = 1.0f); f32 divisor = 1.0f);
void warn_if_field_exists(lua_State *L, int table, void warn_if_field_exists(lua_State *L, int table, const char *fieldname,
const char *fieldname, std::string_view name, std::string_view message);
std::string_view name,
std::string_view message);
size_t write_array_slice_float(lua_State *L, int table_index, float *data, size_t write_array_slice_float(lua_State *L, int table_index, float *data,
v3u16 data_size, v3u16 slice_offset, v3u16 slice_size); v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);