rzel / kahlua

Automatically exported from code.google.com/p/kahlua
0 stars 0 forks source link

About the function() problem in coroutine #13

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I wrote the following Lua source.
revesion kahlua-release-20090426.zip 

After calling Construct() from the inside of the Java code, I am executing 
Loop() repeatedly. 
Although init coroutine function is performed, LuaState.pcall stops 
execution in the part which performs waitproc() in init(). 
waitproc() was not actually executed. 
When the code of waitproc() was unpacked into init(), LuaState.pcall did 
not stop. 

Why is this? 

By an old source code, this problem did not exist rather than a 
20090211zip package. 

local function waitproc()

    local s = 0

    while s == 0 do
        coroutine.yield( 1 )
        s = (Java function)
    end

end

local function init( v )

   (Java function)
   waitproc()  -- LuaState halt

   (Java function)
   waitproc()

   return 0

end

fuction Construct()
   cofunc = coroutine.create( init )
end

function Loop()

    local r , v

    if cofunc ~= nil then

        r , v = coroutine.resume( cofunc )
        if v == 0 then
            cofunc = nil
            return 1;
        end
    end

    return 0

end

Original issue reported on code.google.com by dea...@yahoo.co.jp on 27 Apr 2009 at 11:28

GoogleCodeExporter commented 8 years ago
I can not reproduce it.
Can you try creating a test file called bug13.lua inside kahlua/testsuite/ 
containing
your example code?

You can then test it with:
ant -Dtest.file=bug13.lua

I tried with this code but the test passed, can you see if I did anything wrong 
in
the test?

-- Setup necessary for the test to run
functionCounter = 0
function JavaFunction1()
    functionCounter = functionCounter + 1
    if functionCounter < 10 then
        return 0
    end
    return 1
end

function2Counter = 0    
function JavaFunction2()
    function2Counter = function2Counter + 1

    -- simulate some work
    pcall(function() end)
end

local function waitproc()

    local s = 0

    while s == 0 do
        coroutine.yield( 1 )
        s = JavaFunction1()
    end

end

local function init(v)

   JavaFunction2()

   waitproc()  -- LuaState halt
   JavaFunction2()

   waitproc()
   return 0

end

function Construct()
   cofunc = coroutine.create(init)
end

function Loop()
    local r, v

    if cofunc ~= nil then
        r , v = coroutine.resume(cofunc)
        if v == 0 then
            cofunc = nil
            return 1;
        end
    end

    return 0

end

-- run the test
Construct()
while Loop() == 0 do

end

assert(function2Counter == 2)

Original comment by kristofer.karlsson@gmail.com on 27 Apr 2009 at 12:06

GoogleCodeExporter commented 8 years ago
I'm going to mark this invalid until I am able to reproduce it.
This could be simplified if you sent me code that can be run which proves the 
bug.

Original comment by kristofer.karlsson@gmail.com on 1 May 2009 at 12:15