Page 1 of 1

Possible bug in createThread in lib.lua?

Posted: Tue Apr 16, 2013 8:08 am
by dx876234
When wrapping the thread function in createThread it seems to me the possible arguments are lost and not transfered to the thread function, I suspect the:

Code: Select all

	local wrapped = function (...) coroutine.yield(); func(); end;

	local co = coroutine.create(wrapped);

	local status, err = coroutine.resume(co, ...);
In reality should be as follows to pass arguments to the given function?

Code: Select all

	local wrapped = function (...) coroutine.yield(); func(...); end;  -- NOTE: "..." in func argument

	local co = coroutine.create(wrapped);

	local status, err = coroutine.resume(co, ...);
-dx

Re: Possible bug in createThread in lib.lua?

Posted: Tue Apr 16, 2013 1:45 pm
by Administrator
I think you're right. I guess something must have changed somewhere with the update to Lua 5.2 as it used to work.

Thanks for letting me know.

Re: Possible bug in createThread in lib.lua?

Posted: Thu Jun 27, 2013 3:41 am
by dx876234
Upgraded to 1.03, seems this bug is present there, must have leaked between releases :)

best regards
DX

Re: Possible bug in createThread in lib.lua?

Posted: Mon Jul 01, 2013 11:53 am
by Administrator
Are you sure you updated lib.lua? Seems to work for me.

Code: Select all

local function thread(num)
  for i = 1,10 do
    print("Test: ", num);
    coroutine.yield();
  end
end
 
createThread("test2", thread, 1234);
-- Creates a thread that will continually print out "Test: 1234" 10 times then kill itself.

function main()
	while(true) do
		yrest(1);
	end
end
startMacro(main, true);
Edit: This hasn't actually been officially released. It's in the changelog for 1.04, which has a number of improvements but is still far off from a release.