Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lua51. #15

Closed
orbea opened this issue Feb 12, 2019 · 19 comments
Closed

Support lua51. #15

orbea opened this issue Feb 12, 2019 · 19 comments

Comments

@orbea
Copy link

orbea commented Feb 12, 2019

I was trying to work on building RetroArch with a system version of lua as requested in issue libretro/RetroArch#8153.

However this is made impossible by two things.

  1. rcheevos only builds with lua52 or lua53.
  2. Upstream lua doesn't provide their own shared library or pkgconfig files and this makes checking for the versioned lua libraries or pkgconfig files not portable since every distro reinvents the wheel to accomplish this...

If rcheevos built and worked with any lua version this would be a lot easier to support.

The current build problem is.

deps/rcheevos/src/rcheevos/operand.c: In function ‘rc_evaluate_operand’:
deps/rcheevos/src/rcheevos/operand.c:348:38: error: ‘LUA_OK’ undeclared (first use in this function); did you mean ‘LUA_QL’?
         if (lua_pcall(L, 2, 1, 0) == LUA_OK) {
                                      ^~~~~~
                                      LUA_QL
deps/rcheevos/src/rcheevos/operand.c:348:38: note: each undeclared identifier is reported only once for each function it appears in
make: *** [Makefile:201: obj-unix/release/deps/rcheevos/src/rcheevos/operand.o] Error 1

This feature is apparently not supported by lua51.

@orbea
Copy link
Author

orbea commented Feb 12, 2019

Is this the right repo?

@leiradel
Copy link
Contributor

We intend to use Lua 5.3 because it has bit operators, which makes life a lot easier to write functions that test bits in memory.

Do you absolutely have to use an old Lua version?

@orbea
Copy link
Author

orbea commented Feb 12, 2019

The only way for me to support a system lua in RetroArch's configure is to check only lua.pc, -llua and lua.h, depending on the distro this could be lua51, lua52, or lua53. Trying to check for specific versions just falls apart due to inconsistency between distros...

The alternative would be to fix upstream lua to provide their own shared libraries and pkgconfig files so it could be consistent to test for specific versions, but I'm not holding my breath on that...

From lua53.

/* thread status */
#define LUA_OK          0
#define LUA_YIELD       1
#define LUA_ERRRUN      2
#define LUA_ERRSYNTAX   3
#define LUA_ERRMEM      4
#define LUA_ERRGCMM     5
#define LUA_ERRERR      6

And in lua51.

/* thread status; 0 is OK */
#define LUA_YIELD       1
#define LUA_ERRRUN      2
#define LUA_ERRSYNTAX   3
#define LUA_ERRMEM      4
#define LUA_ERRERR      5

So this diff seems to at least build, would it be acceptable?

diff --git a/deps/rcheevos/src/rcheevos/operand.c b/deps/rcheevos/src/rcheevos/operand.c
index 1e760daa16..a479abf416 100644
--- a/deps/rcheevos/src/rcheevos/operand.c
+++ b/deps/rcheevos/src/rcheevos/operand.c
@@ -345,7 +345,7 @@ unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_S
 
         lua_pushlightuserdata(L, &luapeek);
         
-        if (lua_pcall(L, 2, 1, 0) == LUA_OK) {
+        if (lua_pcall(L, 2, 1, 0) == 0) {
           if (lua_isboolean(L, -1)) {
             value = lua_toboolean(L, -1);
           }

@orbea
Copy link
Author

orbea commented Feb 21, 2019

@leiradel Any further comments?

@leiradel
Copy link
Contributor

Only that I still don't understand the issue. rcheevos needs Lua 5.3, and the branch where it's integrated into RetroArch even includes Lua 5.3's source code. I don't see why we would want to integrate the system's version of Lua instead of that.

@orbea
Copy link
Author

orbea commented Feb 21, 2019

I see two reasons.

  1. Its strongly preferred to use system libraries instead of bundled ones with distros and some users.
  2. Its helpful for debugging lua bugs or regressions which affect RetroArch.

@leiradel
Copy link
Contributor

Sorry, I still don't understand. RetroArch doesn't include rcheevos yet, so it can use whatever Lua it wants, either integrated as source code or from the system. rcheevos needs Lua 5.3, so why patch it to link against other versions?

@orbea
Copy link
Author

orbea commented Feb 26, 2019

I'm not sure who added it, but rcheevos is exposed by ./configure --enable-new_cheevos and it will use lua with --enable-lua.

https://github.com/libretro/RetroArch/tree/0aa9df6acd91212880150554651573d9571f1697/deps/rcheevos

https://github.com/libretro/RetroArch/blob/0aa9df6acd91212880150554651573d9571f1697/Makefile.common#L1678

Honestly I think using lua is causing more problems than its worth, but its not my call. :)

@leiradel
Copy link
Contributor

I'm not sure who added it

I believe it was @meleu , in order to debug the issues that appeared with rcheevos on Android.

Honestly I think using lua is causing more problems than its worth, but its not my call. :)

I know nothing about this other functionality that needs Lua, but I have plenty of experience with it both as a programmer and embedding it into other applications and it's a breeze to work with, but that's also not my call either.

@orbea
Copy link
Author

orbea commented Feb 26, 2019

Just for reference one issue is that when built with --enable-lua (Using the builtin lua5.3) and --enable-mpv when libmpv is built against lua RetroArch will immediately crash in the system lua.

Another issue is the mess with upstream lua and shared libraries I was hoping to work around here.

@leiradel
Copy link
Contributor

Hm, maybe mpv doesn't work with 5.3? Is this with latest? I can take a look later.

@orbea
Copy link
Author

orbea commented Feb 26, 2019

I'm not sure if it works with 5.3 or not, but its built against 5.1 by default here which works fine. It should occur with the mpv and RetroArch master.

Edit: I asked in the mpv irc channel and was told anything other than lua5.3 or newer...

@leiradel
Copy link
Contributor

$ ./configure --enable-lua --enable-mpv
Checking operating system ... Linux (Ubuntu 18.04.1 LTS 18.04)
(snip)
Checking presence of package mpv ... no
Forced to build with package mpv, but cannot locate. Exiting ...

@orbea
Copy link
Author

orbea commented Feb 28, 2019

You need to build mpv with --enable-libmpv-shared and you should have a mpv.pc and libmpv.so files installed.

@leiradel
Copy link
Contributor

I did an apt-get install, but I'll try building it myself. It's this one, right?

@orbea
Copy link
Author

orbea commented Feb 28, 2019

Yes, that one.

https://github.com/mpv-player/mpv

If you need any help building it let me know, they use waf as their build system.

@orbea
Copy link
Author

orbea commented Feb 28, 2019

Actually I forgot three details, first that --enable-mpv still has this build issue (Hence being disabled by default) since the audio callback was never finished upstream in libmpv.

LD retroarch
/usr/bin/ld: obj-unix/release/cores/libretro-mpv/mpv-libretro.o: in function `libretro_mpv_retro_run':
mpv-libretro.c:(.text+0x88f): undefined reference to `mpv_audio_callback'
collect2: error: ld returned 1 exit status
make: *** [Makefile:196: retroarch] Error 1

Here is a workaround, but there will be no audio when using the mpv core in RetroArch which is not important for testing this.

diff --git a/cores/libretro-mpv/mpv-libretro.c b/cores/libretro-mpv/mpv-libretro.c
index c84ebd2561..15fa6f5b24 100644
--- a/cores/libretro-mpv/mpv-libretro.c
+++ b/cores/libretro-mpv/mpv-libretro.c
@@ -399,6 +399,7 @@ void CORE_PREFIX(retro_reset)(void)
 {
 }
 
+#if 0
 static void audio_callback(double fps)
 {
        /* Obtain len samples to reduce lag. */
@@ -436,6 +437,7 @@ static void audio_callback(double fps)
        }
        while(len > 4);
 }
+#endif
 
 static void retropad_update_input(void)
 {
@@ -557,7 +559,7 @@ void CORE_PREFIX(retro_run)(void)
        retropad_update_input();
 
        /* TODO #2: Implement an audio callback feature in to libmpv */
-       audio_callback(container_fps);
+       /* audio_callback(container_fps); */
 
        process_mpv_events(MPV_EVENT_NONE);
 

Second you need to build RetroArch with --enable-new_cheevos and --enable-lua now to even build with lua.

And third my memory was flawed and the crashes only occur when trying to use the builtin mpv core by loading a video file.

@orbea
Copy link
Author

orbea commented Feb 28, 2019

For reference here is the unfinished PR for libmpv to fix the audio.

mpv-player/mpv#5566

@deltabeard
Copy link

The master branch of libretro-mpv as I left it seems to have the audio callback functions commented out, so your patch shouldn't be required and should compile fine without any changes to mpv (other than enabling shared libs), unless if you're using the audio-cb-new branch of the repo.

I'm having another crack at fixing this audio callback nonsense in libretro-mpv...

@orbea orbea closed this as completed Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants