In recent post I've posted part of my library, that deals with PostgreSQL data in binary format. Today, googling for some hints for implementing binary timestamps in double format I've found a reliable library, libpqtypes, which is doing exactly the same as mine (actually more), except it's purpose is PostgreSQL only.
Don't know if it's terrible news or not, as I could adapt my code while using this library and win a lot of time. This is one of the reasons why extensive googling is required before each project.
Showing posts with label opinion. Show all posts
Showing posts with label opinion. Show all posts
2009-05-21
2009-05-01
Lua error message format
I work on the library, which will use Lua. Thinking about the possibility to give a good error structure instead of plain message, I've found that lua_pcall has a nice feature to specify custom error handler function:
Using this there is a way to get a chunk name and it's error line number:
Why? Oh, why the Lua guys are putting assembled error message with chunk name and line number if I use my own error handler? IMHO, this is wrong. There is no other way to give a user nice message except parsing. Actually parsing of such message is easy, but.. the Lua guys have changed error message format a few times already. I'm pissed!
lua_pushcfunction(L, error_handler); luaL_loadfile(L, "file.lua"); lua_pcall(L, 0, 0, -2);
Using this there is a way to get a chunk name and it's error line number:
int error_handler(lua_State* L) {
lua_Debug d;
lua_getstack(L, 1, &d);
lua_getinfo(L, "Sln", &d);
string err = lua_tostring(L, -1);
lua_pop(L, 1);
stringstream msg;
msg << d.short_src << ":" << d.currentline;
if(d.name != 0) {
msg << "(" << d.namewhat << " " << d.name << ")";
}
msg << " > " << err;
lua_pushstring(L, msg.str().c_str());
return 1;
}
Work's like a charm, except one thing. This is the output from this error handler: [string "test"]:1 > [string "test"]:1: attempt to index global 'a' (a nil value)
Why? Oh, why the Lua guys are putting assembled error message with chunk name and line number if I use my own error handler? IMHO, this is wrong. There is no other way to give a user nice message except parsing. Actually parsing of such message is easy, but.. the Lua guys have changed error message format a few times already. I'm pissed!
Subscribe to:
Posts (Atom)