master hovercats/oakiss / pkg / mpv / patch / 0005-Support-lua-5.4.patch
 1From ae44889fc30137f38b74cd0119fe7196c0a1b043 Mon Sep 17 00:00:00 2001
 2From: Michael Forney <mforney@mforney.org>
 3Date: Sun, 3 Dec 2023 11:57:01 -0800
 4Subject: [PATCH] Support lua 5.4
 5
 6---
 7 player/lua.c       | 5 -----
 8 player/lua/osc.lua | 8 ++++----
 9 2 files changed, 4 insertions(+), 9 deletions(-)
10
11diff --git a/player/lua.c b/player/lua.c
12index 63547694e2..0b8c632acd 100644
13--- a/player/lua.c
14+++ b/player/lua.c
15@@ -455,11 +455,6 @@ static int load_lua(struct mp_script_args *args)
16 
17     stats_register_thread_cputime(ctx->stats, "cpu");
18 
19-    if (LUA_VERSION_NUM != 501 && LUA_VERSION_NUM != 502) {
20-        MP_FATAL(ctx, "Only Lua 5.1 and 5.2 are supported.\n");
21-        goto error_out;
22-    }
23-
24     lua_State *L = ctx->state = luaL_newstate();
25     if (!L) {
26         MP_FATAL(ctx, "Could not initialize Lua.\n");
27diff --git a/player/lua/osc.lua b/player/lua/osc.lua
28index 3ba1890a92..945af861f0 100644
29--- a/player/lua/osc.lua
30+++ b/player/lua/osc.lua
31@@ -175,7 +175,7 @@ local margins_opts = {
32 function get_virt_scale_factor()
33     local w, h = mp.get_osd_size()
34     if w <= 0 or h <= 0 then
35-        return 0, 0
36+        return 1, 1
37     end
38     return osc_param.playresx / w, osc_param.playresy / h
39 end
40@@ -193,7 +193,7 @@ end
41 
42 function set_virt_mouse_area(x0, y0, x1, y1, name)
43     local sx, sy = get_virt_scale_factor()
44-    mp.set_mouse_area(x0 / sx, y0 / sy, x1 / sx, y1 / sy, name)
45+    mp.set_mouse_area(x0 // sx, y0 // sy, x1 // sx, y1 // sy, name)
46 end
47 
48 function scale_value(x0, x1, y0, y1, val)
49@@ -299,7 +299,7 @@ end
50 
51 -- multiplies two alpha values, formular can probably be improved
52 function mult_alpha(alphaA, alphaB)
53-    return 255 - (((1-(alphaA/255)) * (1-(alphaB/255))) * 255)
54+    return alphaA + alphaB - alphaA * alphaB / 255
55 end
56 
57 function add_area(name, x1, y1, x2, y2)
58@@ -318,7 +318,7 @@ function ass_append_alpha(ass, alpha, modifier)
59         if state.animation then
60             av = mult_alpha(av, state.animation)
61         end
62-        ar[ai] = av
63+        ar[ai] = math.floor(av)
64     end
65 
66     ass:append(string.format("{\\1a&H%X&\\2a&H%X&\\3a&H%X&\\4a&H%X&}",
67-- 
682.44.0
69