lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hey all,

Correct me if I'm wrong, but one can not yeild from a hook (say a "line" or a "count") function in Lua 5? I wonder if the script below somehow violates expectations for 'yield' usage. I thought a while ago we were told Lua 5 release version will have this capability.

The ouput from the script below is very clear

	Lua 5.0
	LUA :: coroutine_main -- x = 	1
	LUA :: coroutine_main -- x = 	2
	LUA :: coroutine_main -- x = 	3
	LUA :: coroutine_main -- x = 	4
	LUA :: hook event -- 	count
	false	attempt to yield across metamethod/C-call boundary
	false	cannot resume dead coroutine


Any ideas? Thanks,
Alex 

-- Here is the script I am experimenting with.
print(_VERSION)

function coroutine_main()
   function hook (event)
      print("LUA :: hook event -- ", event)
      coroutine.yield()
   end

   debug.sethook(hook, '', 30)
   
   local x = 0
   while(true)
   do 
      x=x+1
      print("LUA :: coroutine_main -- x = ", x)
   end
end

local co = coroutine.create(coroutine_main)

local result, err
result, err = coroutine.resume(co)
print (result, err)
result, err = coroutine.resume(co)
print (result, err)