Simplify and improve Lua-side add_attribute function
Silence missing cast warning