scriptindex: date=unix is now a no-op for empty input
[xapian.git] / xapian-bindings / lua / generate-lua-exceptions
blobf0abb7e8c9a4fe5b641578b7eabb7bfe2b34529e
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
21 END
23 use strict;
24 use exception_data;
26 my @allclasses = (@baseclasses, @classes);
28 open FD, ">except.i" or die $!;
30 $copyright =~ s/^/ */mg;
32 print FD <<"EOF";
33 /** \@file lua/except.i
34  * \@brief Custom Lua exception handling.
35  */
36 /* Warning: This file is generated by $0
37  * - do not modify directly!
38  *
39 $copyright */
41 %include "xapian/error.h"
44 namespace Xapian {
45 void handle_exception(lua_State* L) {
46     try {
47         throw;
48 EOF
50 for (reverse @allclasses) {
51     my ($class, $parent, $comment) = split /\t/, $_, 3;
52     print FD <<"EOF";
53     } catch (const Xapian::$class &e) {
54         SWIG_NewPointerObj(L, (void *)new $class(e), SWIGTYPE_p_Xapian__$class, 1);
55 EOF
58 print FD <<'EOF';
59     } catch (const std::exception& e) {
60         lua_pushfstring(L, "std::exception: %s", e.what());
61     } catch (...) {
62         lua_pushstring(L, "Unknown exception");
63     }
68 /* Functions and methods which are marked as "nothrow": */
69 EOF
71 chdir($INC[0]);
72 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
74 print FD <<'EOF';
76 %exception {
77     try {
78         $action
79     } catch (...) {
80         Xapian::handle_exception(L);
81         SWIG_fail;
82     }
84 EOF
86 close FD or die $!;