fix #3396 lua_function= doesn't work in [effect][filter]
unfortunately this adds an annoying const_cast. The old code 'worked around'
this by getting a nonconst reference to the same unit via the unit map,
which i think is not better just hides the issue.
(cherry-picked from commit 08b7d1b1ac
)
This commit is contained in:
parent
c48735c0fb
commit
21e6b399e8
1 changed files with 10 additions and 6 deletions
|
@ -4763,12 +4763,16 @@ bool game_lua_kernel::run_filter(char const *name, const map_location& l)
|
|||
bool game_lua_kernel::run_filter(char const *name, const unit& u)
|
||||
{
|
||||
lua_State *L = mState;
|
||||
unit_map::const_unit_iterator ui = units().find(u.get_location());
|
||||
if (!ui.valid()) return false;
|
||||
// Pass the unit as argument.
|
||||
luaW_pushunit(L, ui->underlying_id());
|
||||
|
||||
return run_filter(name, 1);
|
||||
lua_unit* lu = luaW_pushlocalunit(L, const_cast<unit&>(u));
|
||||
// stack: unit
|
||||
// put the unit to the stack twice to prevent gc.
|
||||
lua_pushvalue(L, -1);
|
||||
// stack: unit, unit
|
||||
bool res = run_filter(name, 1);
|
||||
// stack: unit
|
||||
lu->clear_ref();
|
||||
lua_pop(L, 1);
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* Runs a script from a filter.
|
||||
|
|
Loading…
Add table
Reference in a new issue