From ee43f559a07d94c740f7bdd566a6ad0f2a2320c4 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Tue, 8 May 2018 18:50:42 +0300 Subject: [PATCH] lua: fix compatibility with 5.2 and 5.3 --- celestia.pro | 8 ++++++-- scripts/randstar.celx | 2 +- scripts/tour-system.celx | 6 +++--- scripts/z-dist.celx | 4 ++-- src/celestia/celx.cpp | 7 +++++++ src/celestia/celx_observer.cpp | 3 +++ 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/celestia.pro b/celestia.pro index 2a7d1ced5..2007bc848 100644 --- a/celestia.pro +++ b/celestia.pro @@ -599,10 +599,14 @@ unix { CONFIG += link_pkgconfig - LUALIST = lua52 lua51 lua + LUALIST = lua53 lua52 lua51 lua for(libpc, LUALIST):system(pkg-config --exists $${libpc}):LUAPC = $${libpc} isEmpty (LUAPC) {error("No shared Lua library found!")} + equals(LUAPC, "lua53"): DEFINES += LUA_VER=0x050300 + equals(LUAPC, "lua52"): DEFINES += LUA_VER=0x050200 + equals(LUAPC, "lua51"): DEFINES += LUA_VER=0x050100 + PKGCONFIG += glu $$LUAPC libpng theora INCLUDEPATH += /usr/local/cspice/include LIBS += -ljpeg /usr/local/cspice/lib/cspice.a @@ -668,7 +672,7 @@ macx { LIBS += macosx/lib/cspice.a } -DEFINES += CELX LUA_VER=0x050200 +DEFINES += CELX # QMAKE_CXXFLAGS += -ffast-math diff --git a/scripts/randstar.celx b/scripts/randstar.celx index 62d883228..a459913bd 100644 --- a/scripts/randstar.celx +++ b/scripts/randstar.celx @@ -6,6 +6,6 @@ while 1 do index = math.floor(nstars * math.random()) star = celestia:getstar(index) celestia:select(star) - obs:goto(star, 10) + obs:gotoobject(star, 10) wait(10) end diff --git a/scripts/tour-system.celx b/scripts/tour-system.celx index c2f0d7d4c..0a8e40464 100644 --- a/scripts/tour-system.celx +++ b/scripts/tour-system.celx @@ -1,7 +1,7 @@ -function goto(o, t) +function gotoobject(o, t) local obs = celestia:getobserver() obs:follow(o) - obs:goto(o, t) + obs:gotoobject(o, t) while (obs:travelling()) do wait(0) end @@ -11,7 +11,7 @@ function visit(o) local i, v celestia:select(o) celestia:flash(o:type() .. " - " .. o:name()) - goto(o, 3) + gotoobject(o, 3) wait(0.5) local children = o:getchildren() for i, v in ipairs(children) do diff --git a/scripts/z-dist.celx b/scripts/z-dist.celx index f093f50b4..6f1ce168a 100644 --- a/scripts/z-dist.celx +++ b/scripts/z-dist.celx @@ -20,7 +20,7 @@ end function rgb2hex(r,g,b) -- Converts color code from RGB to Hex - local hex = string.format("#%.2x%.2x%.2x", r,g,b) + local hex = string.format("#%.2x%.2x%.2x", math.floor(r), math.floor(g), math.floor(b)) return hex end @@ -117,4 +117,4 @@ while true do celestia:print(sel:name()..": "..string.format("redshift z = %5.3f, distance = %5.2f Mpc", z,d).."\nmax. redshift: "..dsomax:name(),5,-1,-1,0,6) end wait(0) -end \ No newline at end of file +end diff --git a/src/celestia/celx.cpp b/src/celestia/celx.cpp index 06e19937c..042cfc60f 100755 --- a/src/celestia/celx.cpp +++ b/src/celestia/celx.cpp @@ -515,7 +515,11 @@ LuaState::LuaState() : ioMode(NoIO), eventHandlerEnabled(false) { +#if LUA_VER >= 0x050100 state = luaL_newstate(); +#else + state = lua_open(); +#endif timer = CreateTimer(); screenshotCount = 0; } @@ -3653,6 +3657,9 @@ bool LuaState::init(CelestiaCore* appCore) openLuaLibrary(state, LUA_MATHLIBNAME, luaopen_math); openLuaLibrary(state, LUA_TABLIBNAME, luaopen_table); openLuaLibrary(state, LUA_STRLIBNAME, luaopen_string); +#if LUA_VER >= 0x050200 + openLuaLibrary(state, LUA_COLIBNAME, luaopen_coroutine); +#endif // Make the package library, except the loadlib function, available // for celx regardless of script system access policy. allowLuaPackageAccess(); diff --git a/src/celestia/celx_observer.cpp b/src/celestia/celx_observer.cpp index 5253b4c63..143264598 100644 --- a/src/celestia/celx_observer.cpp +++ b/src/celestia/celx_observer.cpp @@ -899,7 +899,10 @@ void CreateObserverMetaTable(lua_State* l) celx.registerMethod("__tostring", observer_tostring); celx.registerMethod("isvalid", observer_isvalid); +#if LUA_VER < 0x050200 celx.registerMethod("goto", observer_goto); +#endif + celx.registerMethod("gotoobject", observer_goto); celx.registerMethod("gotolonglat", observer_gotolonglat); celx.registerMethod("gotolocation", observer_gotolocation); celx.registerMethod("gotodistance", observer_gotodistance);