The Battle for Wesnoth  1.15.2+dev
wesnoth_lua_config.h
Go to the documentation of this file.
1 #ifndef WESNOTH_LUA_CONFIG_H_INCLUDED
2 #define WESNOTH_LUA_CONFIG_H_INCLUDED
3 
4 /*
5  Copyright (C) 2016 Gregory A Lundberg
6  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY.
14 
15  See the COPYING file for more details.
16 */
17 
18 /*
19 ** Wesnoth Lua Configuration
20 **
21 ** If at all possible, Wesnoth should use the stock, unmodified Lua source
22 ** kit.
23 **
24 ** This file contains the cross-platform compile-time changes. Platform
25 ** maintainers should consult wesnoth_lua_config.md for guidance on building
26 ** Lua for Wesnoth on their platform using their toolset.
27 **
28 ** Lua comes with a number of configuration options, such as backward
29 ** compatibility with earlier versions. In the original source kit, the
30 ** intention is these be set as compile-time options. For Wesnoth, place
31 ** them here to better ensure consistency.
32 **
33 ** In addition, there are specific non-standard changes which Wesnoth
34 ** requires. Those changes, if at all possible, should appear here. This
35 ** will reduce (hopefully, actually eliminate) any changes to the Lua
36 ** source kit. If that is not possible, be sure to describe the changes
37 ** needed, including a brief rationale and commit hashes, in
38 ** wesnoth_lua_config.md
39 */
40 
41 
42 
43 /*
44 ** Standard Lua options.
45 */
46 
47 /* Wesnoth definitions for compatibility
48  * No longer needed in C++, included only for Lua runtime.
49  */
50 #define LUA_COMPAT_5_2
51 #define LUA_COMPAT_5_1
52 #define LUA_COMPAT_FLOATSTRING
53 
54 
55 
56 /*
57 ** Wesnoth-specific modifications.
58 */
59 
60 /* We canNOT use strcoll on Windows!
61  *
62  * All strings in Wesnoth are UTF-8 encoded. On Windows, strcoll assumes
63  * strings are UTF-16LE encoded; using strcoll will cause the strings to
64  * collate in a different order than on all other targets. This can cause
65  * OOS errors during networked multi-player games.
66  */
67 
68 #include <string.h>
69 #define strcoll(a,b) strcmp(a,b)
70 
71 /* We need to rethrow exceptions.
72  *
73  * The stock Lua catch(...) consumes the exception. We need to re-throw
74  * it so. This allows the inner function (in C++ -> Lua -> C++) to pass
75  * back information about the exception, instead of reclassifying all
76  * exceptions to a single Lua status code.
77  */
78 
79 #include <cassert>
80 #include <exception>
81 
83 
84 #define LUAI_THROW(L,c) throw(c)
85 
86 #define LUAI_TRY(L,c,a) \
87  try { \
88  try { \
89  a \
90  } catch(const lua_jailbreak_exception &e) { \
91  e.store(); \
92  throw; \
93  } catch(const std::exception &e) { \
94  lua_pushstring(L, e.what()); \
95  luaG_errormsg(L); \
96  throw; \
97  } catch (const lua_longjmp *) { \
98  /*this exception is used internaly by lua exceptions*/ \
99  throw; \
100  } catch(...) { \
101  assert(false && "Lua is swallowing an un-named exception... this indicates a programmer error, please derive all exceptions from either std::exception, or lua_jailbreak_exception (and not with multiple inheritance pathways to either or this exception handler will not work!)"); \
102  throw; \
103  } \
104  } catch(...) { \
105  if((c)->status == 0) \
106  (c)->status = -1;\
107  }
108 
109 #define luai_jmpbuf int /* dummy variable */
110 
111 #endif