attempt to yield across metamethod/C-call error

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
rbisso
Prole
Posts: 1
Joined: Sun Feb 15, 2009 10:28 am

attempt to yield across metamethod/C-call error

Hey all,

(Crazy that Valentine's Day (more or less) is my first post on the Love forums, eh?)

In order to simulate spawning a function in another thread, I'm using Lua coroutines. I'm creating the coroutine as per normal, yielding within a loop that's in the coroutine-ized function, and then resuming at the bottom of my update loop. When it goes to resume, it gives me the error:
attempt to yield across metamethod/C-call boundary
Anyone ever get this? How did you deal with it? Thanks so much for your help

Code: Select all

function update( dt )
...
resume_coroutines()
end

...

function rotate_enemy(which_enemy, num_angle)
local angle_increment = num_angle / which_enemy.rate_rotation

coroutine.yield()
end
end
co_rotate_enemy = coroutine.create(rotate_enemy)

...

function resume_coroutines()  -- register my coroutines here...
coroutine.resume(co_rotate_enemy)
end
end



rude
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: attempt to yield across metamethod/C-call error

I've never used coroutines, so frankly, I have (almost) no idea.

HOWEVER: The problem might be related to the fact that the main loop is in C. The global functions update and draw are called each frame. I don't have a solution to your problem, but maybe this will give someone else an idea. (FYI: main loop will be in Lua next version).

Sslaxx
Citizen
Posts: 57
Joined: Sat Feb 14, 2009 8:54 pm
Location: Malvern, Worcs, UK
Contact:

Re: attempt to yield across metamethod/C-call error

Does this mean it'll then become the coder's responsibility to create/update the main loop?

bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: attempt to yield across metamethod/C-call error

As written somewhere else, there is a default which will do exactly the same as the C code is doing now, however you can create your own main loop.

rude
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: attempt to yield across metamethod/C-call error

@Sslaxx, bartbes, and anybody else who cares:

Code: Select all

-- Love.init is the one and only function to be called from C.
-- This function is compiled as Lua-code into the executable, and
-- can't be changed, because it's the function that loads your code (main.lua).
function love.init()
-- loads modules, sets up write directory, and other secret stuff.
-- calls love.run()
end

-- This function is also compiled into the executable, but it is called AFTER main.lua
-- is loaded, so you can overwrite it if you wish.
function love.run()
while running do
-- get events, call callbacks
-- update()
-- draw()
end
end

-- You CAN completely ignore the existence of love.run, and use these like normal
-- (yes, they will be moved to the love-table).
function love.update(dt) ... end
function love.draw() ... end


Sslaxx
Citizen
Posts: 57
Joined: Sat Feb 14, 2009 8:54 pm
Location: Malvern, Worcs, UK
Contact:

Re: attempt to yield across metamethod/C-call error

Always struck me as odd as to why update/init/load weren't in the love table.

bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: attempt to yield across metamethod/C-call error

Well, it always made sense to me in the way that those callbacks aren't actually part of the API/SDK/whatever we need to call it provided by love. They are required, but they're not part of.

Star Crunch
Prole
Posts: 33
Joined: Sun Feb 15, 2009 12:13 am
Location: Monterrey, MX
Contact:

Re: attempt to yield across metamethod/C-call error

I don't have a solution to your problem, but maybe this will give someone else an idea. (FYI: main loop will be in Lua next version).
Unless you plan to target something REALLY exotic, your next version could be built on http://luajit.org/coco.html and this issue should never show up.

Who is online

Users browsing this forum: Davidobot and 25 guests