A set environment or a parameter for API, which do you prefer?

I’m designing a API for my plugin where you return a function from a ModuleScript, but I’m wondering how I should pass over the api.

Should I either setfenv the returned function with the API, or pass it as a parameter?

Example

Setfenv:

return function()
    api.print("yo")
end

Parameter:

return function(api)
    api.print("yo")
end

It’s not exactly a huge difference, but I want to make it as simple as possible to use.
If you have a different idea to these two opposed then I’d like to hear!

I’ll hold a poll:

  • Parameter
  • Set environment
  • Other (please reply!)

0 voters

Thanks!

Setting the environment disables some of Luau’s optimizations. I would stay away from doing so if it’s at all possible.

4 Likes