orbitersim / orbiter

Open-source repository of Orbiter Space Flight Simulator
MIT License
1.6k stars 216 forks source link

Upgrade Lua to version 5.4 and make constants really read-only #391

Open Urwumpe opened 10 months ago

Urwumpe commented 10 months ago

User Story

As script developer, I want to be sure that no other script can overwrite the variables which refer to OrbiterSDK constants and enums, so that its impossible to cause bugs in a different module.

Detailled description

Since version 5.4, Lua supports the keyword const to make variable definitions read-only. By that language feature, we could stop this possible error source. So, the version of Orbiters Lua binding should be raised to 5.4 (at least) and next, the constant definitions in Interpreter.cpp declared to be write protected.

Acceptance criteria

schnepe2 commented 9 months ago

Do you expect any compatibility issues with updating from Lua 5.1.2 to Lua 5.4++?

schnepe2 commented 9 months ago

Here are all the Language Incompatibilities (from 5.2 to 5.4)

  • The concept of environment changed. Only Lua functions have environments. To set the environment of a Lua function, use the variable _ENV or the function load. C functions no longer have environments. Use an upvalue with a shared table if you need to keep shared state among several C functions. (You may use luaL_setfuncs to open a C library with all functions sharing a common upvalue.) To manipulate the "environment" of a userdata (which is now called user value), use the new functions lua_getuservalue and lua_setuservalue.

  • Lua identifiers cannot use locale-dependent letters.

  • Doing a step or a full collection in the garbage collector does not restart the collector if it has been stopped.

  • Weak tables with weak keys now perform like ephemeron tables.

  • The event tail return in debug hooks was removed. Instead, tail calls generate a special new event, tail call, so that the debugger can know that there will not be a corresponding return event.

  • Equality between function values has changed. Now, a function definition may not create a new value; it may reuse some previous value if there is no observable difference to the new function.

  • The main difference between Lua 5.2 and Lua 5.3 is the introduction of an integer subtype for numbers. Although this change should not affect "normal" computations, some computations (mainly those that involve some kind of overflow) can give different results.

    You can fix these differences by forcing a number to be a float (in Lua 5.2 all numbers were float), in particular writing constants with an ending .0 or using x = x + 0.0 to convert a variable. (This recommendation is only for a quick fix for an occasional incompatibility; it is not a general guideline for good programming. For good programming, use floats where you need floats and integers where you need integers.)

  • The conversion of a float to a string now adds a .0 suffix to the result if it looks like an integer. (For instance, the float 2.0 will be printed as 2.0, not as 2.) You should always use an explicit format when you need a specific format for numbers.

    (Formally this is not an incompatibility, because Lua does not specify how numbers are formatted as strings, but some programs assumed a specific format.)

  • The generational mode for the garbage collector was removed. (It was an experimental feature in Lua 5.2.)

  • The coercion of strings to numbers in arithmetic and bitwise operations has been removed from the core language. The string library does a similar job for arithmetic (but not for bitwise) operations using the string metamethods. However, unlike in previous versions, the new implementation preserves the implicit type of the numeral in the string. For instance, the result of "1" + "2" now is an integer, not a float.

  • Literal decimal integer constants that overflow are read as floats, instead of wrapping around. You can use hexadecimal notation for such constants if you want the old behavior (reading them as integers with wrap around).

  • The use of the lt metamethod to emulate le has been removed. When needed, this metamethod must be explicitly defined.

  • The semantics of the numerical for loop over integers changed in some details. In particular, the control variable never wraps around.

  • A label for a goto cannot be declared where a label with the same name is visible, even if this other label is declared in an enclosing block.

  • When finalizing an object, Lua does not ignore __gc metamethods that are not functions. Any value will be called, if present. (Non-callable values will generate a warning, like any other error when calling a finalizer.)

Source: https://www.lua.org/manual/5.2/manual.html#8 https://www.lua.org/manual/5.3/manual.html#8 https://www.lua.org/manual/5.4/manual.html#8

Urwumpe commented 9 months ago

I don't think so, but I am no Lua expert. The changes to the C API could cause minor trouble, but I don't find any usages of that.

schnepe2 commented 9 months ago

Yeah, C-API changes and Library changes must be resolved "in the C++ domain" - if there are any, I don't expect them and I believe a re-compile with the new sources is enough.

What I am concerned about is the Lua-Scripts "out there". I expect some (few) to fail, but I can't estimate how many :wink:

schnepe2 commented 9 months ago

Update: I've just tried to build Orbiter with newer versions of Lua (5.4, 5.3, 5.2) and all fail due to some changes regarding 'coroutines' 😞 As I am totally unfamiliar with that - and I don't see anything mentioned about that in Lua's Version History - I think this has to be tackled by someone who knows what to do (@dimitry-ishenko ?)

Urwumpe commented 9 months ago

Can you post a error message? Maybe its trivial. I remember that coroutines are Luas way of multi-threading, but since than it gets hazy, I last worked with Lua ~15 years ago.

schnepe2 commented 9 months ago

Sure, let me try it again... Those were LINKER errors unfortunately 😢 (This is Lua V5.4.6 BTW)

(The linker warnings can be ignored for now I think. Either they are because of a wrong threading model /MD etc. or can be resolved otherwise)

It's these I'm worried about:

linit.c.obj : error LNK2001: unresolved external symbol luaopen_coroutine linit.c.obj : error LNK2001: unresolved external symbol luaopen_utf8 llex.c.obj : error LNK2001: unresolved external symbol luaictype lobject.c.obj : error LNK2001: unresolved external symbol luaictype lua.dll : fatal error LNK1120: 3 unresolved externals

>------ Build All started: Project: orbiter-git-schnepe2, Configuration: windows-x64-debug ------
  [1/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lapi.c.obj
  [2/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lbaselib.c.obj
  [3/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lauxlib.c.obj
  [4/46] Building C object Extern\CMakeFiles\lua.dir\Lua\ldblib.c.obj
  [5/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lcode.c.obj
  [6/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lfunc.c.obj
  [7/46] Building C object Extern\CMakeFiles\lua.dir\Lua\ldo.c.obj
  [8/46] Building C object Extern\CMakeFiles\lua.dir\Lua\ldump.c.obj
  [9/46] Building C object Extern\CMakeFiles\lua.dir\Lua\linit.c.obj
  [10/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lgc.c.obj
  [11/46] Building C object Extern\CMakeFiles\lua.dir\Lua\ldebug.c.obj
  [12/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lmathlib.c.obj
  [13/46] Building C object Extern\CMakeFiles\lua.dir\Lua\llex.c.obj
  [14/46] Building C object Extern\CMakeFiles\lua.dir\Lua\liolib.c.obj
  [15/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lobject.c.obj
  [16/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lopcodes.c.obj
  [17/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lparser.c.obj
  [18/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lstate.c.obj
  [19/46] Building C object Extern\CMakeFiles\lua.dir\Lua\loslib.c.obj
  [20/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lmem.c.obj
  [21/46] Building C object Extern\CMakeFiles\lua.dir\Lua\ltm.c.obj
  [22/46] Building C object Extern\CMakeFiles\lua.dir\Lua\ltable.c.obj
  [23/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lstring.c.obj
  [24/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lstrlib.c.obj
  [25/46] Building C object Extern\CMakeFiles\lua.dir\Lua\loadlib.c.obj
  [26/46] Building C object Extern\CMakeFiles\lua.dir\Lua\ltests.c.obj
  [27/46] Building C object Extern\CMakeFiles\lua.dir\Lua\ltablib.c.obj
  [28/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lvm.c.obj
  [29/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lzio.c.obj
  [30/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lundump.c.obj
  [31/46] Building C object Extern\CMakeFiles\lua.dir\Lua\lua.c.obj
  [32/46] Linking C shared library lua.dll
  FAILED: lua.dll lua.lib 
  cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_dll --intdir=Extern\CMakeFiles\lua.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo Extern\CMakeFiles\lua.dir\Lua\lapi.c.obj Extern\CMakeFiles\lua.dir\Lua\lauxlib.c.obj Extern\CMakeFiles\lua.dir\Lua\lbaselib.c.obj Extern\CMakeFiles\lua.dir\Lua\lcode.c.obj Extern\CMakeFiles\lua.dir\Lua\ldblib.c.obj Extern\CMakeFiles\lua.dir\Lua\ldebug.c.obj Extern\CMakeFiles\lua.dir\Lua\ldo.c.obj Extern\CMakeFiles\lua.dir\Lua\ldump.c.obj Extern\CMakeFiles\lua.dir\Lua\lfunc.c.obj Extern\CMakeFiles\lua.dir\Lua\lgc.c.obj Extern\CMakeFiles\lua.dir\Lua\linit.c.obj Extern\CMakeFiles\lua.dir\Lua\liolib.c.obj Extern\CMakeFiles\lua.dir\Lua\llex.c.obj Extern\CMakeFiles\lua.dir\Lua\lmathlib.c.obj Extern\CMakeFiles\lua.dir\Lua\lmem.c.obj Extern\CMakeFiles\lua.dir\Lua\loadlib.c.obj Extern\CMakeFiles\lua.dir\Lua\lobject.c.obj Extern\CMakeFiles\lua.dir\Lua\lopcodes.c.obj Extern\CMakeFiles\lua.dir\Lua\loslib.c.obj Extern\CMakeFiles\lua.dir\Lua\lparser.c.obj Extern\CMakeFiles\lua.dir\Lua\lstate.c.obj Extern\CMakeFiles\lua.dir\Lua\lstring.c.obj Extern\CMakeFiles\lua.dir\Lua\lstrlib.c.obj Extern\CMakeFiles\lua.dir\Lua\ltable.c.obj Extern\CMakeFiles\lua.dir\Lua\ltablib.c.obj Extern\CMakeFiles\lua.dir\Lua\ltests.c.obj Extern\CMakeFiles\lua.dir\Lua\ltm.c.obj Extern\CMakeFiles\lua.dir\Lua\lua.c.obj Extern\CMakeFiles\lua.dir\Lua\lundump.c.obj Extern\CMakeFiles\lua.dir\Lua\lvm.c.obj Extern\CMakeFiles\lua.dir\Lua\lzio.c.obj  /out:lua.dll /implib:lua.lib /pdb:lua.pdb /dll /version:0.0 /machine:x64 /debug /INCREMENTAL  /NODEFAULTLIB:\"LIBCMTD\"  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
  LINK Pass 1: command "C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo Extern\CMakeFiles\lua.dir\Lua\lapi.c.obj Extern\CMakeFiles\lua.dir\Lua\lauxlib.c.obj Extern\CMakeFiles\lua.dir\Lua\lbaselib.c.obj Extern\CMakeFiles\lua.dir\Lua\lcode.c.obj Extern\CMakeFiles\lua.dir\Lua\ldblib.c.obj Extern\CMakeFiles\lua.dir\Lua\ldebug.c.obj Extern\CMakeFiles\lua.dir\Lua\ldo.c.obj Extern\CMakeFiles\lua.dir\Lua\ldump.c.obj Extern\CMakeFiles\lua.dir\Lua\lfunc.c.obj Extern\CMakeFiles\lua.dir\Lua\lgc.c.obj Extern\CMakeFiles\lua.dir\Lua\linit.c.obj Extern\CMakeFiles\lua.dir\Lua\liolib.c.obj Extern\CMakeFiles\lua.dir\Lua\llex.c.obj Extern\CMakeFiles\lua.dir\Lua\lmathlib.c.obj Extern\CMakeFiles\lua.dir\Lua\lmem.c.obj Extern\CMakeFiles\lua.dir\Lua\loadlib.c.obj Extern\CMakeFiles\lua.dir\Lua\lobject.c.obj Extern\CMakeFiles\lua.dir\Lua\lopcodes.c.obj Extern\CMakeFiles\lua.dir\Lua\loslib.c.obj Extern\CMakeFiles\lua.dir\Lua\lparser.c.obj Extern\CMakeFiles\lua.dir\Lua\lstate.c.obj Extern\CMakeFiles\lua.dir\Lua\lstring.c.obj Extern\CMakeFiles\lua.dir\Lua\lstrlib.c.obj Extern\CMakeFiles\lua.dir\Lua\ltable.c.obj Extern\CMakeFiles\lua.dir\Lua\ltablib.c.obj Extern\CMakeFiles\lua.dir\Lua\ltests.c.obj Extern\CMakeFiles\lua.dir\Lua\ltm.c.obj Extern\CMakeFiles\lua.dir\Lua\lua.c.obj Extern\CMakeFiles\lua.dir\Lua\lundump.c.obj Extern\CMakeFiles\lua.dir\Lua\lvm.c.obj Extern\CMakeFiles\lua.dir\Lua\lzio.c.obj /out:lua.dll /implib:lua.lib /pdb:lua.pdb /dll /version:0.0 /machine:x64 /debug /INCREMENTAL /NODEFAULTLIB:"LIBCMTD" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:Extern\CMakeFiles\lua.dir/intermediate.manifest Extern\CMakeFiles\lua.dir/manifest.res" failed (exit code 1120) with the following output:
     Creating library lua.lib and object lua.exp
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_close' defined in 'lstate.c.obj' is imported by 'lua.c.obj' in function 'main'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_gettop' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'docall'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_settop' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'report'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_rotate' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'docall'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_type' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'msghandler'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_typename' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'msghandler'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_tointegerx' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'pmain'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_toboolean' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'main'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_tolstring' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'report'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_touserdata' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'pmain'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_pushinteger' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'main'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_pushlstring' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'pushline'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_pushstring' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'createargtable'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_pushfstring' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'msghandler'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_pushcclosure' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'docall'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_pushboolean' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'pmain'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_pushlightuserdata' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'main'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_getglobal' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'dolibrary'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_rawgeti' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'pushargs'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_createtable' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'createargtable'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_setglobal' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'createargtable'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_setfield' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'pmain'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_rawseti' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'createargtable'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_pcallk' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'docall'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_warning' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'runargs'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_gc' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'pmain'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_concat' defined in 'lapi.c.obj' is imported by 'lua.c.obj' in function 'multiline'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'lua_sethook' defined in 'ldebug.c.obj' is imported by 'lua.c.obj' in function 'lstop'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_checkversion_' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'pmain'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_callmeta' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'msghandler'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_tolstring' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'get_prompt'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_checkstack' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'pushargs'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_error' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'lstop'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_loadfilex' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'dofile'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_loadbufferx' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'dostring'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_newstate' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'main'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_len' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'pushargs'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_traceback' defined in 'lauxlib.c.obj' is imported by 'lua.c.obj' in function 'msghandler'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\LINK : warning LNK4217: symbol 'luaL_openlibs' defined in 'linit.c.obj' is imported by 'lua.c.obj' in function 'pmain'
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\linit.c.obj : error LNK2001: unresolved external symbol luaopen_coroutine
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\linit.c.obj : error LNK2001: unresolved external symbol luaopen_utf8
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\llex.c.obj : error LNK2001: unresolved external symbol luai_ctype_
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\lobject.c.obj : error LNK2001: unresolved external symbol luai_ctype_
D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\lua.dll : fatal error LNK1120: 3 unresolved externals
  [33/46] cmd.exe /C "cd /D D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/BinAssets/ D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/Scenarios/ D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Scenarios && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/Textures/ D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Textures && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/Meshes/ D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Meshes && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/Script/ D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Script && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/Config/ D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Config && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/GravityModels/ D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/GravityModels && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/Flights/ D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Flights && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E make_directory D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Orbitersdk/lib/Lua"
  [34/46] cmd.exe /C "cd /D D:\Programme\Orbiter\orbiter-git-schnepe2\out\build\windows-x64-debug\Sound\XRSound && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E make_directory D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Doc && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E make_directory D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/XRSound && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E make_directory D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Orbitersdk/XRSound/ && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/assets/XRSound/XRSound-Atlantis.cfg D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/assets/XRSound/XRSound-DG-S.cfg D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/assets/XRSound/XRSound-DeltaGlider.cfg D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/assets/XRSound/XRSound-ShuttleA.cfg D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/assets/XRSound/XRSound.cfg D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/XRSound/ && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/assets/XRSound/ReadMe.txt D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/XRSound/ && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy "D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/assets/Doc/XRSound User Manual.pdf" D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Doc/ && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/src/XRSound.h D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/Orbitersdk/XRSound/ && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy D:/Programme/Orbiter/orbiter-git-schnepe2/Extern/irrKlang/x64/bin/winx64-visualStudio/ikpMP3.dll D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy D:/Programme/Orbiter/orbiter-git-schnepe2/Extern/irrKlang/x64/bin/winx64-visualStudio/ikpFlac.dll D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy D:/Programme/Orbiter/orbiter-git-schnepe2/Extern/irrKlang/x64/bin/winx64-visualStudio/irrKlang.dll D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_directory D:/Programme/Orbiter/orbiter-git-schnepe2/Sound/XRSound/assets/XRSound/Default D:/Programme/Orbiter/orbiter-git-schnepe2/out/build/windows-x64-debug/XRSound/Default"
  ninja: build stopped: subcommand failed.

Build All failed.
Urwumpe commented 9 months ago

Hmm.... there must be a migration guide somewhere. The luaopen_coroutine still existed in 5.3, so it must be related to a 5.4 change.

EDIT: Hey... did the lua.lib actually build or not? the build step was reported as failed.

schnepe2 commented 9 months ago

Orbiter currently uses 5.1 (no idea if it's "official" or somehow patched).

schnepe2 commented 8 months ago

For whom it might concern 😉

When I manually build Lua like:

cl /MD /O2 /c /DLUA_BUILD_AS_DLL *.c
ren lua.obj lua.o
ren luac.obj luac.o
link /DLL /IMPLIB:lua5.4.6.lib /OUT:lua5.4.6.dll *.obj
link /OUT:lua.exe lua.o lua5.4.6.lib
lib /OUT:lua5.4.6-static.lib *.obj
link /OUT:luac.exe luac.o lua5.4.6-static.lib

...it absolutely works.

The procedure can be found all over the internet (for example here: https://blog.spreendigital.de/2019/06/25/how-to-compile-lua-5-3-5-for-windows/ just for a different version)

The trick is the rename part, to avoid linking lua.obj & luac.obj. How the CMake magic does this with the current setup is a mistery to me 🤷

TheGondos commented 8 months ago

Regarding the fear of cross module bugs, I was under the impression that each module had its own interpreter spawned and the only shared state was the Orbiter core itself. I tried also to use lua 5.4 on linux but I think there was a change with the way the metatable is handled or something like that and I had to go back to 5.1. Staying with 5.1 could have one potential advantage : if there is a need for a boost in performance, it might be possible to use LuaJIT (which is compatible with 5.1)