From f7cb2ae5557c161dd97f49aafbb647a93247f03a Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Mon, 8 Feb 2021 12:50:29 +0100 Subject: [PATCH 1/2] Lua API: add find.action() Make it possible to get an action from the find module. See osdn #41519 --- common/scriptcore/api_game_find.c | 21 +++++++++++++++++++++ common/scriptcore/api_game_find.h | 3 +++ common/scriptcore/tolua_game.pkg | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/common/scriptcore/api_game_find.c b/common/scriptcore/api_game_find.c index a19bce91df..39104867b5 100644 --- a/common/scriptcore/api_game_find.c +++ b/common/scriptcore/api_game_find.c @@ -294,6 +294,27 @@ const Direction *api_find_direction(lua_State *L, int id) return luascript_dir((enum direction8) id); } +/**********************************************************************//** + Returns the action with the specified id. +**************************************************************************/ +Action *api_find_action_type_by_id(lua_State *L, int id) +{ + LUASCRIPT_CHECK_STATE(L, NULL); + + return action_by_number(id); +} + +/**********************************************************************//** + Returns the action with the specified name. +**************************************************************************/ +Action *api_find_action_type_by_name(lua_State *L, const char *name) +{ + LUASCRIPT_CHECK_STATE(L, NULL); + LUASCRIPT_CHECK_ARG_NIL(L, name, 2, string, NULL); + + return action_by_rule_name(name); +} + /*************************************************************************//** Return a dummy pointer. *****************************************************************************/ diff --git a/common/scriptcore/api_game_find.h b/common/scriptcore/api_game_find.h index 99b213546d..3080846fbe 100644 --- a/common/scriptcore/api_game_find.h +++ b/common/scriptcore/api_game_find.h @@ -58,6 +58,9 @@ Terrain *api_find_terrain_by_name(lua_State *L, const char *name_orig); const Direction *api_find_direction (lua_State *L, int id); +Action *api_find_action_type_by_id(lua_State *L, int id); +Action *api_find_action_type_by_name(lua_State *L, const char *name); + Nonexistent *api_find_nonexistent(lua_State *L); #ifdef __cplusplus diff --git a/common/scriptcore/tolua_game.pkg b/common/scriptcore/tolua_game.pkg index 5cdedd79b7..28e2b6b5ab 100644 --- a/common/scriptcore/tolua_game.pkg +++ b/common/scriptcore/tolua_game.pkg @@ -509,6 +509,10 @@ module find { @ direction (lua_State *L, const char *str); Direction *api_find_direction @ direction (lua_State *L, int id); + Action *api_find_action_type_by_name + @ action (lua_State *L, const char *name); + Action *api_find_action_type_by_id + @ action (lua_State *L, int id); Nonexistent *api_find_nonexistent @ nonexistent (lua_State *L); } -- 2.20.1