So, I searched around a while ago, how to make sure a function doesn’t yield. The solution I saw what this:
local function doesYield(func, ...)
local args = ...;
local yields = true
coroutine.wrap(function()
func(args)
yields = false
end)()
return yields
end
And this works, but I can’t return arguments from it and it looks weird.
Now randomly I thought about using coroutine.status to check that, and now this is my attempt at writing this:
local function RunNoYield(func, ...)
local args = ...;
local toReturn;
local thread = coroutine.create(function()
toReturn = table.pack(func(arguments))
end)
coroutine.resume(thread)
local status = coroutine.status(thread)
if status ~= "dead" then
error("Function yielded! Not allowed!")
--\\ can't figure out a way of stopping the function completely as of the moment.
end
return table.unpack(toReturn)
end
And I would like some feedback and some ideas too.