[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: dostring that aborts on errors?
From: Luiz Henrique de Figueiredo <lhf () tecgraf ! puc-rio ! br>
Date: 2001-10-23 13:00:45
Message-ID: 200110231300.LAA04394 () ibere ! tecgraf ! puc-rio ! br
[Download RAW message or body]
>How do I write a "non-trapping" version of the "dostring" function
>that will propagates errors instead of just returning a nil and an error
>string? The default behaviour is that this code
A simple C solution is to change passresults in lbaselib.c to do this.
This solution has the advantage that it will work for bith dostring and dofile.
A simple Lua solution is this:
function mydostring(...)
if arg[1]==nil and type(arg[2])=="string" then error() end
return arg[1],arg[2],arg[3],arg[4],arg[5] -- lazy!
end
function dostring(a)
return mydostring(%dostring(a))
end
The line marked "lazy" above should be replaced by a series of ifs no arg.n,
or by "return unpack(arg)" if you're using 4.1. If you're using 4.0, then you
can just copy the implementation of unpack in lbaselib.c from 4.1-alpha.
--lhf
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic