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