add FFIBytearray
This commit is contained in:
parent
4260742d6e
commit
36c2971fcf
@ -263,6 +263,8 @@ entities.get_all = function(uids)
|
||||
return stdcomp.get_all(uids)
|
||||
end
|
||||
end
|
||||
FFIBytearray = require "core:internal/bytearray"
|
||||
ffi = nil
|
||||
|
||||
math.randomseed(time.uptime() * 1536227939)
|
||||
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
local _ffi = ffi
|
||||
ffi = nil
|
||||
|
||||
-- Lua has no parallelizm, also _set_data does not call any lua functions so
|
||||
-- may be reused one global ffi buffer per lua_State
|
||||
local canvas_ffi_buffer
|
||||
@ -8,14 +5,14 @@ local canvas_ffi_buffer_size = 0
|
||||
|
||||
function __vc_Canvas_set_data(self, data)
|
||||
if type(data) == "cdata" then
|
||||
self:_set_data(tostring(_ffi.cast("uintptr_t", data)))
|
||||
self:_set_data(tostring(ffi.cast("uintptr_t", data)))
|
||||
end
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
|
||||
local size = width * height * 4
|
||||
if size > canvas_ffi_buffer_size then
|
||||
canvas_ffi_buffer = _ffi.new(
|
||||
canvas_ffi_buffer = ffi.new(
|
||||
string.format("unsigned char[%s]", size)
|
||||
)
|
||||
canvas_ffi_buffer_size = size
|
||||
@ -23,7 +20,7 @@ function __vc_Canvas_set_data(self, data)
|
||||
for i=0, size - 1 do
|
||||
canvas_ffi_buffer[i] = data[i + 1]
|
||||
end
|
||||
self:_set_data(tostring(_ffi.cast("uintptr_t", canvas_ffi_buffer)))
|
||||
self:_set_data(tostring(ffi.cast("uintptr_t", canvas_ffi_buffer)))
|
||||
end
|
||||
|
||||
function crc32(bytes, chksum)
|
||||
@ -31,14 +28,14 @@ function crc32(bytes, chksum)
|
||||
|
||||
local length = #bytes
|
||||
if type(bytes) == "table" then
|
||||
local buffer_len = _ffi.new('int[1]', length)
|
||||
local buffer = _ffi.new(
|
||||
local buffer_len = ffi.new('int[1]', length)
|
||||
local buffer = ffi.new(
|
||||
string.format("char[%s]", length)
|
||||
)
|
||||
for i=1, length do
|
||||
buffer[i - 1] = bytes[i]
|
||||
end
|
||||
bytes = _ffi.string(buffer, buffer_len[0])
|
||||
bytes = ffi.string(buffer, buffer_len[0])
|
||||
end
|
||||
return _crc32(bytes, chksum)
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user