[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: prawget etc?
- From: Sean Conner <sean@...>
- Date: Fri, 4 Oct 2013 04:07:33 -0400
It was thus said that the Great Dirk Laurie once stated:
> Look at this:
>
> > print(pcall(0,1,2))
>
> false attempt to call a number value
>
> I.e. `pcall` can't fail. My program retains control.
>
> But now this:
>
> > print(rawget(0,1,2))
> stdin:1: bad argument #1 to 'rawget' (table expected, got number)
>
> To get something non-failing, I need to wrap the 'rawget' in a test inside
> a test for table-ness.
>
> Next time this annoys me enough, I'll write a little module in C that
> provides `prawget` and `prawset`, which stand in the same relationship
> to `rawget` and `rawset` as `pcall` stands to `call`.
>
> Unless someone has already done it?
Um ...
function prawget(tab,idx)
return pcall(rawget,tab,idx)
end
print(prawget(0,1))
print("done")
Seems simple enough ...
-spc