From 05467e5160e6c088a5a35fdbbece4196a197fac3 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 21 Oct 2023 11:49:00 +0300 Subject: [PATCH 38/38] Lua: Rework version functions Add name_version(), comparable_version(), and version_string() Deprecate fc_version() See osdn #48879 Signed-off-by: Marko Lindqvist --- common/scriptcore/api_common_utilities.c | 39 +++++++++++++++++++++++- common/scriptcore/api_common_utilities.h | 3 ++ common/scriptcore/tolua_common_a.pkg | 7 +++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/common/scriptcore/api_common_utilities.c b/common/scriptcore/api_common_utilities.c index d1ec6dccb7..42ba7ada84 100644 --- a/common/scriptcore/api_common_utilities.c +++ b/common/scriptcore/api_common_utilities.c @@ -46,13 +46,50 @@ int api_utilities_random(lua_State *L, int min, int max) } /********************************************************************//** - Return the version of freeciv lua script + Name and version of freeciv. + Deprecated because of the confusing function name. ************************************************************************/ const char *api_utilities_fc_version(lua_State *L) { + LUASCRIPT_CHECK_STATE(L, 0); + + log_deprecation("Deprecated: lua construct \"fc_version\", " + "deprecated since \"3.2\", used. " + "Use \"name_version\" instead."); + return freeciv_name_version(); } +/********************************************************************//** + Return the name and version of freeciv +************************************************************************/ +const char *api_utilities_name_version(lua_State *L) +{ + LUASCRIPT_CHECK_STATE(L, 0); + + return freeciv_name_version(); +} + +/********************************************************************//** + Comparable freeciv version +************************************************************************/ +const char *api_utilities_comparable_version(lua_State *L) +{ + LUASCRIPT_CHECK_STATE(L, 0); + + return fc_comparable_version(); +} + +/********************************************************************//** + Version string with no name +************************************************************************/ +const char *api_utilities_version_string(lua_State *L) +{ + LUASCRIPT_CHECK_STATE(L, 0); + + return freeciv_datafile_version(); +} + /********************************************************************//** One log message. This module is used by script_game and script_auth. ************************************************************************/ diff --git a/common/scriptcore/api_common_utilities.h b/common/scriptcore/api_common_utilities.h index a59882feed..f5e2342a41 100644 --- a/common/scriptcore/api_common_utilities.h +++ b/common/scriptcore/api_common_utilities.h @@ -34,6 +34,9 @@ int api_utilities_direction_id(lua_State *L, Direction dir); const char *api_utilities_dir2str(lua_State *L, Direction dir); const char *api_utilities_fc_version(lua_State *L); +const char *api_utilities_name_version(lua_State *L); +const char *api_utilities_comparable_version(lua_State *L); +const char *api_utilities_version_string(lua_State *L); void api_utilities_log_base(lua_State *L, int level, const char *message); diff --git a/common/scriptcore/tolua_common_a.pkg b/common/scriptcore/tolua_common_a.pkg index cc6860b982..513ad66d4a 100644 --- a/common/scriptcore/tolua_common_a.pkg +++ b/common/scriptcore/tolua_common_a.pkg @@ -121,6 +121,13 @@ int api_utilities_random const char *api_utilities_fc_version @ fc_version (lua_State *L); +const char *api_utilities_name_version + @ name_version (lua_State *L); +const char *api_utilities_comparable_version + @ comparable_version (lua_State *L); +const char *api_utilities_version_string + @ version_string (lua_State *L); + $[ -- *************************************************************************** -- Dump the state of user scalar variables to a Lua code string. -- 2.42.0