omegatest: Skip another testcase with 32-bit time_t
[xapian.git] / xapian-bindings / lua / generate-lua-exceptions
blob4c62feff31db31b4a316db45221e5c074c247fcf
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
34  * \@brief Custom Lua exception handling.
35  */
36 /* Warning: This file is generated by $0
37  * - do not modify directly!
38  *
39 $copyright */
41 %ignore Xapian::Error::Error(const Error&);
42 %include "xapian/error.h"
45 namespace Xapian {
46 void handle_exception(lua_State* L) {
47     try {
48         throw;
49 EOF
51 for (reverse @allclasses) {
52     my ($class) = @{$_};
53     print FD <<"EOF";
54     } catch (const Xapian::$class &e) {
55         SWIG_NewPointerObj(L, (void *)new $class(e), SWIGTYPE_p_Xapian__$class, 1);
56 EOF
59 print FD <<'EOF';
60     } catch (const std::exception& e) {
61         lua_pushfstring(L, "std::exception: %s", e.what());
62     } catch (...) {
63         lua_pushstring(L, "Unknown exception");
64     }
69 /* Functions and methods which are marked as "nothrow": */
70 EOF
72 chdir($INC[0]);
73 exception_data::for_each_nothrow(sub { print FD "%exception $_[0];\n" });
75 print FD <<'EOF';
77 %exception {
78     try {
79         $action
80     } catch (...) {
81         Xapian::handle_exception(L);
82         SWIG_fail;
83     }
85 EOF
87 close FD or die $!;