kingstoncompsci
kingstoncompsci

Reputation: 163

Does lua perform "require" during compile time?

When "require" is called in Lua, is the file simply copied into the current file (similar to include "*.h" in C) or is it done by the VM during runtime?

Upvotes: 1

Views: 442

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474326

require is not a part of Lua as a language. It's just a function call in Lua's standard library. And all function calls execute at runtime.

After all, require doesn't load files; the package system's loaders do. Those loaders can be changed at runtime, and all require calls after such changes will reflect them. Some loaders are based on environment variables, whose values can change between executions of a Lua program. Each execution of the script, whether pre-compiled or not, will see these changes.

Upvotes: 1

Related Questions