Skip to content

Commit 24e52fe

Browse files
authored
Lua: Fix DisplayVariable (dkfans#4812)
1 parent 8b644d4 commit 24e52fe

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/lua_api.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,13 +858,18 @@ static int lua_Display_countdown(lua_State *L)
858858
static int lua_Display_variable(lua_State *L)
859859
{
860860
PlayerNumber player = luaL_checkPlayerSingle(L, 1);
861-
int variable = luaL_checkinteger(L,2);
862-
int target = luaL_checkinteger(L,3);
861+
int32_t varib_id, varib_type;
862+
luaL_checkVariable(L, 2, &varib_id, &varib_type);
863+
int target = luaL_optinteger(L,3,0);
864+
unsigned char target_type = luaL_optinteger(L,4,0);
863865

864866
game.script_variable_player = player;
865-
game.script_value_type = variable;
866-
game.script_value_id = target;
867+
game.script_value_type = varib_type;
868+
game.script_value_id = varib_id;
869+
game.script_variable_target = target;
870+
game.script_variable_target_type = target_type;
867871
game.flags_gui |= GGUI_Variable;
872+
868873
return 0;
869874
}
870875

src/lua_params.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,15 @@ long luaL_checkAnimationId(lua_State* L, int index)
544544
return 0;
545545
}
546546

547+
void luaL_checkVariable(lua_State* L, int index, int32_t* varib_id, int32_t* varib_type)
548+
{
549+
const char* variable = luaL_checkstring(L, index);
550+
if (!parse_get_varib(variable, varib_id, varib_type, 1))
551+
{
552+
luaL_argerror(L, index, lua_pushfstring(L, "Unknown variable, '%s'", variable));
553+
}
554+
}
555+
547556
/***************************************************************************************************/
548557
/************ Outputs *************************************************************************/
549558
/***************************************************************************************************/

src/lua_params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct Thing *luaL_checkCreature(lua_State *L, int index);
6565
struct Thing* luaL_checkObject(lua_State* L, int index);
6666
void luaL_checkCoord3d(lua_State *L, int index, struct Coord3d* pos);
6767
long luaL_checkAnimationId(lua_State* L, int index);
68+
void luaL_checkVariable(lua_State* L, int index, int32_t* varib_id, int32_t* varib_type);
6869

6970
/**** Outputs *******/
7071
void lua_pushThing(lua_State *L, struct Thing* thing);

0 commit comments

Comments
 (0)