lua-users home
lua-l archive

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

>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!

 function dostring(a)
  return mydostring(%dostring(a))

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.