The Battle for Wesnoth  1.19.0-dev
wesnoth_lua_config.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
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 ** Wesnoth must use the stock, unmodified Lua source kit, to remain compatible
23 ** with using system copies of Lua. Please avoid making incompatible changes
24 ** here.
25 */
26 
27 
28 
29 /*
30 ** Wesnoth-specific modifications.
31 */
32 
33 /* We canNOT use strcoll on Windows!
34  *
35  * All strings in Wesnoth are UTF-8 encoded. On Windows, strcoll assumes
36  * strings are UTF-16LE encoded; using strcoll will cause the strings to
37  * collate in a different order than on all other targets. This can cause
38  * OOS errors during networked multi-player games.
39  */
40 
41 #include <string.h>
42 #define strcoll(a,b) strcmp(a,b)
43 
44 /* Push std::exception::what() strings onto the Lua stack for use by
45  * luaW_pcall().
46  *
47  * LUAI_THROW() and LUAI_TRY() are internal Lua macros that may not always
48  * exist and can't be defined for system copies of Lua, so don't rely on them
49  * for anything more important.
50  */
51 
52 #include <cassert>
53 #include <exception>
54 
56 
57 #define LUAI_THROW(L,c) throw(c)
58 
59 #define LUAI_TRY(L,c,a) \
60  try { \
61  try { \
62  a \
63  } catch(const lua_jailbreak_exception &) { \
64  throw; \
65  } catch(const std::exception &e) { \
66  lua_pushstring(L, e.what()); \
67  luaG_errormsg(L); \
68  throw; \
69  } catch (const lua_longjmp *) { \
70  /*this exception is used internaly by lua exceptions*/ \
71  throw; \
72  } catch(...) { \
73  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!)"); \
74  throw; \
75  } \
76  } catch(...) { \
77  if((c)->status == 0) \
78  (c)->status = -1;\
79  }
80 
81 #define luai_jmpbuf int /* dummy variable */
82 
83 #endif