@@ -716,19 +716,32 @@ static void push_location(lua_State *lua_state,
716716 lua_pushnumber (lua_state, location.lat ());
717717}
718718
719- int output_flex_t::app_get_bbox ()
719+ /* *
720+ * Helper function checking that Lua function "name" is called in the correct
721+ * context and without parameters.
722+ */
723+ void output_flex_t::check_context_and_state (char const *name,
724+ char const *context, bool condition)
720725{
721- if (m_calling_context != calling_context::process_node &&
722- m_calling_context != calling_context::process_way &&
723- m_calling_context != calling_context::process_relation) {
726+ if (condition) {
724727 throw std::runtime_error{
725- " The function get_bbox () can only be called from the "
726- " process_node/way/relation() functions. " };
728+ " The function {} () can only be called from the {}. " _format (
729+ name, context) };
727730 }
728731
729732 if (lua_gettop (lua_state ()) > 1 ) {
730- throw std::runtime_error{" No parameter(s) needed for get_box()." };
733+ throw std::runtime_error{
734+ " No parameter(s) needed for {}()." _format (name)};
731735 }
736+ }
737+
738+ int output_flex_t::app_get_bbox ()
739+ {
740+ check_context_and_state (
741+ " get_bbox" , " process_node/way/relation() functions" ,
742+ m_calling_context != calling_context::process_node &&
743+ m_calling_context != calling_context::process_way &&
744+ m_calling_context != calling_context::process_relation);
732745
733746 if (m_calling_context == calling_context::process_node) {
734747 push_location (lua_state (), m_context_node->location ());
0 commit comments