moteus / lua-llthreads2

`llthreads` library rewritten without `LuaNativeObjects` code generator
MIT License
76 stars 22 forks source link

Passing arguments to a thread #3

Closed subnetmarco closed 9 years ago

subnetmarco commented 9 years ago

How can I pass an argument to a thread? For example:

local function start_thread(message)
  local thread = Threads.new({
    function()
      print(message)
    end;
  })
end

start_thread("Hello World")
moteus commented 9 years ago

You can just pass arguments to constructor. Each thread has its own lua_State and you can not use common globals or upvalues.

local function start_thread(message)
  local thread = Threads.new(function(message)
    print(message)
  end, message):start()
end

start_thread("Hello World")
subnetmarco commented 9 years ago

Thank you