lua-users home
lua-l archive

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


Yes, I am frightened that into this "handle errors this or that" issue
can disturb the work on any larger software project tremendously, and
nevertheless you have to think about this very very carefully very
very early in design state, otherwise later you tend to run easily
into tremendous pitchfalls. And changing application error handling at
later points is usually nearly impossible to keep reasonable
compatibility with already running applications.

In Lua  generally I like the very flexible approach. But I also think
that practically all userdata metafunctions generally should be
programmed advanced enough, that they handle ALL sort of calculations
"thoughtfully" by themselves, including error handling, so I think it
is quite clear that Lua should give error handling to the userdata
metafunction, as soon as ONE of the arguments is some userdata.

On Sun, Jan 30, 2022 at 10:47 PM Nathan Page <nathanrpage97@gmail.com> wrote:
>
> Thanks for the reference snippets, I know that I needed the Protect or
> else the lua vm would crash sometimes (didn't dig into why this
> happens) so it does have precedent. My only concern with going to the
> general step like you show is that lots of libraries, especially c
> libraries may use certain assumptions about the types of things it can
> be compared against leading to errors instead of returning false (not
> sure if you have run into this issue).
>
> Thanks,
> Nathan
>
>
> On Thu, Jan 20, 2022 at 11:30 PM Flyer31 Test <flyer31@googlemail.com> wrote:
> >
> > PS: sorry I overlooked this in the existing / old "..." text, you can
> > then comment out these lines:
> > //      case LUA_VUSERDATA: {
> > //        if (uvalue(t1) == uvalue(t2)) return 1;
> > //        else if (L == NULL) return 0;
> > //        tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
> > //        if (tm == NULL)
> > //          tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
> > //        break;  /* will try TM */
> > //      }
> >
> > (so mainly you just shift this block to the function start and do it
> > also already, if only ONE of two operands is LUA_VUSERDATA).
> >
> > Further I needed a line change in function luaV_execute for the
> > switch-case-block vmcase(OP_EQK):
> > +       Protect(cond = luaV_equalobj(L, s2v(ra), rb));
> > -        cond = luaV_equalobj(L, s2v(ra), rb);
> >
> > .. so I added this "Protect(...)" there - do not ask me why, I did not
> > write a comment there... .