luerl icon indicating copy to clipboard operation
luerl copied to clipboard

Validate Func(Args) return value

Open maxlapshin opened this issue 12 years ago • 4 comments

Need to validate return value from called function.

maxlapshin avatar Jul 17 '13 17:07 maxlapshin

I was wondering what would be the best way of handling bad return values. Instead of matching a pair would it be better to just accept anything as a bad return value and generate an error. Dou you intend and Erlang or a Lua error?

rvirding avatar Jul 20 '13 01:07 rvirding

I think that erlang error is better, because problem is on erlang level.

And I don't understand why don't you like this patch. I check return value and if is bad, I raise error.

maxlapshin avatar Jul 20 '13 03:07 maxlapshin

I don't dislike this patch, I was just wondering if it shouldn't be something like:

case Func(Args, St0#luerl{stk=Stk}) of
    {Ret,St1} when is_list(Ret) ->
        {Ret,St1#luerl{stk=Stk0}};      %Replace it
    _ ->
        error({invalid_reply,function,Func})
end;

so it catches all error returns?

rvirding avatar Jul 20 '13 20:07 rvirding

so, maybe better:

case Func(Args, ...) of
    {Ret, St1} when is_list(Ret) >
        {Ret, St1#luerl{stk =Stk0}};
    {Ret, St1} -> 
        error({invalid_reply,Ret,function,Func});
    _ ->
         error({invalid_return,function,Func})
 end

?

On Jul 21, 2013, at 12:43 AM, Robert Virding wrote:

I don't dislike this patch, I was just wondering if it shouldn't be something like:

case Func(Args, St0#luerl{stk=Stk}) of {Ret,St1} when is_list(Ret) -> {Ret,St1#luerl{stk=Stk0}}; %Replace it _ -> error({invalid_reply,function,Func}) end; so it catches all error returns?

— Reply to this email directly or view it on GitHub.

maxlapshin avatar Jul 21 '13 05:07 maxlapshin