1 # generate-lua-exceptions: generate error handling code for Lua bindings
2 my $copyright = <<'END';
3 Copyright (C) 2003,2004,2006,2007,2008,2011,2012 Olly Betts
4 Copyright (C) 2007 Lemur Consulting Ltd
5 Copyright (C) 2007 Richard Boulton
6 Copyright (C) 2011 Xiaona Han
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 my @allclasses = (@baseclasses, @classes);
28 open FD, ">except.i" or die $!;
30 $copyright =~ s/^/ */mg;
34 * \@brief Custom Lua exception handling.
36 /* Warning: This file is generated by $0
37 * - do not modify directly!
41 %ignore Xapian::Error::Error(const Error&);
42 %include "xapian/error.h"
46 void handle_exception(lua_State* L) {
51 for (reverse @allclasses) {
54 } catch (const Xapian::$class &e) {
55 SWIG_NewPointerObj(L, (void *)new $class(e), SWIGTYPE_p_Xapian__$class, 1);
60 } catch (const std::exception& e) {
61 lua_pushfstring(L, "std::exception: %s", e.what());
63 lua_pushstring(L, "Unknown exception");
69 /* Functions and methods which are marked as "nothrow": */
73 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
81 Xapian::handle_exception(L);