Write the callback as a separate function (I know this can often mean passing dozens of variables between functions, but it it worthwhile in this case).
So if your function is called 'my_function(a,b,c)' then put 'result=my_function(x,y,z)' as the callback string. You can then also call my_function at the start of your main script in the normal way.
M