lua: fix compatibility with 5.2 and 5.3

pull/110/head
Hleb Valoshka 2018-05-08 18:50:42 +03:00
parent c748b2f3f8
commit ee43f559a0
6 changed files with 22 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
end

View File

@ -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();

View File

@ -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);