Attempt to yield across C-call boundary
Posted: Sat Jul 04, 2015 2:24 pm
So I'm trying to make a global function _G.wait(sTime), and it does the same thing as love.timer.sleep, only it will hault the current thread running rather than the whole window. This allows my to yield the main thread, but not love.draw or love.update. Here's what's going on:
MainMenu.lua:
This code will, successfully, wait two seconds before starting up the main menu.
However, when I try waiting inside the main menu file, rather than inside main.lua, it will give me this error:
Error: Attempt to yield across C-call boundary.
Debugging the traceback of the callstack, I've pinpointed the problem. The problem, I found was that that the require() function is a C function, meaning when I try yielding, it will halt the thread past a C function.
Is there any good way to get around this? I want to be able to use multiple files in order to organize my game efficiently. And I also want to run the game's thread separate from the thread that love.draws and love.updates in order to time my game into a certain sequence (For cutscenes and such) within the same function.
Code: Select all
_G.GlobalData = {}
MainWaiting = false
MainWaitingTimer = 0
_G.wait = function(sTime)
MainWaitingTimer = sTime or 1 / 30
MainWaiting = true
coroutine.yield()
end
function love.load(arg)
GlobalData.MainThread = coroutine.create(function() -- This will separate the game from the main thread calling love.update and love.draw.
wait(2)
require("MainMenu")()
end)
coroutine.resume(GlobalData.MainThread)
end
function love.update(deltaTime)
if MainWaiting then
MainWaitingTimer = MainWaitingTimer - deltaTime
if MainWaitingTimer < 0 then
MainWaiting = false
coroutine.resume(GlobalData.MainThread)
end
end
end
Code: Select all
return function()
print("Hello, World!")
end
However, when I try waiting inside the main menu file, rather than inside main.lua, it will give me this error:
Error: Attempt to yield across C-call boundary.
Debugging the traceback of the callstack, I've pinpointed the problem. The problem, I found was that that the require() function is a C function, meaning when I try yielding, it will halt the thread past a C function.
Is there any good way to get around this? I want to be able to use multiple files in order to organize my game efficiently. And I also want to run the game's thread separate from the thread that love.draws and love.updates in order to time my game into a certain sequence (For cutscenes and such) within the same function.