From 805e3fdd7dbe59544a6665764ce886792e30923c Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 1 May 2025 18:20:02 +0300 Subject: [PATCH] add Bytearray '__pairs` metamethod --- res/modules/internal/bytearray.lua | 3 ++- res/scripts/stdlib.lua | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/res/modules/internal/bytearray.lua b/res/modules/internal/bytearray.lua index 35bc6cc6..ab93cfea 100644 --- a/res/modules/internal/bytearray.lua +++ b/res/modules/internal/bytearray.lua @@ -166,11 +166,12 @@ local bytearray_mt = { end end } +bytearray_mt.__pairs = bytearray_mt.__ipairs local bytearray_type = FFI.metatype("bytearray_t", bytearray_mt) local FFIBytearray = { - __call = function (n) + __call = function (self, n) local t = type(n) if t == "string" then local buffer = malloc(#n) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index f60242cd..3bc2147e 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -279,7 +279,7 @@ end local bytearray = require "core:internal/bytearray" Bytearray = bytearray.FFIBytearray Bytearray_as_string = bytearray.FFIBytearray_as_string -Bytearray_construct = Bytearray.__call +Bytearray_construct = function(...) return Bytearray(...) end ffi = nil math.randomseed(time.uptime() * 1536227939)