Fix returning invalid unit types (bug #25041)
This commit is contained in:
parent
b7455d3bd4
commit
91bd6ab6d0
2 changed files with 9 additions and 6 deletions
|
@ -110,8 +110,11 @@ static int impl_unit_type_lookup(lua_State* L)
|
|||
} else {
|
||||
ut = unit_types.find(id);
|
||||
}
|
||||
luaW_pushunittype(L, ut);
|
||||
return 1;
|
||||
if(ut) {
|
||||
luaW_pushunittype(L, *ut);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int impl_unit_type_new(lua_State* L)
|
||||
|
@ -143,7 +146,7 @@ static int impl_unit_type_next(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
lua_pushlstring(L, it->first.c_str(), it->first.size());
|
||||
luaW_pushunittype(L, &it->second);
|
||||
luaW_pushunittype(L, it->second);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -190,9 +193,9 @@ namespace lua_unit_type {
|
|||
}
|
||||
}
|
||||
|
||||
void luaW_pushunittype(lua_State *L, const unit_type* ut)
|
||||
void luaW_pushunittype(lua_State *L, const unit_type& ut)
|
||||
{
|
||||
*static_cast<const unit_type**>(lua_newuserdata(L, sizeof(unit_type*))) = ut;
|
||||
*static_cast<const unit_type**>(lua_newuserdata(L, sizeof(unit_type*))) = &ut;
|
||||
luaL_setmetatable(L, UnitType);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace lua_unit_type {
|
|||
|
||||
/// Create a lua object containing a reference to a unittype, and a
|
||||
/// metatable to access the properties.
|
||||
void luaW_pushunittype(lua_State *, const unit_type*);
|
||||
void luaW_pushunittype(lua_State *, const unit_type&);
|
||||
|
||||
/// Test if a stack element is a unit type, and return it if so
|
||||
const unit_type* luaW_tounittype(lua_State*, int);
|
||||
|
|
Loading…
Add table
Reference in a new issue