I usually use something like local s = [[ local logger, RLC = ... return function (cpu) -- some code end ]] local f = assert(load(s, s, "t", {}))(logger, RLC) for this.