Lua and the use of xpcall

Started by garry23, June 26, 2016, 12:44:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

I hope some kind expert will be able to point me in the right direction.

I'm still trying to detect the 'soft limit reached' in a Lua script and thought I would try pcall and xpcall.

I'm using this test script:

err_state = true

function move()
lens.focus(1,1,true)
end

function erf()
err_state = false
end

function focus()
err_state = true
repeat
xpcall(move,erf)
until err_state == false
-- now move the other way having detected an error
lens.focus(-10,1,true)
end

scrnshot_menu = menu.new
{
    name = "Test",
select = function(this)
task.create(focus)
end
}


The lens moves as instructed and a 0 gets displayed but the (soft limit) error doesn't get intercepted and I get the ML error message and the script stops.

Anyone got any ideas?

dmilligan

lens.focus does not "raise" a Lua error (this is something that must be done explicitly by the Lua backend), it returns true or false whether or not it succeeded.

garry23