bennyxqg / lua-alchemy

Automatically exported from code.google.com/p/lua-alchemy
0 stars 0 forks source link

flyield() doesn't seem to fully relinquish control #112

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. use flyield() in a loop to allow flex to resume for handling async data.

Example lua code: (container is the flex object that manages the URLLoader)

url = "http://www.yahoo.com"
container.loadSomeData( as3.toas3(url))
repeat
    as3.flyield()
until( as3.tolua(container.lua_status) ~= 0  )

print (as3.tolua( container.urlData ))

Example As3 code:

public var lua_status:int = 1;

public var init() : void {
    loader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, handleData );
}

public var loadSomeData( url:String ) : void {
    lua_status = 0;
        loader.load( new URLRequest(url) ); 
}

public function handleData( event:Event ) : void {
    urlData = loader.data; 
    lua_status = 1;
}

I did see the discussion on Adobe's Alchemy forum. It seems that the as3lib
example uses flyield, but they do their test for continuation in the C code. 

Would it make to sense to allow a callback into lua's C environment, so
that an flpause function can be created, and then lua resumed from within
as3, with a callback mechanism as in the following example:

lua:

-- call some async function
container.loadData( url )
as3.pause()

As3:
public var lua:LuaAlchemy;
public function handleLoadComplete( event:Event ) : void {
     lua.resume();
}

One possible mechanism for this is to set a flag in the lua environment
e.g. lua_running, and use a loop as in the as3lib example

if (!lua_running) {
    flyield();
}

I'm currently unable to find a way to totally pause the Alchemy state
machine, but I think that would actually be a useful thing if there was a
way of doing it.

Original issue reported on code.google.com by sh0rtw...@gmail.com on 13 Feb 2009 at 11:23

GoogleCodeExporter commented 9 years ago
Adobe Alchemy's flyield() is ether broken or badly documented -- it does not 
work as
expected. The problem is reproduceable without Lua Alchemy, in plain C. (See 
also
as3/filegetcontents.lua for Lua Alchemy-only implementation of your code.)

We're working on devising a the workaround for this problem.

If you need to pause Lua script, you may do this without Lua Alchemy help: put 
your
Lua code inside a Lua coroutine. Pause would be a call to coroutine.yield(). 
Resume
that coroutine on AS3 timer events. If you wish a sample code, please ask in Lua
Alchemy mailing list, I'll help you there.

http://groups.google.com/group/lua-alchemy-dev

Original comment by aglad...@gmail.com on 14 Feb 2009 at 6:38

GoogleCodeExporter commented 9 years ago
By default it only yields for one millisecond.  However, ACHACKS_TMPS=1 lets 
one see 
how it is compiling the statement.  Maybe something like this could help?

__asm__("mstate.esp += 8; state ++; throw new AlchemyYield(1000);"); // yield 
for one 
second

Original comment by fuzzy...@gmail.com on 19 Mar 2009 at 3:27

GoogleCodeExporter commented 9 years ago
It seems that flyield works only if method it is called in is declared as 
AS3_FunctionAsync.

Original comment by aglad...@gmail.com on 21 Feb 2010 at 9:43

GoogleCodeExporter commented 9 years ago
...Or maybe we should yield in a loop.

Original comment by aglad...@gmail.com on 15 Apr 2011 at 2:41

GoogleCodeExporter commented 9 years ago
Yes, we should yield in a loop, and yes, flyield would work only if it is 
called from async function.

So, welcome doStringAsync(callback, code)

Original comment by aglad...@gmail.com on 19 Apr 2011 at 12:13