lua-users home
lua-l archive

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


> Is it possible to do something in Lua and somehow control use of
> temporary objects when dealing with typical +-*/ math operations in Lua??

It is not possible to know directly when Lua is creating a temporary object,
though you could do something along the lines of the "Using fallbacks" section
in the SPE paper: http://www.lua.org/spe.html (I have the equivalent code for
Lua 5.1 somewhere).

Another alternative is to provide "begin_computation" and "end_computation"
functions that will store all objects created between these calls in an
internal C stack that can be freed or recycled in one go.

for n=1,1000 do
    begin_computation()
    m= m*m1 + m2
    end_computation()  -- must not free m, ie, the last object created
end