load()import()require()module()module()?
module("module_name")module = {}module("module_name", {})module = "module_name"require() function do in Lua?
package.pathpackage.loadedpackage.modulepackage.preloadpackage.path define in Lua?
mymodule using require()?
require("mymodule")import("mymodule")load("mymodule")use("mymodule")package.loaded contain in Lua?
require() on an already loaded module?
nil.true.module table.export() function.require() to call it.global keyword.module = {}module("mymodule", {})module("mymodule")module = function() endpackage.preload in Lua?package.pathimport() functionrequire()package.loadedpackage.path = package.path .. ";/usr/local/lua/?.lua"?require() return after loading a module?package.loaded["module_name"] check in Lua?require() function.package.get() function.module() function in Lua?require("mymodule") return when the module mymodule contains a table with a function foo()?nil.foo() function.foo is a field.foo() function immediately.package.path in Lua?require() function handle circular dependencies?package.searchpackage.pathrequire()import()require().alias()module()require()load()package.loaded.require() twice.load() with a custom check.module() with a conditional.package.loaded.| Qno | Answer |
|---|---|
| 1 | A) To organize code into reusable functions |
| 2 | C) require() |
| 3 | C) module("module_name", {}) |
| 4 | A) It loads a module and executes it if not already loaded. |
| 5 | C) package.module |
| 6 | B) The paths for loading modules |
| 7 | A) require("mymodule") |
| 8 | A) A table of all loaded modules |
| 9 | C) It skips loading the module and returns true. |
| 10 | A) Assign it to the module table. |
| 11 | B) module("mymodule", {}) |
| 12 | A) It defines custom modules that are loaded before the default package system. |
| 13 | A) By modifying package.path |
| 14 | A) It adds a new search path for Lua modules. |
| 15 | A) A table with module functions |
| 16 | A) If the module is loaded |
| 17 | B) A module must be a table. |
| 18 | D) By accessing it through the module table. |
| 19 | A) It defines a new module and optionally initializes it. |
| 20 | C) It returns the module table, where foo is a field. |
| 21 | B) It will change the default paths for module searching. |
| 22 | C) It handles them automatically by reusing previously loaded modules. |
| 23 | A) It gets loaded into memory. |
| 24 | B) Modify package.path |
| 25 | D) Modules must always be explicitly reloaded. |
| 26 | B) Organizing reusable code in separate files. |
| 27 | A) Define a table that will hold the module’s functions. |
| 28 | B) module() |
| 29 | A) Use package.loaded. |
| 30 | B) It returns the module from package.loaded. |