lua-users home
lua-l archive

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


On Sep 1, 2014, at 11:02 PM, Sean Conner <sean@conman.org> wrote:

>  I thought that you could yield through a C-call boundary in Lua 5.2.  

I guess not always, e.g.:

local function gfind( aString, aPattern, isPlain )
  assert( type( aString ) == 'string' )
  assert( type( aPattern ) == 'string' )
  assert( aPattern:len() > 0 )

  if isPlain then aPattern = aPattern:gsub( '%p', '%%%1' ) end
  aPattern = ( '()(%s)()' ):format( aPattern )

  return coroutine.wrap( function() aString:gsub( aPattern, function( aStart, aValue, anEnd ) coroutine.yield( aStart, anEnd - 1, aValue ) end ) end )
end

for aStart, anEnd in gfind( aString, aPattern ) do
  print( aStart, anEnd, ( '%q' ):format( aString:sub( aStart, anEnd ) ) )
end

lua: attempt to yield across a C-call boundary
stack traceback:
	[C]: in function 'for iterator'