lua-users home
lua-l archive

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


> > >Let every function that pushes a result
> > >on the stack return the stack index of the result.

> > We thought about that for Lua 4.0, but it brings a performance problem.
> > In many machines (Linux, for instance), the size of a TObject is not
> > a power of 2, and so the difference between two (TObject *) is not
> > an efficient operation.

> Wasting programmer time to gain machine time is rarely worth it, and really
> needs to be backed up with figures. Here it really doesn't seem worth it at
> all, unless I'm missing something big.

I am afraid I didn't make myself clear. The point is that, at least in my 
experience, more often than not you don't use that result. For instance, in 
the whole Lua libraries, we would use such result only once. (Of course, 
that depends a little on your programming style.) So, if we had it for 
free, then we could return it. But to do a computation for a value that 
will almost never be used, then it is better to call lua_gettop explicitly 
when you need it. And it is quite easy to write macros if you want 
that value all the time: 

  #define lua_t_getglobal(L,n)	(lua_getglobal(L,n), lua_gettop(L))
  ...

-- Roberto