lua-users home
lua-l archive

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



Here is a simple rewrite of the example:


-- t1.lua
require 'task'
task.create( 't2.lua')
local msg, flags = task.receive( -1 )
if flags then print( msg ) end

-- t2.lua
local ok, err = pcall( function()

print( 'printing inside t2' )
error( 'hello error' )

end )
if ok then task.post( 1, '', 0 ) else task.post( 1, err or '?', -1 ) end

This pcall solution is much cleaner, very tricky.
I'm using LuaTask with wxLua and the result is great.
The GUI starts a LuaTask and in idle events calls task.receive(0) to update it's LOG text control.
As you suggested I was rewriting error() and assert(), but this method is better.
With the flag parameter I can use 1=control, 2=log, 3=error.
Very simple, very effective, thank you for this great module.
I still miss a way to cancel a task, but I'm aware of the portability/no support issues.

Regards,
Francisco