Can someone help me with moving a memory address
Posted: Fri Jan 28, 2022 10:46 pm
I am trying to smuggle a memory address into a lua thread, but I can't figure out how to.
I thought maybe I could use love.data but things aren't panning out.
I just want to be able to access the same memory I use in the main thread in a seperate thread.
I thought maybe I could use love.data but things aren't panning out.
I just want to be able to access the same memory I use in the main thread in a seperate thread.
Code: Select all
local ffi = require("ffi")
ffi.cdef(" typedef long map[1000000]; void* malloc(size_t); void free(void*);")
local Memory = love.data.newByteData(ffi.sizeof("map"))
local map = ffi.cast("map(&)", Memory:getFFIPointer())
map[7] = 44
local threadCode = [[
-- Receive values sent via thread:start
local bytedata = ...
local ffi = require("ffi")
ffi.cdef(" typedef long map[10000000]; void* malloc(size_t); void free(void*);")
local map = ffi.cast("map(&)", bytedata)
print("THREAD", map[7]) -- Should equal 44
]]
thread = love.thread.newThread(threadCode)
thread:start(Memory, 0)