| 228 | } |
| 229 | |
| 230 | int luabb_error(Lua lua, SP sp, const char *fmt, ...) |
| 231 | { |
| 232 | char c[1]; |
| 233 | va_list args; |
| 234 | int len; |
| 235 | char *out = NULL; |
| 236 | va_start(args, fmt); |
| 237 | len = vsnprintf(c, 1, fmt, args); |
| 238 | va_end(args); |
| 239 | |
| 240 | if (len == 0) |
| 241 | out = sp ? strdup("") : ""; |
| 242 | else if (len < 0) |
| 243 | luaL_error(lua, "can't format string"); |
| 244 | else { |
| 245 | out = sp ? malloc(len + 2) : alloca(len + 2); |
| 246 | va_start(args, fmt); |
| 247 | vsnprintf(out, len+1, fmt, args); |
| 248 | out[len+1] = 0; |
| 249 | va_end(args); |
| 250 | } |
| 251 | |
| 252 | extern int gbl_allow_lua_print; |
| 253 | if (gbl_allow_lua_print) { |
| 254 | luaL_where(lua, 0); |
| 255 | lua_pop(lua, 1); |
| 256 | #if 0 |
| 257 | const char *src = lua_tostring(lua, -1); |
| 258 | if (sp && sp->spname) |
| 259 | fprintf(stderr, "ERROR in SP:%s Ver:%d %s:%s\n", |
| 260 | sp->spname, sp->spversion, out, src); |
| 261 | else |
| 262 | fprintf(stderr, "ERROR:%s %s]\n", src, out); |
| 263 | #endif |
| 264 | } |
| 265 | |
| 266 | if (sp) { |
| 267 | if(sp->rc == 0) |
| 268 | sp->rc = -1; |
| 269 | lua_pushnil(lua); |
| 270 | lua_pushnumber(lua, sp->rc); |
| 271 | if (sp->error) |
| 272 | free(sp->error); |
| 273 | sp->error = out; |
| 274 | return 1; /* Just returning error code. */ |
| 275 | } else { |
| 276 | lua_pushnumber(lua, -1); |
| 277 | return luaL_error(lua, out); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | int luabb_type_by_name_int(const char *name, dbtypes_enum min) |
| 282 | { |
no test coverage detected