lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all,

while I'm experimenting with lua coroutines and while I'm very happy
with the stunning speed of context switches (I created a "multi
threading" package on top of coroutines in pure lua, and running 100.000
threads is no problem at all), now I'm faced with a evil detail:

Lua 5.0.2. can't yield accross a pcall(). I can't write something like:


	function a()
	  coroutine.yield()
	end

	function b()
	  assert( pcall(a) )
	end

	co = coroutine.create(b)

	assert( coroutine.resume(co) )


Ok, at least this is the way currently lua is implemented, because
pcall() use setjmp()/longjmp() and coroutines aren't implemented using
setjmp()/rightjmp(), right?

Will lua 5.1 help? In lua.h of lua-5.1-work2 I found that lua_pcall()
can return LUA_YIELD. But how to use this code? Should I return
lua_yield() after lua_pcall() returned LUA_YIELD?

If lua 5.1 doesn't help, would it be possible to change lua in that way,
that you can push an error handler function onto the stack followed by
the function to call in a protected environment together with its
arguments? Something like this:


	lua_pushcfunction(L, err_handler);
	lua_push_some_function(L, ...);
	lua_push_some_arguments(L, ...);

	return lua_trycall(L, nargs);	/* like lua_yield() */


If an error occurs, lua can wind up the stack and call the first
'err_handler' it finds and the handler can cleanup. (This is only a
roughly idea.) With this technics it should also be possible to add
try/raise/catch exception handling to lua, if needed.

Opinions? Suggestions?


cu

Michael


-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBcu5uSIrOxc3jOmoRApBxAKC6UpRbhBa/ObCbwN/LXMESR031TgCfUQTr
8vSSpPF+UUJ7jaX7yUYU42A=
=DJyS
-----END PGP SIGNATURE-----