From 3884696d3831978e331e5fe8e109aad38643acee Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Mon, 15 Mar 2021 22:33:21 +0100 Subject: [PATCH] common/scriptcore: fix header line length. See osdn #41793 --- common/scriptcore/api_common_intl.c | 16 +- common/scriptcore/api_game_effects.c | 15 +- common/scriptcore/api_game_find.c | 102 ++++---- common/scriptcore/api_game_methods.c | 361 +++++++++++++------------- common/scriptcore/api_game_specenum.c | 56 ++-- common/scriptcore/api_signal_base.c | 23 +- common/scriptcore/luascript.c | 122 ++++----- common/scriptcore/luascript_func.c | 48 ++-- common/scriptcore/luascript_signal.c | 75 +++--- 9 files changed, 419 insertions(+), 399 deletions(-) diff --git a/common/scriptcore/api_common_intl.c b/common/scriptcore/api_common_intl.c index 89091fac1d..8a698f484e 100644 --- a/common/scriptcore/api_common_intl.c +++ b/common/scriptcore/api_common_intl.c @@ -23,9 +23,9 @@ #include "api_common_intl.h" -/*************************************************************************//** +/**********************************************************************//** Translation helper function. -*****************************************************************************/ +**************************************************************************/ const char *api_intl__(lua_State *L, const char *untranslated) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -34,9 +34,9 @@ const char *api_intl__(lua_State *L, const char *untranslated) return _(untranslated); } -/*************************************************************************//** +/**********************************************************************//** Translation helper function. -*****************************************************************************/ +**************************************************************************/ const char *api_intl_N_(lua_State *L, const char *untranslated) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -45,9 +45,9 @@ const char *api_intl_N_(lua_State *L, const char *untranslated) return N_(untranslated); } -/*************************************************************************//** +/**********************************************************************//** Translation helper function. -*****************************************************************************/ +**************************************************************************/ const char *api_intl_Q_(lua_State *L, const char *untranslated) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -56,9 +56,9 @@ const char *api_intl_Q_(lua_State *L, const char *untranslated) return Q_(untranslated); } -/*************************************************************************//** +/**********************************************************************//** Translation helper function. -*****************************************************************************/ +**************************************************************************/ const char *api_intl_PL_(lua_State *L, const char *singular, const char *plural, int n) { diff --git a/common/scriptcore/api_game_effects.c b/common/scriptcore/api_game_effects.c index 92f3ab8195..f182a52ab4 100644 --- a/common/scriptcore/api_game_effects.c +++ b/common/scriptcore/api_game_effects.c @@ -23,9 +23,9 @@ #include "api_game_effects.h" -/*************************************************************************//** +/**********************************************************************//** Returns the effect bonus in the world -*****************************************************************************/ +**************************************************************************/ int api_effects_world_bonus(lua_State *L, const char *effect_type) { enum effect_type etype = EFT_COUNT; @@ -40,9 +40,9 @@ int api_effects_world_bonus(lua_State *L, const char *effect_type) return get_world_bonus(etype); } -/*************************************************************************//** +/**********************************************************************//** Returns the effect bonus for a player -*****************************************************************************/ +**************************************************************************/ int api_effects_player_bonus(lua_State *L, Player *pplayer, const char *effect_type) { @@ -59,10 +59,11 @@ int api_effects_player_bonus(lua_State *L, Player *pplayer, return get_player_bonus(pplayer, etype); } -/*************************************************************************//** +/**********************************************************************//** Returns the effect bonus at a city. -*****************************************************************************/ -int api_effects_city_bonus(lua_State *L, City *pcity, const char *effect_type) +**************************************************************************/ +int api_effects_city_bonus(lua_State *L, City *pcity, + const char *effect_type) { enum effect_type etype = EFT_COUNT; diff --git a/common/scriptcore/api_game_find.c b/common/scriptcore/api_game_find.c index 39104867b5..7bfbdf046a 100644 --- a/common/scriptcore/api_game_find.c +++ b/common/scriptcore/api_game_find.c @@ -25,9 +25,9 @@ #include "api_game_find.h" -/*************************************************************************//** +/**********************************************************************//** Return a player with the given player_id. -*****************************************************************************/ +**************************************************************************/ Player *api_find_player(lua_State *L, int player_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -35,9 +35,9 @@ Player *api_find_player(lua_State *L, int player_id) return player_by_number(player_id); } -/*************************************************************************//** +/**********************************************************************//** Return a player city with the given city_id. -*****************************************************************************/ +**************************************************************************/ City *api_find_city(lua_State *L, Player *pplayer, int city_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -49,9 +49,9 @@ City *api_find_city(lua_State *L, Player *pplayer, int city_id) } } -/*************************************************************************//** +/**********************************************************************//** Return a player unit with the given unit_id. -*****************************************************************************/ +**************************************************************************/ Unit *api_find_unit(lua_State *L, Player *pplayer, int unit_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -63,11 +63,11 @@ Unit *api_find_unit(lua_State *L, Player *pplayer, int unit_id) } } -/*************************************************************************//** +/**********************************************************************//** Return a unit that can transport ptype at a given ptile. -*****************************************************************************/ -Unit *api_find_transport_unit(lua_State *L, Player *pplayer, Unit_Type *ptype, - Tile *ptile) +**************************************************************************/ +Unit *api_find_transport_unit(lua_State *L, Player *pplayer, + Unit_Type *ptype, Tile *ptile) { LUASCRIPT_CHECK_STATE(L, NULL); LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL); @@ -85,10 +85,10 @@ Unit *api_find_transport_unit(lua_State *L, Player *pplayer, Unit_Type *ptype, } } -/*************************************************************************//** +/**********************************************************************//** Return a unit type for given role or flag. (Prior to 2.6.0, this worked only for roles.) -*****************************************************************************/ +**************************************************************************/ Unit_Type *api_find_role_unit_type(lua_State *L, const char *role_name, Player *pplayer) { @@ -115,9 +115,9 @@ Unit_Type *api_find_role_unit_type(lua_State *L, const char *role_name, } } -/*************************************************************************//** +/**********************************************************************//** Return the tile at the given native coordinates. -*****************************************************************************/ +**************************************************************************/ Tile *api_find_tile(lua_State *L, int nat_x, int nat_y) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -125,9 +125,9 @@ Tile *api_find_tile(lua_State *L, int nat_x, int nat_y) return native_pos_to_tile(&(wld.map), nat_x, nat_y); } -/*************************************************************************//** +/**********************************************************************//** Return the tile at the given index. -*****************************************************************************/ +**************************************************************************/ Tile *api_find_tile_by_index(lua_State *L, int tindex) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -135,9 +135,9 @@ Tile *api_find_tile_by_index(lua_State *L, int tindex) return index_to_tile(&(wld.map), tindex); } -/*************************************************************************//** +/**********************************************************************//** Return the government with the given Government_type_id index. -*****************************************************************************/ +**************************************************************************/ Government *api_find_government(lua_State *L, int government_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -145,10 +145,11 @@ Government *api_find_government(lua_State *L, int government_id) return government_by_number(government_id); } -/*************************************************************************//** +/**********************************************************************//** Return the governmet with the given name_orig. -*****************************************************************************/ -Government *api_find_government_by_name(lua_State *L, const char *name_orig) +**************************************************************************/ +Government *api_find_government_by_name(lua_State *L, + const char *name_orig) { LUASCRIPT_CHECK_STATE(L, NULL); LUASCRIPT_CHECK_ARG_NIL(L, name_orig, 2, string, NULL); @@ -156,9 +157,9 @@ Government *api_find_government_by_name(lua_State *L, const char *name_orig) return government_by_rule_name(name_orig); } -/*************************************************************************//** +/**********************************************************************//** Return the nation type with the given nation_type_id index. -*****************************************************************************/ +**************************************************************************/ Nation_Type *api_find_nation_type(lua_State *L, int nation_type_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -166,10 +167,11 @@ Nation_Type *api_find_nation_type(lua_State *L, int nation_type_id) return nation_by_number(nation_type_id); } -/*************************************************************************//** +/**********************************************************************//** Return the nation type with the given name_orig. -*****************************************************************************/ -Nation_Type *api_find_nation_type_by_name(lua_State *L, const char *name_orig) +**************************************************************************/ +Nation_Type *api_find_nation_type_by_name(lua_State *L, + const char *name_orig) { LUASCRIPT_CHECK_STATE(L, NULL); LUASCRIPT_CHECK_ARG_NIL(L, name_orig, 2, string, NULL); @@ -177,9 +179,9 @@ Nation_Type *api_find_nation_type_by_name(lua_State *L, const char *name_orig) return nation_by_rule_name(name_orig); } -/*************************************************************************//** +/**********************************************************************//** Return the action type with the given action_id number. -*****************************************************************************/ +**************************************************************************/ Action *api_find_action(lua_State *L, action_id act_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -187,9 +189,9 @@ Action *api_find_action(lua_State *L, action_id act_id) return action_by_number(act_id); } -/*************************************************************************//** +/**********************************************************************//** Return the action with the given name_orig. -*****************************************************************************/ +**************************************************************************/ Action *api_find_action_by_name(lua_State *L, const char *name_orig) { @@ -199,9 +201,9 @@ Action *api_find_action_by_name(lua_State *L, const char *name_orig) return action_by_rule_name(name_orig); } -/*************************************************************************//** +/**********************************************************************//** Return the improvement type with the given impr_type_id index. -*****************************************************************************/ +**************************************************************************/ Building_Type *api_find_building_type(lua_State *L, int building_type_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -209,9 +211,9 @@ Building_Type *api_find_building_type(lua_State *L, int building_type_id) return improvement_by_number(building_type_id); } -/*************************************************************************//** +/**********************************************************************//** Return the improvement type with the given name_orig. -*****************************************************************************/ +**************************************************************************/ Building_Type *api_find_building_type_by_name(lua_State *L, const char *name_orig) { @@ -221,9 +223,9 @@ Building_Type *api_find_building_type_by_name(lua_State *L, return improvement_by_rule_name(name_orig); } -/*************************************************************************//** +/**********************************************************************//** Return the unit type with the given unit_type_id index. -*****************************************************************************/ +**************************************************************************/ Unit_Type *api_find_unit_type(lua_State *L, int unit_type_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -231,9 +233,9 @@ Unit_Type *api_find_unit_type(lua_State *L, int unit_type_id) return utype_by_number(unit_type_id); } -/*************************************************************************//** +/**********************************************************************//** Return the unit type with the given name_orig. -*****************************************************************************/ +**************************************************************************/ Unit_Type *api_find_unit_type_by_name(lua_State *L, const char *name_orig) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -242,9 +244,9 @@ Unit_Type *api_find_unit_type_by_name(lua_State *L, const char *name_orig) return unit_type_by_rule_name(name_orig); } -/*************************************************************************//** +/**********************************************************************//** Return the tech type with the given tech_type_id index. -*****************************************************************************/ +**************************************************************************/ Tech_Type *api_find_tech_type(lua_State *L, int tech_type_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -252,9 +254,9 @@ Tech_Type *api_find_tech_type(lua_State *L, int tech_type_id) return advance_by_number(tech_type_id); } -/*************************************************************************//** +/**********************************************************************//** Return the tech type with the given name_orig. -*****************************************************************************/ +**************************************************************************/ Tech_Type *api_find_tech_type_by_name(lua_State *L, const char *name_orig) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -263,9 +265,9 @@ Tech_Type *api_find_tech_type_by_name(lua_State *L, const char *name_orig) return advance_by_rule_name(name_orig); } -/*************************************************************************//** +/**********************************************************************//** Return the terrain with the given terrain_id index. -*****************************************************************************/ +**************************************************************************/ Terrain *api_find_terrain(lua_State *L, int terrain_id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -273,9 +275,9 @@ Terrain *api_find_terrain(lua_State *L, int terrain_id) return terrain_by_number(terrain_id); } -/*************************************************************************//** +/**********************************************************************//** Return the terrain with the given name_orig. -*****************************************************************************/ +**************************************************************************/ Terrain *api_find_terrain_by_name(lua_State *L, const char *name_orig) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -284,9 +286,9 @@ Terrain *api_find_terrain_by_name(lua_State *L, const char *name_orig) return terrain_by_rule_name(name_orig); } -/**********************************************************************//***** +/**********************************************************************//** Return the direction with the given id -*****************************************************************************/ +**************************************************************************/ const Direction *api_find_direction(lua_State *L, int id) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -315,9 +317,9 @@ Action *api_find_action_type_by_name(lua_State *L, const char *name) return action_by_rule_name(name); } -/*************************************************************************//** +/**********************************************************************//** Return a dummy pointer. -*****************************************************************************/ +**************************************************************************/ Nonexistent *api_find_nonexistent(lua_State *L) { static char *p = ""; diff --git a/common/scriptcore/api_game_methods.c b/common/scriptcore/api_game_methods.c index a13cfdea66..090a15b6bc 100644 --- a/common/scriptcore/api_game_methods.c +++ b/common/scriptcore/api_game_methods.c @@ -43,9 +43,9 @@ #include "api_game_methods.h" -/*************************************************************************//** +/**********************************************************************//** Return the current turn. -*****************************************************************************/ +**************************************************************************/ int api_methods_game_turn(lua_State *L) { LUASCRIPT_CHECK_STATE(L, 0); @@ -53,9 +53,9 @@ int api_methods_game_turn(lua_State *L) return game.info.turn; } -/*************************************************************************//** +/**********************************************************************//** Return the current year. -*****************************************************************************/ +**************************************************************************/ int api_methods_game_year(lua_State *L) { LUASCRIPT_CHECK_STATE(L, 0); @@ -63,9 +63,9 @@ int api_methods_game_year(lua_State *L) return game.info.year; } -/*************************************************************************//** +/**********************************************************************//** Return the current year fragment. -*****************************************************************************/ +**************************************************************************/ int api_methods_game_year_fragment(lua_State *L) { LUASCRIPT_CHECK_STATE(L, 0); @@ -73,9 +73,9 @@ int api_methods_game_year_fragment(lua_State *L) return game.info.fragment_count; } -/*************************************************************************//** +/**********************************************************************//** Return textual representation of the current calendar time. -*****************************************************************************/ +**************************************************************************/ const char *api_methods_game_year_text(lua_State *L) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -83,9 +83,9 @@ const char *api_methods_game_year_text(lua_State *L) return calendar_text(); } -/*************************************************************************//** +/**********************************************************************//** Return the current turn, as if real turns started from 0. -*****************************************************************************/ +**************************************************************************/ int api_methods_game_turn_deprecated(lua_State *L) { LUASCRIPT_CHECK_STATE(L, 0); @@ -100,25 +100,25 @@ int api_methods_game_turn_deprecated(lua_State *L) return game.info.turn; } -/*************************************************************************//** +/**********************************************************************//** Return name of the current ruleset. -*****************************************************************************/ +**************************************************************************/ const char *api_methods_game_rulesetdir(lua_State *L) { return game.server.rulesetdir; } -/*************************************************************************//** +/**********************************************************************//** Return name of the current ruleset. -*****************************************************************************/ +**************************************************************************/ const char *api_methods_game_ruleset_name(lua_State *L) { return game.control.name; } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if pbuilding is a wonder. -*****************************************************************************/ +**************************************************************************/ bool api_methods_building_type_is_wonder(lua_State *L, Building_Type *pbuilding) { @@ -128,9 +128,9 @@ bool api_methods_building_type_is_wonder(lua_State *L, return is_wonder(pbuilding); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if pbuilding is a great wonder. -*****************************************************************************/ +**************************************************************************/ bool api_methods_building_type_is_great_wonder(lua_State *L, Building_Type *pbuilding) { @@ -140,9 +140,9 @@ bool api_methods_building_type_is_great_wonder(lua_State *L, return is_great_wonder(pbuilding); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if pbuilding is a small wonder. -*****************************************************************************/ +**************************************************************************/ bool api_methods_building_type_is_small_wonder(lua_State *L, Building_Type *pbuilding) { @@ -152,9 +152,9 @@ bool api_methods_building_type_is_small_wonder(lua_State *L, return is_small_wonder(pbuilding); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if pbuilding is a building. -*****************************************************************************/ +**************************************************************************/ bool api_methods_building_type_is_improvement(lua_State *L, Building_Type *pbuilding) { @@ -164,9 +164,9 @@ bool api_methods_building_type_is_improvement(lua_State *L, return is_improvement(pbuilding); } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Building_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_building_type_rule_name(lua_State *L, Building_Type *pbuilding) { @@ -176,9 +176,9 @@ const char *api_methods_building_type_rule_name(lua_State *L, return improvement_rule_name(pbuilding); } -/*************************************************************************//** +/**********************************************************************//** Return translated name for Building_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_building_type_name_translation(lua_State *L, Building_Type *pbuilding) @@ -189,9 +189,9 @@ const char return improvement_name_translation(pbuilding); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE iff city has building -*****************************************************************************/ +**************************************************************************/ bool api_methods_city_has_building(lua_State *L, City *pcity, Building_Type *building) { @@ -202,9 +202,9 @@ bool api_methods_city_has_building(lua_State *L, City *pcity, return city_has_building(pcity, building); } -/*************************************************************************//** +/**********************************************************************//** Return the square raduis of the city map. -*****************************************************************************/ +**************************************************************************/ int api_methods_city_map_sq_radius(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, 0); @@ -213,9 +213,9 @@ int api_methods_city_map_sq_radius(lua_State *L, City *pcity) return city_map_radius_sq_get(pcity); } -/*************************************************************************//** +/**********************************************************************//** Return the size of the city. -*****************************************************************************/ +**************************************************************************/ int api_methods_city_size_get(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, 1); @@ -224,9 +224,9 @@ int api_methods_city_size_get(lua_State *L, City *pcity) return city_size_get(pcity); } -/*************************************************************************//** +/**********************************************************************//** Return the tile of the city. -*****************************************************************************/ +**************************************************************************/ Tile *api_methods_city_tile_get(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -235,10 +235,11 @@ Tile *api_methods_city_tile_get(lua_State *L, City *pcity) return pcity->tile; } -/*************************************************************************//** +/**********************************************************************//** How much city inspires partisans for a player. -*****************************************************************************/ -int api_methods_city_inspire_partisans(lua_State *L, City *self, Player *inspirer) +**************************************************************************/ +int api_methods_city_inspire_partisans(lua_State *L, City *self, + Player *inspirer) { bool inspired = FALSE; @@ -279,9 +280,9 @@ int api_methods_city_inspire_partisans(lua_State *L, City *self, Player *inspire return 0; } -/*************************************************************************//** +/**********************************************************************//** How much culture city has? -*****************************************************************************/ +**************************************************************************/ int api_methods_city_culture_get(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, 0); @@ -290,9 +291,9 @@ int api_methods_city_culture_get(lua_State *L, City *pcity) return city_culture(pcity); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE iff city happy -*****************************************************************************/ +**************************************************************************/ bool api_methods_is_city_happy(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -302,9 +303,9 @@ bool api_methods_is_city_happy(lua_State *L, City *pcity) return is_server() ? city_happy(pcity) : pcity->client.happy; } -/*************************************************************************//** +/**********************************************************************//** Return TRUE iff city is unhappy -*****************************************************************************/ +**************************************************************************/ bool api_methods_is_city_unhappy(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -314,9 +315,9 @@ bool api_methods_is_city_unhappy(lua_State *L, City *pcity) return is_server() ? city_unhappy(pcity) : pcity->client.unhappy; } -/*************************************************************************//** +/**********************************************************************//** Return TRUE iff city is celebrating -*****************************************************************************/ +**************************************************************************/ bool api_methods_is_city_celebrating(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -325,9 +326,9 @@ bool api_methods_is_city_celebrating(lua_State *L, City *pcity) return city_celebrating(pcity); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE iff city is government center -*****************************************************************************/ +**************************************************************************/ bool api_methods_is_gov_center(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -336,9 +337,9 @@ bool api_methods_is_gov_center(lua_State *L, City *pcity) return is_gov_center(pcity); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if city is capital -*****************************************************************************/ +**************************************************************************/ bool api_methods_is_capital(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -347,9 +348,9 @@ bool api_methods_is_capital(lua_State *L, City *pcity) return is_capital(pcity); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if city is primary capital -*****************************************************************************/ +**************************************************************************/ bool api_methods_is_primary_capital(lua_State *L, City *pcity) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -358,9 +359,9 @@ bool api_methods_is_primary_capital(lua_State *L, City *pcity) return pcity->capital == CAPITAL_PRIMARY; } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Government -*****************************************************************************/ +**************************************************************************/ const char *api_methods_government_rule_name(lua_State *L, Government *pgovernment) { @@ -370,9 +371,9 @@ const char *api_methods_government_rule_name(lua_State *L, return government_rule_name(pgovernment); } -/*************************************************************************//** +/**********************************************************************//** Return translated name for Government -*****************************************************************************/ +**************************************************************************/ const char *api_methods_government_name_translation(lua_State *L, Government *pgovernment) { @@ -382,9 +383,9 @@ const char *api_methods_government_name_translation(lua_State *L, return government_name_translation(pgovernment); } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Nation_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_nation_type_rule_name(lua_State *L, Nation_Type *pnation) { @@ -394,9 +395,9 @@ const char *api_methods_nation_type_rule_name(lua_State *L, return nation_rule_name(pnation); } -/*************************************************************************//** +/**********************************************************************//** Return translated adjective for Nation_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_nation_type_name_translation(lua_State *L, Nation_Type *pnation) { @@ -406,9 +407,9 @@ const char *api_methods_nation_type_name_translation(lua_State *L, return nation_adjective_translation(pnation); } -/*************************************************************************//** +/**********************************************************************//** Return translated plural noun for Nation_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_nation_type_plural_translation(lua_State *L, Nation_Type *pnation) { @@ -418,10 +419,11 @@ const char *api_methods_nation_type_plural_translation(lua_State *L, return nation_plural_translation(pnation); } -/*************************************************************************//** +/**********************************************************************//** Return gui type string of the controlling connection. -*****************************************************************************/ -const char *api_methods_player_controlling_gui(lua_State *L, Player *pplayer) +**************************************************************************/ +const char *api_methods_player_controlling_gui(lua_State *L, + Player *pplayer) { struct connection *conn = NULL; @@ -442,9 +444,9 @@ const char *api_methods_player_controlling_gui(lua_State *L, Player *pplayer) return gui_type_name(conn->client_gui); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE iff player has wonder -*****************************************************************************/ +**************************************************************************/ bool api_methods_player_has_wonder(lua_State *L, Player *pplayer, Building_Type *building) { @@ -455,9 +457,9 @@ bool api_methods_player_has_wonder(lua_State *L, Player *pplayer, return wonder_is_built(pplayer, building); } -/*************************************************************************//** +/**********************************************************************//** Return player number -*****************************************************************************/ +**************************************************************************/ int api_methods_player_number(lua_State *L, Player *pplayer) { LUASCRIPT_CHECK_STATE(L, -1); @@ -466,9 +468,9 @@ int api_methods_player_number(lua_State *L, Player *pplayer) return player_number(pplayer); } -/*************************************************************************//** +/**********************************************************************//** Return the number of cities pplayer has. -*****************************************************************************/ +**************************************************************************/ int api_methods_player_num_cities(lua_State *L, Player *pplayer) { LUASCRIPT_CHECK_STATE(L, 0); @@ -477,9 +479,9 @@ int api_methods_player_num_cities(lua_State *L, Player *pplayer) return city_list_size(pplayer->cities); } -/*************************************************************************//** +/**********************************************************************//** Return the number of units pplayer has. -*****************************************************************************/ +**************************************************************************/ int api_methods_player_num_units(lua_State *L, Player *pplayer) { LUASCRIPT_CHECK_STATE(L, 0); @@ -488,9 +490,9 @@ int api_methods_player_num_units(lua_State *L, Player *pplayer) return unit_list_size(pplayer->units); } -/*************************************************************************//** +/**********************************************************************//** Return gold for Player -*****************************************************************************/ +**************************************************************************/ int api_methods_player_gold(lua_State *L, Player *pplayer) { LUASCRIPT_CHECK_STATE(L, 0); @@ -499,9 +501,9 @@ int api_methods_player_gold(lua_State *L, Player *pplayer) return pplayer->economic.gold; } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if Player knows advance ptech. -*****************************************************************************/ +**************************************************************************/ bool api_methods_player_knows_tech(lua_State *L, Player *pplayer, Tech_Type *ptech) { @@ -513,9 +515,9 @@ bool api_methods_player_knows_tech(lua_State *L, Player *pplayer, advance_number(ptech)) == TECH_KNOWN; } -/*************************************************************************//** +/**********************************************************************//** How much culture player has? -*****************************************************************************/ +**************************************************************************/ int api_methods_player_culture_get(lua_State *L, Player *pplayer) { LUASCRIPT_CHECK_STATE(L, 0); @@ -524,10 +526,11 @@ int api_methods_player_culture_get(lua_State *L, Player *pplayer) return player_culture(pplayer); } -/*************************************************************************//** +/**********************************************************************//** Does player have flag set? -*****************************************************************************/ -bool api_methods_player_has_flag(lua_State *L, Player *pplayer, const char *flag) +**************************************************************************/ +bool api_methods_player_has_flag(lua_State *L, Player *pplayer, + const char *flag) { enum plr_flag_id flag_val; @@ -543,9 +546,9 @@ bool api_methods_player_has_flag(lua_State *L, Player *pplayer, const char *flag return FALSE; } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if players share research. -*****************************************************************************/ +**************************************************************************/ bool api_methods_player_shares_research(lua_State *L, Player *pplayer, Player *aplayer) { @@ -556,9 +559,9 @@ bool api_methods_player_shares_research(lua_State *L, Player *pplayer, return research_get(pplayer) == research_get(aplayer); } -/*************************************************************************//** +/**********************************************************************//** Return name of the research group player belongs to. -*****************************************************************************/ +**************************************************************************/ const char *api_methods_research_rule_name(lua_State *L, Player *pplayer) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -567,10 +570,11 @@ const char *api_methods_research_rule_name(lua_State *L, Player *pplayer) return research_rule_name(research_get(pplayer)); } -/*************************************************************************//** +/**********************************************************************//** Return name of the research group player belongs to. -*****************************************************************************/ -const char *api_methods_research_name_translation(lua_State *L, Player *pplayer) +**************************************************************************/ +const char *api_methods_research_name_translation(lua_State *L, + Player *pplayer) { static char buf[MAX_LEN_MSG]; @@ -582,9 +586,9 @@ const char *api_methods_research_name_translation(lua_State *L, Player *pplayer) return buf; } -/*************************************************************************//** +/**********************************************************************//** Return list head for unit list for Player -*****************************************************************************/ +**************************************************************************/ Unit_List_Link *api_methods_private_player_unit_list_head(lua_State *L, Player *pplayer) { @@ -593,9 +597,9 @@ Unit_List_Link *api_methods_private_player_unit_list_head(lua_State *L, return unit_list_head(pplayer->units); } -/*************************************************************************//** +/**********************************************************************//** Return list head for city list for Player -*****************************************************************************/ +**************************************************************************/ City_List_Link *api_methods_private_player_city_list_head(lua_State *L, Player *pplayer) { @@ -605,9 +609,9 @@ City_List_Link *api_methods_private_player_city_list_head(lua_State *L, return city_list_head(pplayer->cities); } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Tech_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_tech_type_rule_name(lua_State *L, Tech_Type *ptech) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -616,9 +620,9 @@ const char *api_methods_tech_type_rule_name(lua_State *L, Tech_Type *ptech) return advance_rule_name(ptech); } -/*************************************************************************//** +/**********************************************************************//** Return translated name for Tech_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_tech_type_name_translation(lua_State *L, Tech_Type *ptech) { @@ -628,9 +632,9 @@ const char *api_methods_tech_type_name_translation(lua_State *L, return advance_name_translation(ptech); } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Terrain -*****************************************************************************/ +**************************************************************************/ const char *api_methods_terrain_rule_name(lua_State *L, Terrain *pterrain) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -639,9 +643,9 @@ const char *api_methods_terrain_rule_name(lua_State *L, Terrain *pterrain) return terrain_rule_name(pterrain); } -/*************************************************************************//** +/**********************************************************************//** Return translated name for Terrain -*****************************************************************************/ +**************************************************************************/ const char *api_methods_terrain_name_translation(lua_State *L, Terrain *pterrain) { @@ -651,9 +655,9 @@ const char *api_methods_terrain_name_translation(lua_State *L, return terrain_name_translation(pterrain); } -/*************************************************************************//** +/**********************************************************************//** Return name of the terrain's class -*****************************************************************************/ +**************************************************************************/ const char *api_methods_terrain_class_name(lua_State *L, Terrain *pterrain) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -662,9 +666,9 @@ const char *api_methods_terrain_class_name(lua_State *L, Terrain *pterrain) return terrain_class_name(terrain_type_terrain_class(pterrain)); } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Disaster -*****************************************************************************/ +**************************************************************************/ const char *api_methods_disaster_rule_name(lua_State *L, Disaster *pdis) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -673,9 +677,9 @@ const char *api_methods_disaster_rule_name(lua_State *L, Disaster *pdis) return disaster_rule_name(pdis); } -/*************************************************************************//** +/**********************************************************************//** Return translated name for Disaster -*****************************************************************************/ +**************************************************************************/ const char *api_methods_disaster_name_translation(lua_State *L, Disaster *pdis) { @@ -685,10 +689,11 @@ const char *api_methods_disaster_name_translation(lua_State *L, return disaster_name_translation(pdis); } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Achievement -*****************************************************************************/ -const char *api_methods_achievement_rule_name(lua_State *L, Achievement *pach) +**************************************************************************/ +const char *api_methods_achievement_rule_name(lua_State *L, + Achievement *pach) { LUASCRIPT_CHECK_STATE(L, NULL); LUASCRIPT_CHECK_SELF(L, pach, NULL); @@ -696,9 +701,9 @@ const char *api_methods_achievement_rule_name(lua_State *L, Achievement *pach) return achievement_rule_name(pach); } -/*************************************************************************//** +/**********************************************************************//** Return translated name for Achievement -*****************************************************************************/ +**************************************************************************/ const char *api_methods_achievement_name_translation(lua_State *L, Achievement *pach) { @@ -708,9 +713,9 @@ const char *api_methods_achievement_name_translation(lua_State *L, return achievement_name_translation(pach); } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Action -*****************************************************************************/ +**************************************************************************/ const char *api_methods_action_rule_name(lua_State *L, Action *pact) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -719,9 +724,9 @@ const char *api_methods_action_rule_name(lua_State *L, Action *pact) return action_id_rule_name(pact->id); } -/*************************************************************************//** +/**********************************************************************//** Return translated name for Action -*****************************************************************************/ +**************************************************************************/ const char *api_methods_action_name_translation(lua_State *L, Action *pact) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -746,9 +751,9 @@ const char *api_methods_action_target_kind(lua_State *L, Action *pact) return action_target_kind_name(action_get_target_kind(paction)); } -/*************************************************************************//** +/**********************************************************************//** Return the native x coordinate of the tile. -*****************************************************************************/ +**************************************************************************/ int api_methods_tile_nat_x(lua_State *L, Tile *ptile) { LUASCRIPT_CHECK_STATE(L, -1); @@ -757,9 +762,9 @@ int api_methods_tile_nat_x(lua_State *L, Tile *ptile) return index_to_native_pos_x(tile_index(ptile)); } -/*************************************************************************//** +/**********************************************************************//** Return the native y coordinate of the tile. -*****************************************************************************/ +**************************************************************************/ int api_methods_tile_nat_y(lua_State *L, Tile *ptile) { LUASCRIPT_CHECK_STATE(L, -1); @@ -768,9 +773,9 @@ int api_methods_tile_nat_y(lua_State *L, Tile *ptile) return index_to_native_pos_y(tile_index(ptile)); } -/*************************************************************************//** +/**********************************************************************//** Return the map x coordinate of the tile. -*****************************************************************************/ +**************************************************************************/ int api_methods_tile_map_x(lua_State *L, Tile *ptile) { LUASCRIPT_CHECK_STATE(L, -1); @@ -779,9 +784,9 @@ int api_methods_tile_map_x(lua_State *L, Tile *ptile) return index_to_map_pos_x(tile_index(ptile)); } -/*************************************************************************//** +/**********************************************************************//** Return the map y coordinate of the tile. -*****************************************************************************/ +**************************************************************************/ int api_methods_tile_map_y(lua_State *L, Tile *ptile) { LUASCRIPT_CHECK_STATE(L, -1); @@ -790,9 +795,9 @@ int api_methods_tile_map_y(lua_State *L, Tile *ptile) return index_to_map_pos_y(tile_index(ptile)); } -/*************************************************************************//** +/**********************************************************************//** Return City on ptile, else NULL -*****************************************************************************/ +**************************************************************************/ City *api_methods_tile_city(lua_State *L, Tile *ptile) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -801,9 +806,9 @@ City *api_methods_tile_city(lua_State *L, Tile *ptile) return tile_city(ptile); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if there is a city inside the maximum city radius from ptile. -*****************************************************************************/ +**************************************************************************/ bool api_methods_tile_city_exists_within_max_city_map(lua_State *L, Tile *ptile, bool may_be_on_center) @@ -814,11 +819,12 @@ bool api_methods_tile_city_exists_within_max_city_map(lua_State *L, return city_exists_within_max_city_map(ptile, may_be_on_center); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if there is a extra with rule name name on ptile. If no name is specified return true if there is a extra on ptile. -*****************************************************************************/ -bool api_methods_tile_has_extra(lua_State *L, Tile *ptile, const char *name) +**************************************************************************/ +bool api_methods_tile_has_extra(lua_State *L, Tile *ptile, + const char *name) { LUASCRIPT_CHECK_STATE(L, FALSE); LUASCRIPT_CHECK_SELF(L, ptile, FALSE); @@ -840,10 +846,10 @@ bool api_methods_tile_has_extra(lua_State *L, Tile *ptile, const char *name) } } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if there is a base with rule name name on ptile. If no name is specified return true if there is any base on ptile. -*****************************************************************************/ +**************************************************************************/ bool api_methods_tile_has_base(lua_State *L, Tile *ptile, const char *name) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -867,10 +873,10 @@ bool api_methods_tile_has_base(lua_State *L, Tile *ptile, const char *name) } } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if there is a road with rule name name on ptile. If no name is specified return true if there is any road on ptile. -*****************************************************************************/ +**************************************************************************/ bool api_methods_tile_has_road(lua_State *L, Tile *ptile, const char *name) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -930,9 +936,9 @@ Player *api_methods_tile_extra_owner(lua_State *L, } } -/*************************************************************************//** +/**********************************************************************//** Is tile occupied by enemies -*****************************************************************************/ +**************************************************************************/ bool api_methods_enemy_tile(lua_State *L, Tile *ptile, Player *against) { struct city *pcity; @@ -952,9 +958,9 @@ bool api_methods_enemy_tile(lua_State *L, Tile *ptile, Player *against) return FALSE; } -/*************************************************************************//** +/**********************************************************************//** Return number of units on tile -*****************************************************************************/ +**************************************************************************/ int api_methods_tile_num_units(lua_State *L, Tile *ptile) { LUASCRIPT_CHECK_STATE(L, 0); @@ -963,9 +969,9 @@ int api_methods_tile_num_units(lua_State *L, Tile *ptile) return unit_list_size(ptile->units); } -/*************************************************************************//** +/**********************************************************************//** Return list head for unit list for Tile -*****************************************************************************/ +**************************************************************************/ Unit_List_Link *api_methods_private_tile_unit_list_head(lua_State *L, Tile *ptile) { @@ -975,10 +981,10 @@ Unit_List_Link *api_methods_private_tile_unit_list_head(lua_State *L, return unit_list_head(ptile->units); } -/*************************************************************************//** +/**********************************************************************//** Return nth tile iteration index (for internal use) Will return the next index, or an index < 0 when done -*****************************************************************************/ +**************************************************************************/ int api_methods_private_tile_next_outward_index(lua_State *L, Tile *pstart, int tindex, int max_dist) { @@ -1015,11 +1021,11 @@ int api_methods_private_tile_next_outward_index(lua_State *L, Tile *pstart, return -1; } -/*************************************************************************//** +/**********************************************************************//** Return tile for nth iteration index (for internal use) -*****************************************************************************/ -Tile *api_methods_private_tile_for_outward_index(lua_State *L, Tile *pstart, - int tindex) +**************************************************************************/ +Tile *api_methods_private_tile_for_outward_index(lua_State *L, + Tile *pstart, int tindex) { int newx, newy; @@ -1040,9 +1046,9 @@ Tile *api_methods_private_tile_for_outward_index(lua_State *L, Tile *pstart, return map_pos_to_tile(&(wld.map), newx, newy); } -/*************************************************************************//** +/**********************************************************************//** Return squared distance between tiles 1 and 2 -*****************************************************************************/ +**************************************************************************/ int api_methods_tile_sq_distance(lua_State *L, Tile *ptile1, Tile *ptile2) { LUASCRIPT_CHECK_STATE(L, 0); @@ -1052,9 +1058,9 @@ int api_methods_tile_sq_distance(lua_State *L, Tile *ptile1, Tile *ptile2) return sq_map_distance(ptile1, ptile2); } -/*************************************************************************//** +/**********************************************************************//** Can punit found a city on its tile? -*****************************************************************************/ +**************************************************************************/ bool api_methods_unit_city_can_be_built_here(lua_State *L, Unit *punit) { LUASCRIPT_CHECK_STATE(L, FALSE); @@ -1063,9 +1069,9 @@ bool api_methods_unit_city_can_be_built_here(lua_State *L, Unit *punit) return city_can_be_built_here(unit_tile(punit), punit); } -/*************************************************************************//** +/**********************************************************************//** Return the tile of the unit. -*****************************************************************************/ +**************************************************************************/ Tile *api_methods_unit_tile_get(lua_State *L, Unit *punit) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -1074,10 +1080,11 @@ Tile *api_methods_unit_tile_get(lua_State *L, Unit *punit) return unit_tile(punit); } -/*************************************************************************//** +/**********************************************************************//** Get unit orientation -*****************************************************************************/ -const Direction *api_methods_unit_orientation_get(lua_State *L, Unit *punit) +**************************************************************************/ +const Direction *api_methods_unit_orientation_get(lua_State *L, + Unit *punit) { LUASCRIPT_CHECK_STATE(L, NULL); LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, NULL); @@ -1085,9 +1092,9 @@ const Direction *api_methods_unit_orientation_get(lua_State *L, Unit *punit) return luascript_dir(punit->facing); } -/*************************************************************************//** +/**********************************************************************//** Return Unit that transports punit, if any. -*****************************************************************************/ +**************************************************************************/ Unit *api_methods_unit_transporter(lua_State *L, Unit *punit) { LUASCRIPT_CHECK_STATE(L, NULL); @@ -1096,9 +1103,9 @@ Unit *api_methods_unit_transporter(lua_State *L, Unit *punit) return punit->transporter; } -/*************************************************************************//** +/**********************************************************************//** Return list head for cargo list for Unit -*****************************************************************************/ +**************************************************************************/ Unit_List_Link *api_methods_private_unit_cargo_list_head(lua_State *L, Unit *punit) { @@ -1107,9 +1114,9 @@ Unit_List_Link *api_methods_private_unit_cargo_list_head(lua_State *L, return unit_list_head(punit->transporting); } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if punit_type has flag. -*****************************************************************************/ +**************************************************************************/ bool api_methods_unit_type_has_flag(lua_State *L, Unit_Type *punit_type, const char *flag) { @@ -1128,9 +1135,9 @@ bool api_methods_unit_type_has_flag(lua_State *L, Unit_Type *punit_type, } } -/*************************************************************************//** +/**********************************************************************//** Return TRUE if punit_type has role. -*****************************************************************************/ +**************************************************************************/ bool api_methods_unit_type_has_role(lua_State *L, Unit_Type *punit_type, const char *role) { @@ -1149,9 +1156,9 @@ bool api_methods_unit_type_has_role(lua_State *L, Unit_Type *punit_type, } } -/*************************************************************************//** +/**********************************************************************//** Return TRUE iff the unit type can exist on the tile. -*****************************************************************************/ +**************************************************************************/ bool api_methods_unit_type_can_exist_at_tile(lua_State *L, Unit_Type *punit_type, Tile *ptile) @@ -1163,9 +1170,9 @@ bool api_methods_unit_type_can_exist_at_tile(lua_State *L, return can_exist_at_tile(&(wld.map), punit_type, ptile); } -/*************************************************************************//** +/**********************************************************************//** Return rule name for Unit_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_unit_type_rule_name(lua_State *L, Unit_Type *punit_type) { @@ -1175,9 +1182,9 @@ const char *api_methods_unit_type_rule_name(lua_State *L, return utype_rule_name(punit_type); } -/*************************************************************************//** +/**********************************************************************//** Return translated name for Unit_Type -*****************************************************************************/ +**************************************************************************/ const char *api_methods_unit_type_name_translation(lua_State *L, Unit_Type *punit_type) { @@ -1188,9 +1195,9 @@ const char *api_methods_unit_type_name_translation(lua_State *L, } -/*************************************************************************//** +/**********************************************************************//** Return Unit for list link -*****************************************************************************/ +**************************************************************************/ Unit *api_methods_unit_list_link_data(lua_State *L, Unit_List_Link *ul_link) { @@ -1199,9 +1206,9 @@ Unit *api_methods_unit_list_link_data(lua_State *L, return unit_list_link_data(ul_link); } -/*************************************************************************//** +/**********************************************************************//** Return next list link or NULL when link is the last link -*****************************************************************************/ +**************************************************************************/ Unit_List_Link *api_methods_unit_list_next_link(lua_State *L, Unit_List_Link *ul_link) { @@ -1210,9 +1217,9 @@ Unit_List_Link *api_methods_unit_list_next_link(lua_State *L, return unit_list_link_next(ul_link); } -/*************************************************************************//** +/**********************************************************************//** Return City for list link -*****************************************************************************/ +**************************************************************************/ City *api_methods_city_list_link_data(lua_State *L, City_List_Link *cl_link) { @@ -1221,9 +1228,9 @@ City *api_methods_city_list_link_data(lua_State *L, return city_list_link_data(cl_link); } -/*************************************************************************//** +/**********************************************************************//** Return next list link or NULL when link is the last link -*****************************************************************************/ +**************************************************************************/ City_List_Link *api_methods_city_list_next_link(lua_State *L, City_List_Link *cl_link) { diff --git a/common/scriptcore/api_game_specenum.c b/common/scriptcore/api_game_specenum.c index 2bc29e9b98..804437be6f 100644 --- a/common/scriptcore/api_game_specenum.c +++ b/common/scriptcore/api_game_specenum.c @@ -35,37 +35,37 @@ #define API_SPECENUM_CREATE_TABLE(L, type, name) \ api_specenum_create_table((L), (name), API_SPECENUM_INDEX_NAME(type)) -/*************************************************************************//** +/**********************************************************************//** Define a the __index (table, key) -> value metamethod Return the enum value whose name is the concatenation of prefix and key. The fetched value is written back to the lua table, and further accesses will resolve there instead of this function. -*****************************************************************************/ -#define API_SPECENUM_DEFINE_INDEX(type_name, prefix) \ - static int (API_SPECENUM_INDEX_NAME(type_name))(lua_State *L) \ - { \ - static char _buf[128]; \ - const char *_key; \ - enum type_name _value; \ - luaL_checktype(L, 1, LUA_TTABLE); \ - _key = luaL_checkstring(L, 2); \ - fc_snprintf(_buf, sizeof(_buf), prefix "%s", _key); \ - _value = type_name##_by_name(_buf, strcmp); \ - if (_value != type_name##_invalid()) { \ - /* T[_key] = _value */ \ - lua_pushstring(L, _key); \ - lua_pushinteger(L, _value); \ - lua_rawset(L, 1); \ - lua_pushinteger(L, _value); \ - } else { \ - lua_pushnil(L); \ - } \ - return 1; \ +**************************************************************************/ +#define API_SPECENUM_DEFINE_INDEX(type_name, prefix) \ + static int (API_SPECENUM_INDEX_NAME(type_name))(lua_State *L) \ + { \ + static char _buf[128]; \ + const char *_key; \ + enum type_name _value; \ + luaL_checktype(L, 1, LUA_TTABLE); \ + _key = luaL_checkstring(L, 2); \ + fc_snprintf(_buf, sizeof(_buf), prefix "%s", _key); \ + _value = type_name##_by_name(_buf, strcmp); \ + if (_value != type_name##_invalid()) { \ + /* T[_key] = _value */ \ + lua_pushstring(L, _key); \ + lua_pushinteger(L, _value); \ + lua_rawset(L, 1); \ + lua_pushinteger(L, _value); \ + } else { \ + lua_pushnil(L); \ + } \ + return 1; \ } -/*************************************************************************//** +/**********************************************************************//** Create a module table and set the member lookup function. -*****************************************************************************/ +**************************************************************************/ static void api_specenum_create_table(lua_State *L, const char *name, lua_CFunction findex) { @@ -87,14 +87,14 @@ static void api_specenum_create_table(lua_State *L, const char *name, lua_pop(L, 1); } -/*************************************************************************//** +/**********************************************************************//** Define the __index function for each exported specenum type. -*****************************************************************************/ +**************************************************************************/ API_SPECENUM_DEFINE_INDEX(event_type, "E_") -/*************************************************************************//** +/**********************************************************************//** Load the specenum modules into Lua state L. -*****************************************************************************/ +**************************************************************************/ int api_specenum_open(lua_State *L) { API_SPECENUM_CREATE_TABLE(L, event_type, "E"); diff --git a/common/scriptcore/api_signal_base.c b/common/scriptcore/api_signal_base.c index 42a7c670b2..ebdb8e225f 100644 --- a/common/scriptcore/api_signal_base.c +++ b/common/scriptcore/api_signal_base.c @@ -21,9 +21,9 @@ #include "api_signal_base.h" -/*************************************************************************//** +/**********************************************************************//** Connects a callback function to a certain signal. -*****************************************************************************/ +**************************************************************************/ void api_signal_connect(lua_State *L, const char *signal_name, const char *callback_name) { @@ -40,9 +40,9 @@ void api_signal_connect(lua_State *L, const char *signal_name, luascript_signal_callback(fcl, signal_name, callback_name, TRUE); } -/*************************************************************************//** +/**********************************************************************//** Removes a callback function to a certain signal. -*****************************************************************************/ +**************************************************************************/ void api_signal_remove(lua_State *L, const char *signal_name, const char *callback_name) { @@ -59,9 +59,9 @@ void api_signal_remove(lua_State *L, const char *signal_name, luascript_signal_callback(fcl, signal_name, callback_name, FALSE); } -/*************************************************************************//** +/**********************************************************************//** Returns if a callback function to a certain signal is defined. -*****************************************************************************/ +**************************************************************************/ bool api_signal_defined(lua_State *L, const char *signal_name, const char *callback_name) { @@ -78,11 +78,12 @@ bool api_signal_defined(lua_State *L, const char *signal_name, return luascript_signal_callback_defined(fcl, signal_name, callback_name); } -/*************************************************************************//** +/**********************************************************************//** Return the name of the signal with the given index. -*****************************************************************************/ +**************************************************************************/ const char *api_signal_callback_by_index(lua_State *L, - const char *signal_name, int sindex) + const char *signal_name, + int sindex) { struct fc_lua *fcl; @@ -96,10 +97,10 @@ const char *api_signal_callback_by_index(lua_State *L, return luascript_signal_callback_by_index(fcl, signal_name, sindex); } -/*************************************************************************//** +/**********************************************************************//** Return the name of the 'index' callback function of the signal with the name 'signal_name'. -*****************************************************************************/ +**************************************************************************/ const char *api_signal_by_index(lua_State *L, int sindex) { struct fc_lua *fcl; diff --git a/common/scriptcore/luascript.c b/common/scriptcore/luascript.c index 080a690292..faa0a7b36a 100644 --- a/common/scriptcore/luascript.c +++ b/common/scriptcore/luascript.c @@ -126,10 +126,11 @@ static void luascript_hook_end(lua_State *L); static void luascript_openlibs(lua_State *L, const luaL_Reg *llib); static void luascript_blacklist(lua_State *L, const char *lsymbols[]); -/*************************************************************************//** +/**********************************************************************//** Report a lua error. -*****************************************************************************/ -static int luascript_report(struct fc_lua *fcl, int status, const char *code) +**************************************************************************/ +static int luascript_report(struct fc_lua *fcl, int status, + const char *code) { fc_assert_ret_val(fcl, -1); fc_assert_ret_val(fcl->state, -1); @@ -198,9 +199,9 @@ static int luascript_report(struct fc_lua *fcl, int status, const char *code) return status; } -/*************************************************************************//** +/**********************************************************************//** Find the debug.traceback function and store in the registry -*****************************************************************************/ +**************************************************************************/ static void luascript_traceback_func_save(lua_State *L) { /* Find the debug.traceback function, if available */ @@ -212,17 +213,17 @@ static void luascript_traceback_func_save(lua_State *L) lua_pop(L, 1); /* pop debug */ } -/*************************************************************************//** +/**********************************************************************//** Push the traceback function to the stack -*****************************************************************************/ +**************************************************************************/ static void luascript_traceback_func_push(lua_State *L) { lua_getfield(L, LUA_REGISTRYINDEX, "freeciv_traceback"); } -/*************************************************************************//** +/**********************************************************************//** Check currently excecuting lua function for execution time limit -*****************************************************************************/ +**************************************************************************/ static void luascript_exec_check(lua_State *L, lua_Debug *ar) { lua_Number exec_clock; @@ -236,9 +237,9 @@ static void luascript_exec_check(lua_State *L, lua_Debug *ar) } } -/*************************************************************************//** +/**********************************************************************//** Setup function execution guard -*****************************************************************************/ +**************************************************************************/ static void luascript_hook_start(lua_State *L) { #if LUASCRIPT_CHECKINTERVAL @@ -249,9 +250,9 @@ static void luascript_hook_start(lua_State *L) #endif } -/*************************************************************************//** +/**********************************************************************//** Clear function execution guard -*****************************************************************************/ +**************************************************************************/ static void luascript_hook_end(lua_State *L) { #if LUASCRIPT_CHECKINTERVAL @@ -259,9 +260,9 @@ static void luascript_hook_end(lua_State *L) #endif } -/*************************************************************************//** +/**********************************************************************//** Open lua libraries in the array of library definitions in llib. -*****************************************************************************/ +**************************************************************************/ static void luascript_openlibs(lua_State *L, const luaL_Reg *llib) { /* set results to global table */ @@ -271,9 +272,9 @@ static void luascript_openlibs(lua_State *L, const luaL_Reg *llib) } } -/*************************************************************************//** +/**********************************************************************//** Remove global symbols from lua state L -*****************************************************************************/ +**************************************************************************/ static void luascript_blacklist(lua_State *L, const char *lsymbols[]) { int i; @@ -284,9 +285,9 @@ static void luascript_blacklist(lua_State *L, const char *lsymbols[]) } } -/*************************************************************************//** +/**********************************************************************//** Internal api error function - varg version. -*****************************************************************************/ +**************************************************************************/ int luascript_error(lua_State *L, const char *format, ...) { va_list vargs; @@ -299,11 +300,11 @@ int luascript_error(lua_State *L, const char *format, ...) return ret; } -/*************************************************************************//** +/**********************************************************************//** Internal api error function. Invoking this will cause Lua to stop executing the current context and throw an exception, so to speak. -*****************************************************************************/ +**************************************************************************/ int luascript_error_vargs(lua_State *L, const char *format, va_list vargs) { fc_assert_ret_val(L != NULL, -1); @@ -315,18 +316,19 @@ int luascript_error_vargs(lua_State *L, const char *format, va_list vargs) return lua_error(L); } -/*************************************************************************//** - Like script_error, but using a prefix identifying the called lua function: +/**********************************************************************//** + Like script_error, but using a prefix identifying the called lua + function: bad argument #narg to '': msg -*****************************************************************************/ +**************************************************************************/ int luascript_arg_error(lua_State *L, int narg, const char *msg) { return luaL_argerror(L, narg, msg); } -/*************************************************************************//** +/**********************************************************************//** Initialize the scripting state. -*****************************************************************************/ +**************************************************************************/ struct fc_lua *luascript_new(luascript_log_func_t output_fct, bool secured_environment) { @@ -358,9 +360,9 @@ struct fc_lua *luascript_new(luascript_log_func_t output_fct, return fcl; } -/*************************************************************************//** +/**********************************************************************//** Get the freeciv lua struct from a lua state. -*****************************************************************************/ +**************************************************************************/ struct fc_lua *luascript_get_fcl(lua_State *L) { struct fc_lua *fcl; @@ -378,9 +380,9 @@ struct fc_lua *luascript_get_fcl(lua_State *L) return fcl; } -/*************************************************************************//** +/**********************************************************************//** Free the scripting data. -*****************************************************************************/ +**************************************************************************/ void luascript_destroy(struct fc_lua *fcl) { if (fcl) { @@ -401,9 +403,9 @@ void luascript_destroy(struct fc_lua *fcl) } } -/*************************************************************************//** +/**********************************************************************//** Print a message to the selected output handle. -*****************************************************************************/ +**************************************************************************/ void luascript_log(struct fc_lua *fcl, enum log_level level, const char *format, ...) { @@ -414,9 +416,9 @@ void luascript_log(struct fc_lua *fcl, enum log_level level, va_end(args); } -/*************************************************************************//** +/**********************************************************************//** Print a message to the selected output handle. -*****************************************************************************/ +**************************************************************************/ void luascript_log_vargs(struct fc_lua *fcl, enum log_level level, const char *format, va_list args) { @@ -434,9 +436,9 @@ void luascript_log_vargs(struct fc_lua *fcl, enum log_level level, } } -/*************************************************************************//** +/**********************************************************************//** Pop return values from the Lua stack. -*****************************************************************************/ +**************************************************************************/ void luascript_pop_returns(struct fc_lua *fcl, const char *func_name, int nreturns, enum api_types *preturn_types, va_list args) @@ -493,9 +495,9 @@ void luascript_pop_returns(struct fc_lua *fcl, const char *func_name, } } -/*************************************************************************//** +/**********************************************************************//** Push arguments into the Lua stack. -*****************************************************************************/ +**************************************************************************/ void luascript_push_args(struct fc_lua *fcl, int nargs, enum api_types *parg_types, va_list args) { @@ -543,9 +545,10 @@ void luascript_push_args(struct fc_lua *fcl, int nargs, } } -/*************************************************************************//** - Return if the function 'funcname' is define in the lua state 'fcl->state'. -*****************************************************************************/ +/**********************************************************************//** + Return if the function 'funcname' is define in the lua state + 'fcl->state'. +**************************************************************************/ bool luascript_check_function(struct fc_lua *fcl, const char *funcname) { bool defined; @@ -560,7 +563,7 @@ bool luascript_check_function(struct fc_lua *fcl, const char *funcname) return defined; } -/*************************************************************************//** +/**********************************************************************//** Evaluate a Lua function call or loaded script on the stack. Return nonzero if an error occurred. @@ -571,8 +574,9 @@ bool luascript_check_function(struct fc_lua *fcl, const char *funcname) On error, print an error message with traceback. Nothing is pushed to the stack. -*****************************************************************************/ -int luascript_call(struct fc_lua *fcl, int narg, int nret, const char *code) +**************************************************************************/ +int luascript_call(struct fc_lua *fcl, int narg, int nret, + const char *code) { int status; int base; /* Index of function to call */ @@ -607,10 +611,11 @@ int luascript_call(struct fc_lua *fcl, int narg, int nret, const char *code) return status; } -/*************************************************************************//** +/**********************************************************************//** lua_dostring replacement with error message showing on errors. -*****************************************************************************/ -int luascript_do_string(struct fc_lua *fcl, const char *str, const char *name) +**************************************************************************/ +int luascript_do_string(struct fc_lua *fcl, const char *str, + const char *name) { int status; @@ -626,9 +631,9 @@ int luascript_do_string(struct fc_lua *fcl, const char *str, const char *name) return status; } -/*************************************************************************//** +/**********************************************************************//** Parse and execute the script at filename. -*****************************************************************************/ +**************************************************************************/ int luascript_do_file(struct fc_lua *fcl, const char *filename) { int status; @@ -646,10 +651,11 @@ int luascript_do_file(struct fc_lua *fcl, const char *filename) } -/*************************************************************************//** +/**********************************************************************//** Invoke the 'callback_name' Lua function. -*****************************************************************************/ -bool luascript_callback_invoke(struct fc_lua *fcl, const char *callback_name, +**************************************************************************/ +bool luascript_callback_invoke(struct fc_lua *fcl, + const char *callback_name, int nargs, enum api_types *parg_types, va_list args) { @@ -686,11 +692,11 @@ bool luascript_callback_invoke(struct fc_lua *fcl, const char *callback_name, return stop_emission; } -/*************************************************************************//** +/**********************************************************************//** Mark any, if exported, full userdata representing 'object' in the current script state as 'Nonexistent'. This changes the type of the lua variable. -*****************************************************************************/ +**************************************************************************/ void luascript_remove_exported_object(struct fc_lua *fcl, void *object) { if (fcl && fcl->state) { @@ -725,9 +731,9 @@ void luascript_remove_exported_object(struct fc_lua *fcl, void *object) } } -/*************************************************************************//** +/**********************************************************************//** Save lua variables to file. -*****************************************************************************/ +**************************************************************************/ void luascript_vars_save(struct fc_lua *fcl, struct section_file *file, const char *section) { @@ -751,9 +757,9 @@ void luascript_vars_save(struct fc_lua *fcl, struct section_file *file, } } -/*************************************************************************//** +/**********************************************************************//** Load lua variables from file. -*****************************************************************************/ +**************************************************************************/ void luascript_vars_load(struct fc_lua *fcl, struct section_file *file, const char *section) { diff --git a/common/scriptcore/luascript_func.c b/common/scriptcore/luascript_func.c index 0b18578481..2262a451ff 100644 --- a/common/scriptcore/luascript_func.c +++ b/common/scriptcore/luascript_func.c @@ -55,9 +55,9 @@ struct luascript_func { #define luascript_func_hash_keys_iterate_end \ HASH_KEYS_ITERATE_END -/*************************************************************************//** +/**********************************************************************//** Create a new function definition. -*****************************************************************************/ +**************************************************************************/ static struct luascript_func *func_new(bool required, int nargs, enum api_types *parg_types, int nreturns, @@ -74,9 +74,9 @@ static struct luascript_func *func_new(bool required, int nargs, return pfunc; } -/*************************************************************************//** +/**********************************************************************//** Free a function definition. -*****************************************************************************/ +**************************************************************************/ static void func_destroy(struct luascript_func *pfunc) { if (pfunc->arg_types) { @@ -86,11 +86,11 @@ static void func_destroy(struct luascript_func *pfunc) free(pfunc); } -/*************************************************************************//** +/**********************************************************************//** Test if all function are defines. If it fails (return value FALSE), the missing functions are listed in 'missing_func_required' and 'missing_func_optional'. -*****************************************************************************/ +**************************************************************************/ bool luascript_func_check(struct fc_lua *fcl, struct strvec *missing_func_required, struct strvec *missing_func_optional) @@ -120,9 +120,9 @@ bool luascript_func_check(struct fc_lua *fcl, return ret; } -/*************************************************************************//** +/**********************************************************************//** Add a lua function. -*****************************************************************************/ +**************************************************************************/ void luascript_func_add_valist(struct fc_lua *fcl, const char *func_name, bool required, int nargs, int nreturns, va_list args) @@ -153,9 +153,9 @@ void luascript_func_add_valist(struct fc_lua *fcl, const char *func_name, luascript_func_hash_insert(fcl->funcs, func_name, pfunc); } -/*************************************************************************//** +/**********************************************************************//** Add a lua function. -*****************************************************************************/ +**************************************************************************/ void luascript_func_add(struct fc_lua *fcl, const char *func_name, bool required, int nargs, int nreturns, ...) { @@ -167,9 +167,9 @@ void luascript_func_add(struct fc_lua *fcl, const char *func_name, } -/*************************************************************************//** +/**********************************************************************//** Free the function definitions. -*****************************************************************************/ +**************************************************************************/ void luascript_func_free(struct fc_lua *fcl) { if (fcl && fcl->funcs) { @@ -178,9 +178,9 @@ void luascript_func_free(struct fc_lua *fcl) } } -/*************************************************************************//** +/**********************************************************************//** Initialize the structures needed to save functions definitions. -*****************************************************************************/ +**************************************************************************/ void luascript_func_init(struct fc_lua *fcl) { fc_assert_ret(fcl != NULL); @@ -191,13 +191,13 @@ void luascript_func_init(struct fc_lua *fcl) } } -/*************************************************************************//** - Call a lua function; return value is TRUE if no errors occurred, otherwise - FALSE. +/**********************************************************************//** + Call a lua function; return value is TRUE if no errors occurred, + otherwise FALSE. Example call to the lua function 'user_load()': success = luascript_func_call(L, "user_load", pconn, &password); -*****************************************************************************/ +**************************************************************************/ bool luascript_func_call_valist(struct fc_lua *fcl, const char *func_name, va_list args) { @@ -240,13 +240,13 @@ bool luascript_func_call_valist(struct fc_lua *fcl, const char *func_name, return success; } -/*************************************************************************//** - Call a lua function; return value is TRUE if no errors occurred, otherwise - FALSE. +/**********************************************************************//** + Call a lua function; return value is TRUE if no errors occurred, + otherwise FALSE. Example call to the lua function 'user_load()': success = luascript_func_call(L, "user_load", pconn, &password); -*****************************************************************************/ +**************************************************************************/ bool luascript_func_call(struct fc_lua *fcl, const char *func_name, ...) { va_list args; @@ -259,9 +259,9 @@ bool luascript_func_call(struct fc_lua *fcl, const char *func_name, ...) return success; } -/*************************************************************************//** +/**********************************************************************//** Return iff the function is required. -*****************************************************************************/ +**************************************************************************/ bool luascript_func_is_required(struct fc_lua *fcl, const char *func_name) { struct luascript_func *pfunc; diff --git a/common/scriptcore/luascript_signal.c b/common/scriptcore/luascript_signal.c index 7493fc787c..339337c955 100644 --- a/common/scriptcore/luascript_signal.c +++ b/common/scriptcore/luascript_signal.c @@ -108,9 +108,9 @@ struct signal_callback { #define luascript_signal_name_list_iterate_end \ LIST_ITERATE_END -/*************************************************************************//** +/**********************************************************************//** Create a new signal callback. -*****************************************************************************/ +**************************************************************************/ static struct signal_callback *signal_callback_new(const char *name) { struct signal_callback *pcallback = fc_malloc(sizeof(*pcallback)); @@ -119,18 +119,18 @@ static struct signal_callback *signal_callback_new(const char *name) return pcallback; } -/*************************************************************************//** +/**********************************************************************//** Free a signal callback. -*****************************************************************************/ +**************************************************************************/ static void signal_callback_destroy(struct signal_callback *pcallback) { free(pcallback->name); free(pcallback); } -/*************************************************************************//** +/**********************************************************************//** Create a new signal. -*****************************************************************************/ +**************************************************************************/ static struct signal *signal_new(int nargs, enum api_types *parg_types) { struct signal *psignal = fc_malloc(sizeof(*psignal)); @@ -144,9 +144,9 @@ static struct signal *signal_new(int nargs, enum api_types *parg_types) return psignal; } -/*************************************************************************//** +/**********************************************************************//** Free a signal. -*****************************************************************************/ +**************************************************************************/ static void signal_destroy(struct signal *psignal) { if (psignal->arg_types) { @@ -159,10 +159,11 @@ static void signal_destroy(struct signal *psignal) free(psignal); } -/*************************************************************************//** +/**********************************************************************//** Invoke all the callback functions attached to a given signal. -*****************************************************************************/ -void luascript_signal_emit_valist(struct fc_lua *fcl, const char *signal_name, +**************************************************************************/ +void luascript_signal_emit_valist(struct fc_lua *fcl, + const char *signal_name, va_list args) { struct signal *psignal; @@ -188,10 +189,11 @@ void luascript_signal_emit_valist(struct fc_lua *fcl, const char *signal_name, } } -/*************************************************************************//** +/**********************************************************************//** Invoke all the callback functions attached to a given signal. -*****************************************************************************/ -void luascript_signal_emit(struct fc_lua *fcl, const char *signal_name, ...) +**************************************************************************/ +void luascript_signal_emit(struct fc_lua *fcl, + const char *signal_name, ...) { va_list args; @@ -200,9 +202,9 @@ void luascript_signal_emit(struct fc_lua *fcl, const char *signal_name, ...) va_end(args); } -/*************************************************************************//** +/**********************************************************************//** Create a new signal type. -*****************************************************************************/ +**************************************************************************/ static struct signal *luascript_signal_create_valist(struct fc_lua *fcl, const char *signal_name, int nargs, va_list args) @@ -235,11 +237,12 @@ static struct signal *luascript_signal_create_valist(struct fc_lua *fcl, } } -/*************************************************************************//** +/**********************************************************************//** Create a new signal type. -*****************************************************************************/ -signal_deprecator *luascript_signal_create(struct fc_lua *fcl, const char *signal_name, - int nargs, ...) +**************************************************************************/ +signal_deprecator *luascript_signal_create(struct fc_lua *fcl, + const char *signal_name, + int nargs, ...) { va_list args; struct signal *created; @@ -255,9 +258,9 @@ signal_deprecator *luascript_signal_create(struct fc_lua *fcl, const char *signa return NULL; } -/*************************************************************************//** +/**********************************************************************//** Mark signal deprecated. -*****************************************************************************/ +**************************************************************************/ void deprecate_signal(signal_deprecator *deprecator, char *signal_name, char *replacement, char *deprecated_since) { @@ -281,9 +284,9 @@ void deprecate_signal(signal_deprecator *deprecator, char *signal_name, } } -/*************************************************************************//** +/**********************************************************************//** Connects a callback function to a certain signal. -*****************************************************************************/ +**************************************************************************/ void luascript_signal_callback(struct fc_lua *fcl, const char *signal_name, const char *callback_name, bool create) { @@ -326,9 +329,9 @@ void luascript_signal_callback(struct fc_lua *fcl, const char *signal_name, } } -/*************************************************************************//** +/**********************************************************************//** Returns if a callback function to a certain signal is defined. -*****************************************************************************/ +**************************************************************************/ bool luascript_signal_callback_defined(struct fc_lua *fcl, const char *signal_name, const char *callback_name) @@ -350,18 +353,18 @@ bool luascript_signal_callback_defined(struct fc_lua *fcl, return FALSE; } -/*************************************************************************//** +/**********************************************************************//** Callback for freeing memory where luascript_signal_name_list has signal name. -*****************************************************************************/ +**************************************************************************/ static void sn_free(char *name) { FC_FREE(name); } -/*************************************************************************//** +/**********************************************************************//** Initialize script signals and callbacks. -*****************************************************************************/ +**************************************************************************/ void luascript_signal_init(struct fc_lua *fcl) { fc_assert_ret(fcl != NULL); @@ -372,9 +375,9 @@ void luascript_signal_init(struct fc_lua *fcl) } } -/*************************************************************************//** +/**********************************************************************//** Free script signals and callbacks. -*****************************************************************************/ +**************************************************************************/ void luascript_signal_free(struct fc_lua *fcl) { if (NULL != fcl && NULL != fcl->signals) { @@ -386,9 +389,9 @@ void luascript_signal_free(struct fc_lua *fcl) } } -/*************************************************************************//** +/**********************************************************************//** Return the name of the signal with the given index. -*****************************************************************************/ +**************************************************************************/ const char *luascript_signal_by_index(struct fc_lua *fcl, int sindex) { fc_assert_ret_val(fcl != NULL, NULL); @@ -397,10 +400,10 @@ const char *luascript_signal_by_index(struct fc_lua *fcl, int sindex) return luascript_signal_name_list_get(fcl->signal_names, sindex); } -/*************************************************************************//** +/**********************************************************************//** Return the name of the 'index' callback function of the signal with the name 'signal_name'. -*****************************************************************************/ +**************************************************************************/ const char *luascript_signal_callback_by_index(struct fc_lua *fcl, const char *signal_name, int sindex) -- 2.20.1