lua-users home
lua-l archive

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


According to Lua 5.2 manual, the `collectgarbage` function allows to
change the "pause" and "step multiplier" settings of the garbage
collector, and when doing so, the previous values are returned.
However I don't see a way to retrieve these values without changing
them.

At best I suppose I could change them to some arbitrary value, record
the previous values, then change them back to those, but what values
would be safe to change them to? I might use the defaults, but that
still might not be safe if they've previously been changed. (I also
note that the default value for "pause" doesn't seem to be
documented.)

My concern with just "change it, then change it back" is that a
drastic change might suddenly trigger a long-running cycle, or
otherwise change the collector's state in a way that isn't undone by
changing them back. Besides that, it just feels a bit hackish, and the
API feels incomplete providing a way to change them but not read them.

Perhaps I've just missed something. I thought maybe just omitting the
new value would do what I want (e.g. pause =
collectgarbage("setpause"), but instead it sets the parameter to zero.
(Though, the manual doesn't specify how the function should behave in
this situation, so this seems like undefined behaviour, which means it
should theoretically be safe to change it to "return the current value
and don't change it" in a new version...)

While we're on the subject, the manual also doesn't specify whether
these parameters are floats or integers.

-- 
Sent from my Game Boy.