<p></p>
<p><b>@joto</b> requested changes on this pull request.</p>
<p>This looks better now. I added some small nit-pick comments. I'd probably put this function into the <code>lua-utils.cpp</code> file and not made it a member of <code>output_flex_t</code>, because it isn't really related to it, it is just a Lua helper function.</p><hr>
<p>In <a href="https://github.com/openstreetmap/osm2pgsql/pull/1142#discussion_r418451363">src/output-flex.cpp</a>:</p>
<pre style='color:#555'>> + }
+ else {
+ msg = lua_pushfstring(lua_state, "(error object is a %s value)",
+ luaL_typename(lua_state, 1));
+ }
+ }
+ luaL_traceback(lua_state, lua_state, msg, 1); // append a standard traceback
+ return 1; // return the traceback
+}
+
+int output_flex_t::do_pcall(int narg, int nres)
+{
+ int const base = lua_gettop(lua_state()) - narg; // function index
+ lua_pushcfunction(lua_state(), msghandler); // push message handler
+ lua_insert(lua_state(), base); // put it under function and args
+ int status = lua_pcall(lua_state(), narg, nres, base);
</pre>
<p>Can be <code>const</code></p>
<hr>
<p>In <a href="https://github.com/openstreetmap/osm2pgsql/pull/1142#discussion_r418451533">src/output-flex.cpp</a>:</p>
<pre style='color:#555'>> @@ -983,6 +983,35 @@ void output_flex_t::add_row(table_connection_t *table_connection,
}
}
+static int msghandler(lua_State *lua_state)
+{
+ assert(lua_state);
+
+ char const *msg = lua_tostring(lua_state, 1);
+ if (msg == nullptr) { // is error object not a string?
+ if (luaL_callmeta(lua_state, 1, "__tostring") && // does it have a metamethod
+ lua_type(lua_state, -1) == LUA_TSTRING) { // that produces a string?
+ return 1; // that is the message
+ }
+ else {
</pre>
<p>Formatting looks unusual. Did you run <code>clang-format</code>?</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/osm2pgsql/pull/1142#discussion_r418452814">src/output-flex.cpp</a>:</p>
<pre style='color:#555'>> @@ -983,6 +983,35 @@ void output_flex_t::add_row(table_connection_t *table_connection,
}
}
+static int msghandler(lua_State *lua_state)
</pre>
<p>Maybe a bit more descriptive function name?</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/osm2pgsql/pull/1142#pullrequestreview-404056955">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AA6353TWR5SHA4RLE5OZB3TRPJ6LPANCNFSM4MTB2SEA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AA6353SYAFEYIYYOXNFAP4DRPJ6LPA5CNFSM4MTB2SEKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGODAKWW6Y.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/osm2pgsql/pull/1142#pullrequestreview-404056955",
"url": "https://github.com/openstreetmap/osm2pgsql/pull/1142#pullrequestreview-404056955",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>