When creating units in Lua from a vconfig, don't parse any contained [filter_recall] or [event]

This commit is contained in:
Celtic Minstrel 2016-08-23 12:21:19 -04:00
parent 09854e99ad
commit 1e575480a4
3 changed files with 27 additions and 8 deletions

View file

@ -2513,7 +2513,8 @@ int game_lua_kernel::intf_put_unit(lua_State *L)
}
else if (!lua_isnoneornil(L, unit_arg))
{
config cfg = luaW_checkconfig(L, unit_arg);
vconfig* vcfg = nullptr;
config cfg = luaW_checkconfig(L, unit_arg, vcfg);
if (unit_arg == 1 && !map().on_board(loc)) {
loc.x = cfg["x"] - 1;
loc.y = cfg["y"] - 1;
@ -2522,7 +2523,7 @@ int game_lua_kernel::intf_put_unit(lua_State *L)
} else if (unit_arg != 1) {
WRN_LUA << "wesnoth.put_unit(x, y, unit) is deprecated. Use wesnoth.put_unit(unit, x, y) instead\n";
}
u = unit_ptr (new unit(cfg, true));
u = unit_ptr (new unit(cfg, true, vcfg));
}
if (game_display_) {
@ -2623,8 +2624,9 @@ int game_lua_kernel::intf_put_recall_unit(lua_State *L)
}
else
{
config cfg = luaW_checkconfig(L, 1);
u = unit_ptr(new unit(cfg, true));
vconfig* vcfg = nullptr;
config cfg = luaW_checkconfig(L, 1, vcfg);
u = unit_ptr(new unit(cfg, true, vcfg));
}
if (!side) side = u->side();
@ -2691,8 +2693,9 @@ int game_lua_kernel::intf_find_vacant_tile(lua_State *L)
if (luaW_hasmetatable(L, 2, getunitKey)) {
u = static_cast<lua_unit *>(lua_touserdata(L, 2))->get_shared();
} else {
config cfg = luaW_checkconfig(L, 2);
u.reset(new unit(cfg, false));
vconfig* vcfg = nullptr;
config cfg = luaW_checkconfig(L, 2, vcfg);
u.reset(new unit(cfg, false, vcfg));
}
}
@ -2733,8 +2736,9 @@ int game_lua_kernel::intf_float_label(lua_State *L)
*/
static int intf_create_unit(lua_State *L)
{
config cfg = luaW_checkconfig(L, 1);
unit_ptr u = unit_ptr(new unit(cfg, true));
vconfig* vcfg = nullptr;
config cfg = luaW_checkconfig(L, 1, vcfg);
unit_ptr u = unit_ptr(new unit(cfg, true, vcfg));
new(lua_newuserdata(L, sizeof(lua_unit))) lua_unit(u);
lua_pushlightuserdata(L
, getunitKey);

View file

@ -755,6 +755,15 @@ config luaW_checkconfig(lua_State *L, int index)
return result;
}
config luaW_checkconfig(lua_State *L, int index, vconfig* vcfg)
{
config result = luaW_checkconfig(L, index);
if(void* p = luaL_testudata(L, index, vconfigKey)) {
vcfg = static_cast<vconfig*>(p);
}
return result;
}
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
{
switch (lua_type(L, index))

View file

@ -135,6 +135,12 @@ bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg);
*/
vconfig luaW_checkvconfig(lua_State *L, int index, bool allow_missing = false);
/**
* Like the two-argument version, but if it was a vconfig, also
* returns a pointer to that vconfig.
*/
config luaW_checkconfig(lua_State *L, int index, vconfig* vcfg);
/**
* Pushes the value found by following the variadic names (char *), if the
* value is not nil.