From 5c84507e221dbd4ac376862fc0cdc84efeece4d5 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Fri, 8 Aug 2014 04:04:14 +0300 Subject: [PATCH] Revert "Remove Lua 5.1 support" This reverts commit c87c5de4589fd5da5c873218d632a7309f28e7b5. --- include/library/lua-base.hpp | 6 ++++++ manual.lyx | 4 ++-- manual.txt | 4 ++-- src/library/lua.cpp | 5 +++++ src/lua/loadfile.cpp | 6 +++++- src/lua/lua.cpp | 10 ++++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/library/lua-base.hpp b/include/library/lua-base.hpp index 33f33687..7f309bed 100644 --- a/include/library/lua-base.hpp +++ b/include/library/lua-base.hpp @@ -429,8 +429,14 @@ public: void pushboolean(int b) { lua_pushboolean(lua_handle, b); } lua_Number tonumber(int index) { return lua_tonumber(lua_handle, index); } void gettable(int index) { lua_gettable(lua_handle, index); } +#if LUA_VERSION_NUM == 501 + int load(lua_Reader reader, void* data, const char* chunkname) { return lua_load(lua_handle, reader, data, + chunkname); } +#endif +#if LUA_VERSION_NUM == 502 int load(lua_Reader reader, void* data, const char* chunkname, const char* mode) { return lua_load(lua_handle, reader, data, chunkname, mode); } +#endif const char* tostring(int index) { return lua_tostring(lua_handle, index); } const char* tolstring(int index, size_t& len) { return lua_tolstring(lua_handle, index, &len); } void pushlstring(const char* s, size_t len) { lua_pushlstring(lua_handle, s, len); } diff --git a/manual.lyx b/manual.lyx index 21def0bf..067a721e 100644 --- a/manual.lyx +++ b/manual.lyx @@ -144,11 +144,11 @@ libao (libao sound only) \end_layout \begin_layout Enumerate -Lua version 5.2.X +Lua version 5.1.X or 5.2.X \end_layout \begin_layout Enumerate -G++ 4.7 or 4.8 +G++ 4.6 or 4.7 \end_layout \begin_layout Enumerate diff --git a/manual.txt b/manual.txt index 5dfc269b..a2c847fb 100644 --- a/manual.txt +++ b/manual.txt @@ -38,9 +38,9 @@ lsnes is SNES rerecording emulator based on bsnes core. 12. libao (libao sound only) -13. Lua version 5.2.X +13. Lua version 5.1.X or 5.2.X -14. G++ 4.7 or 4.8 +14. G++ 4.6 or 4.7 15. libopus (optional, for commentary track tool) diff --git a/src/library/lua.cpp b/src/library/lua.cpp index a7c2c062..b3c77aca 100644 --- a/src/library/lua.cpp +++ b/src/library/lua.cpp @@ -242,7 +242,12 @@ namespace void recursive_lookup_table(state& L, const std::string& tab) { if(tab == "") { +#if LUA_VERSION_NUM == 501 + L.pushvalue(LUA_GLOBALSINDEX); +#endif +#if LUA_VERSION_NUM == 502 L.rawgeti(LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS); +#endif assert(L.type(-1) == LUA_TTABLE); return; } diff --git a/src/lua/loadfile.cpp b/src/lua/loadfile.cpp index de9d1e49..ebae0357 100644 --- a/src/lua/loadfile.cpp +++ b/src/lua/loadfile.cpp @@ -267,7 +267,11 @@ namespace else chunkname = file1; reader rc(file, absfilename); - int r = lua_load(L.handle(), reader::rfn, &rc, chunkname.c_str(), "t"); + int r = lua_load(L.handle(), reader::rfn, &rc, chunkname.c_str() +#if LUA_VERSION_NUM == 502 + , "t" +#endif + ); delete &file; if(rc.get_err() != "") throw std::runtime_error(rc.get_err()); diff --git a/src/lua/lua.cpp b/src/lua/lua.cpp index 1cb5d4ee..f2aa3141 100644 --- a/src/lua/lua.cpp +++ b/src/lua/lua.cpp @@ -128,7 +128,12 @@ namespace void copy_system_tables(lua::state& L) { +#if LUA_VERSION_NUM == 501 + L.pushvalue(LUA_GLOBALSINDEX); +#endif +#if LUA_VERSION_NUM == 502 L.rawgeti(LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS); +#endif L.newtable(); L.pushnil(); while(L.next(-3)) { @@ -505,7 +510,12 @@ bool lua_state::run_lua_fragment() throw(std::bad_alloc) bool result = true; if(recursive_flag) return false; +#if LUA_VERSION_NUM == 501 + int t = L.load(read_lua_fragment, &luareader_fragment, "run_lua_fragment"); +#endif +#if LUA_VERSION_NUM == 502 int t = L.load(read_lua_fragment, &luareader_fragment, "run_lua_fragment", "t"); +#endif if(t == LUA_ERRSYNTAX) { messages << "Can't run Lua: Internal syntax error: " << L.tostring(-1) << std::endl; -- 2.11.4.GIT