lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

If a new thread is created with lua_newthread, can I in that thread create a table, add it to another global table (List) and use that other table to access the first table in the main thread?

In other words, can I do this:

List = {}

-- called from 'other' thread
function ListV3D(x, y, z)

-- ... lock so List isn't accessed simultaniously ...

local entry = {}
List[#List + 1] = entry

entry.x = x
entry.y = y
entry.z = z

--- ... unlock ...
end

-- called in 'main' thread
function DoList()
-- ... do the lock thing ...

if #List > 0 then
  local i = 1
 while List[i] do
  local entry = List[i]
  -- ... do something with entry ...
 i = i + 1
 end
 List = {}
end

-- ... unlock ...
end

I am getting some weird crashes, not sure if it is because the above is invalid in some way...

   Thanks!
Hugo