lune icon indicating copy to clipboard operation
lune copied to clipboard

collectgarbage("count") does not accept other values [v0.10.0 - v0.10.1]

Open TokenManiac opened this issue 5 months ago • 8 comments

Hello, just today I noticed that any other option than "count" passed into collectgarbage throws the following error in versions v0.10.0 - v0.10.1:

collectgarbage("collect")

test:1: collectgarbage called with invalid option
[Stack Begin]
    Script '[C]'
    Script 'test', Line 1
[Stack End]

Expected behavior: collectgarbage("collect" | "stop" | "restart" | "step" | "isrunning") should run without errors, as in previous versions.

Actual behavior: The function throws an “invalid option” error for any option except "count"

This change wasn't specified in the changelog so it may just be a mistake? Either way it may result in confusion 👍

p.s. thank you for maintaining this awesome project!

TokenManiac avatar Jul 20 '25 00:07 TokenManiac

This is a mlua change to block collectgarbage collect etc in sandboxed mode (Im actually the person who asked for this change too) due to the security implications of allowing user code to control the gc. This is not just me/mlua btw, it’s actually what luau itself recommends (see https://luau.org/sandbox#library) so I’d say that this change brings mlua more in line with luau’s sandboxing guidelines.

Personally, I think that lune should expose its own gc API if that’s something actually desired though

cheesycod avatar Jul 20 '25 04:07 cheesycod

I would say one of the strengths of lune is its flexibility (with the upcoming ffi support). I'd like to see a few options being brought back.

An approach might be an optional "unsafe" flag for power users who know exactly what they're doing, allowing options like "step" and "collect" but excluding ones like "stop" or "restart" (maybe?). Or as you've suggested an API could be introduced to keep things way safer. I'm not exactly sure.

Again, with the upcoming ffi support, having more granular GC control would definitely improve flexibility over memory.

TokenManiac avatar Jul 23 '25 16:07 TokenManiac

Yeah I'm not quite sure what to do about this. Lune enables sandboxed Luau for performance reasons, and manual garbage collection, as noted, is disabled in this mode for safety.. We may be able to add back manual garbage collection in the future so I labeled this as "enhancement" for now.

filiptibell avatar Jul 29 '25 10:07 filiptibell

Yeah I'm not quite sure what to do about this. Lune enables sandboxed Luau for performance reasons, and manual garbage collection, as noted, is disabled in this mode for safety.. We may be able to add back manual garbage collection in the future so I labeled this as "enhancement" for now.

yes please do add this is great feature + unrelated but ServiceProvider.ServiceAdded && ServiceProvider.ServiceRemoving isnt implemented,

vaxtalastus-web avatar Nov 07 '25 07:11 vaxtalastus-web

Yeah I'm not quite sure what to do about this. Lune enables sandboxed Luau for performance reasons, and manual garbage collection, as noted, is disabled in this mode for safety.. We may be able to add back manual garbage collection in the future so I labeled this as "enhancement" for now.

so yeah a function like: getgc (ironically the same name as a function name for a roblox cheats function | but its a good name still 😭) that returns a table with the entire gc | also add replacegc which replaces something in gc with value, because replacing v it wont do anything lol

vaxtalastus-web avatar Nov 07 '25 07:11 vaxtalastus-web

I would say one of the strengths of lune is its flexibility (with the upcoming ffi support). I'd like to see a few options being brought back.

An approach might be an optional "unsafe" flag for power users who know exactly what they're doing, allowing options like "step" and "collect" but excluding ones like "stop" or "restart" (maybe?). Or as you've suggested an API could be introduced to keep things way safer. I'm not exactly sure.

Again, with the upcoming ffi support, having more granular GC control would definitely improve flexibility over memory.

no add a collectgarbage("unsafe") flag that will enable all options

vaxtalastus-web avatar Nov 10 '25 03:11 vaxtalastus-web

Yeah I'm not quite sure what to do about this. Lune enables sandboxed Luau for performance reasons, and manual garbage collection, as noted, is disabled in this mode for safety.. We may be able to add back manual garbage collection in the future so I labeled this as "enhancement" for now.

deprecated but for powerusers it should still be avaliable

vaxtalastus-web avatar Nov 10 '25 03:11 vaxtalastus-web

also add a collectgarbage("get") to return the entire gc and a collectgarbage("replace", toReplace, ReplaceWith)

vaxtalastus-web avatar Nov 10 '25 03:11 vaxtalastus-web