Skip to content

Commit

Permalink
Move local changes to proper place
Browse files Browse the repository at this point in the history
luaconf.h provides a place for us to make changes, avoiding the need to change the original definitions. Move everything down there. This encompases the following changes:

1) Disable compatibility with old versions of Lua in the C++. Compatability is maintained only for the Lua runtime. Only one correction was needed: in application_lua_kernel.cpp

2) Change how the backpointer is defined, for forward compatability with Lua 5.3. This effected only one line: in lua_kernel_base.cpp. Using the Lua 5.3 macro caused a GCC warning, suppressed it for that line.

3) Certain Windows-only features are no longer available in the Lua runtime. These features are all in the Lua io module, which we don't allow access to, so this is a non-change for the runtime.

4) Lua will behave as if it is a standard C environment. This, again, mainly effects the Windows environment and features we don't allow access to in the runtime.
  • Loading branch information
GregoryLundberg committed Oct 17, 2016
1 parent f00357d commit 8e7b28c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
60 changes: 28 additions & 32 deletions src/lua/luaconf.h
Expand Up @@ -10,13 +10,6 @@
#include <limits.h>
#include <stddef.h>

/*
* Wesnoth definitions for compatibility
*/
#define LUA_COMPAT_MODULE

// todo: remove after 1.11.2
#define LUA_COMPAT_ALL

/*
** ==================================================================
Expand All @@ -30,6 +23,9 @@
** CHANGE it (define it) if you want Lua to avoid the use of any
** non-ansi feature or library.
*/
#if !defined(LUA_ANSI) && defined(__STRICT_ANSI__)
#define LUA_ANSI
#endif


#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE)
Expand Down Expand Up @@ -214,14 +210,7 @@
*/
#if defined(LUA_LIB) || defined(lua_c)
#include <stdio.h>
inline void fwrite_wrapper(const void * ptr, size_t size, size_t count, FILE * stream ) {
size_t i = fwrite(ptr, size, count, stream);
if (i != count * size) {
puts("error in fwrite by lua, unexpected amount of bytes written");
}
}

#define luai_writestring(s,l) fwrite_wrapper((s), sizeof(char), (l), stdout)
#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
#endif

Expand Down Expand Up @@ -510,9 +499,7 @@ inline void fwrite_wrapper(const void * ptr, size_t size, size_t count, FILE * s
/* Microsoft compiler on a Pentium (32 bit) ? */
#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */

/* We currently don't use direct3d so we can use LUA_IEEE754TRICK on windows too. */
#define LUA_IEEE754TRICK
#define LUA_IEEELL
#define LUA_MSASMTRICK
#define LUA_IEEEENDIAN 0
#define LUA_NANTRICK

Expand All @@ -530,33 +517,21 @@ inline void fwrite_wrapper(const void * ptr, size_t size, size_t count, FILE * s

#define LUA_IEEE754TRICK
#define LUA_IEEEENDIAN 0
#define LUA_IEEELL

#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */

#define LUA_IEEE754TRICK
#define LUA_IEEEENDIAN 1
#define LUA_IEEELL

#else /* }{ */

/* assume IEEE754 and a 32-bit integer type */
#define LUA_IEEE754TRICK
#define LUA_IEEELL

#endif /* } */

#endif /* } */

#if defined(__STDC_IEC_559__) && !defined(LUA_IEEE754TRICK)
#define LUA_IEEE754TRICK
#define LUA_IEEELL
#endif

#ifndef LUA_IEEE754TRICK
/* We need a same floating point calculations on all clients to prevent OOS */
#error IEEE754 Support is required to play build wesnoth
#endif
/* }================================================================== */


Expand All @@ -569,8 +544,29 @@ inline void fwrite_wrapper(const void * ptr, size_t size, size_t count, FILE * s
** without modifying the main part of the file.
*/

#define LUA_KERNEL_BASE_OFFSET sizeof(void*)
#define LUAI_EXTRASPACE LUA_KERNEL_BASE_OFFSET
/* Lua 5.3 forward compatability for backpointer */
#define LUAI_EXTRASPACE (sizeof(void*))
#define lua_getextraspace(L) ((void *)((char *)(L) - LUAI_EXTRASPACE))

/* LUA_ANSI may be defined so these check were skipped. */
/* Microsoft compiler on a Pentium (32 bit) ? */
#if defined(_WIN32) && !defined(_WIN32_WCE) && defined(_MSC_VER) && defined(_M_IX86) /* { */
#undef LUA_MSASMTRICK
#define LUA_IEEEENDIAN 0
#define LUA_NANTRICK
/* pentium 32 bits? */
#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */
#define LUA_IEEEENDIAN 0
#define LUA_NANTRICK
/* pentium 64 bits? */
#elif defined(__x86_64) /* }{ */
#define LUA_IEEEENDIAN 0
#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
#define LUA_IEEEENDIAN 1
#endif /* } */
#define LUA_IEEE754TRICK
#define LUA_IEEELL


#endif

2 changes: 1 addition & 1 deletion src/scripting/application_lua_kernel.cpp
Expand Up @@ -155,7 +155,7 @@ static lua_State * get_new_thread(lua_State * L)
lua_newtable(L);
} // stack is now [script key] [table]

lua_pushinteger(L, lua_objlen(L, -1) + 1); // push #table + 1 onto the stack
lua_pushinteger(L, lua_rawlen(L, -1) + 1); // push #table + 1 onto the stack

lua_State * T = lua_newthread(L); // create new thread T
// stack is now [script key] [table] [#table + 1] [thread]
Expand Down
5 changes: 4 additions & 1 deletion src/scripting/lua_kernel_base.cpp
Expand Up @@ -722,7 +722,10 @@ std::vector<std::string> lua_kernel_base::get_attribute_names(const std::string

lua_kernel_base*& lua_kernel_base::get_lua_kernel_base_ptr(lua_State *L)
{
return *reinterpret_cast<lua_kernel_base**>(reinterpret_cast<char*>(L) - LUA_KERNEL_BASE_OFFSET);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
return *reinterpret_cast<lua_kernel_base**>(lua_getextraspace(L));
#pragma GCC diagnostic pop
}

uint32_t lua_kernel_base::get_random_seed()
Expand Down
10 changes: 10 additions & 0 deletions src/wesnoth_lua_config.h
Expand Up @@ -38,10 +38,20 @@
** wesnoth_lua_config.md
*/



/*
** Standard Lua options.
*/

/* Wesnoth definitions for compatibility
* No longer needed in C++, included only for Lua runtime.
*/
#define LUA_COMPAT_MODULE
#define LUA_COMPAT_ALL



/*
** Wesnoth-specific modifications.
*/
Expand Down

0 comments on commit 8e7b28c

Please sign in to comment.