From 3502da4889bb9d04b6e127bd18bcb6aa7d7cd9ec Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Tue, 7 Feb 2023 22:19:05 +0100 Subject: [PATCH] Add support for byte arrays to audio.play --- Capy64/Runtime/Libraries/Audio.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Capy64/Runtime/Libraries/Audio.cs b/Capy64/Runtime/Libraries/Audio.cs index 53186a6..23bed03 100644 --- a/Capy64/Runtime/Libraries/Audio.cs +++ b/Capy64/Runtime/Libraries/Audio.cs @@ -90,7 +90,25 @@ public class Audio : IPlugin { var L = Lua.FromIntPtr(state); - var buffer = L.CheckBuffer(1); + byte[] buffer; + + if (L.IsString(1)) + { + buffer = L.CheckBuffer(1); + } + else + { + L.CheckType(1, LuaType.Table); + var len = L.RawLen(1); + buffer = new byte[len]; + for (int i = 1; i <= len; i++) + { + L.GetInteger(1, i); + var value = L.CheckInteger(-1); + buffer[i - 1] = (byte)value; + L.Pop(1); + } + } if (_game.Audio.Sound.PendingBufferCount > queueLimit) {