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
Before you make a thread asking for help, read this.
Post Reply
rbisso
Prole
Posts: 1
Joined: Sun Feb 15, 2009 10:28 am

attempt to yield across metamethod/C-call error

Post by rbisso »

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 :D

Code: Select all

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

...

function rotate_enemy(which_enemy, num_angle)
	local cur_heading = which_enemy.heading
	local goal_heading = which_enemy.heading + num_angle
	local angle_increment = num_angle / which_enemy.rate_rotation

	
	while( cur_heading ~= goal_heading )do
		cur_heading = cur_heading + angle_increment
		which_enemy.heading = cur_heading
		coroutine.yield()
	end
end
co_rotate_enemy = coroutine.create(rotate_enemy)

...

function resume_coroutines()  -- register my coroutines here...
	if(coroutine.status(co_rotate_enemy) ~= 'dead' )then
		coroutine.resume(co_rotate_enemy)
	end
end

User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

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

Post by rude »

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).
User avatar
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

Post by Sslaxx »

Does this mean it'll then become the coder's responsibility to create/update the main loop?
User avatar
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

Post by bartbes »

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.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

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

Post by rude »

@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.
   -- loads the main.lua file from your game. 
   -- 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()
   -- load()
   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.load() ... end
function love.update(dt) ... end
function love.draw() ... end
User avatar
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

Post by Sslaxx »

Always struck me as odd as to why update/init/load weren't in the love table.
User avatar
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

Post by bartbes »

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.
User avatar
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

Post by Star Crunch »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests