MCQs on Customizing Lua Behavior | Lua

1. Customizing the Lua Interpreter

  1. Which function is used to modify the behavior of Lua’s garbage collector?
    • A) collectgarbage()
    • B) setgarbage()
    • C) gcmodify()
    • D) garbagecontrol()
  2. In Lua, what is the purpose of the load() function?
    • A) Load external libraries
    • B) Compile Lua code from a string
    • C) Execute a file
    • D) Load a Lua module
  3. What is the primary purpose of modifying the Lua interpreter?
    • A) Increase speed
    • B) Debug Lua scripts
    • C) Customize runtime behavior
    • D) Modify the Lua syntax
  4. Which of the following can be modified in the Lua interpreter to change Lua’s execution environment?
    • A) Global environment
    • B) Error handling
    • C) Garbage collection
    • D) All of the above
  5. What is the effect of setting package.loaded to a custom value in Lua?
    • A) It changes the location of Lua libraries
    • B) It affects the module loading behavior
    • C) It deletes loaded modules
    • D) It prevents the execution of external files

2. Using Hooks with the Debug Library

  1. Which function in the debug library sets a hook for Lua’s execution?
    • A) debug.sethook()
    • B) debug.settrace()
    • C) debug.setcallback()
    • D) debug.execute()
  2. What does the debug.sethook() function allow you to do?
    • A) Set breakpoints during execution
    • B) Set the number of iterations for a loop
    • C) Monitor function calls, returns, and line changes
    • D) Prevent the execution of functions
  3. What are the four hook types available in Lua’s debug library?
    • A) Line, call, return, and closure
    • B) Line, call, return, and count
    • C) Call, exit, return, and callback
    • D) Break, return, entry, and exit
  4. How does Lua’s debug library help in debugging scripts?
    • A) By logging execution flow and state
    • B) By modifying Lua’s core behavior
    • C) By allowing execution without modification
    • D) By halting the script automatically
  5. Which of the following is true when using the debug library’s hook functionality?
    • A) Hooks are automatically cleared after execution
    • B) Hooks run before the Lua interpreter is modified
    • C) Hooks monitor program flow but cannot stop execution
    • D) Hooks do not provide information on function arguments

3. Lua’s Sandboxing for Secure Execution

  1. What is Lua sandboxing primarily used for?
    • A) Improving performance in high-load systems
    • B) Isolating potentially dangerous code execution
    • C) Enabling multithreading in Lua
    • D) Securing Lua syntax errors
  2. Which function is commonly used to prevent access to dangerous operations in Lua?
    • A) os.exit()
    • B) debug.getupvalue()
    • C) loadstring()
    • D) setfenv()
  3. How does Lua’s setfenv() function contribute to sandboxing?
    • A) Modifies the global environment for a function
    • B) Disables access to specific modules
    • C) Encrypts Lua bytecode
    • D) Optimizes the performance of Lua code
  4. In a Lua sandbox, which of the following is typically restricted?
    • A) Reading from external files
    • B) Modifying global variables
    • C) Accessing the network
    • D) All of the above
  5. Which Lua function allows you to safely execute a string of code within a controlled environment?
    • A) load()
    • B) dofile()
    • C) require()
    • D) loadstring()
  6. What is the purpose of Lua’s package.loaded in a sandbox environment?
    • A) Prevent libraries from being loaded into memory
    • B) Manage external library installation
    • C) Track function calls
    • D) Secure user input
  7. Which of the following is NOT a common use case for sandboxing Lua?
    • A) Running untrusted code safely
    • B) Allowing code to access global resources
    • C) Isolating execution from the host environment
    • D) Preventing system resource exhaustion
  8. Which of the following best describes the loadfile() function in a sandboxed environment?
    • A) It loads Lua code from a file, but restricts access to sensitive system resources
    • B) It executes Lua code directly from a string
    • C) It imports an external module
    • D) It is a deprecated function in sandboxing
  9. In a Lua sandbox, which of the following would you likely disable for security reasons?
    • A) io.read()
    • B) os.execute()
    • C) debug.traceback()
    • D) All of the above
  10. Which approach is commonly used to prevent Lua code from accessing certain libraries in a sandbox?
    • A) Modifying the require function
    • B) Adding new global variables
    • C) Restricting access to table methods
    • D) Blocking loadstring()

General Lua Customization

  1. Which command allows you to print the current environment of a Lua function?
    • A) debug.getinfo()
    • B) debug.printenv()
    • C) getfenv()
    • D) env.print()
  2. What is the primary benefit of using Lua’s debug.getlocal() function?
    • A) Returns local variables of a function
    • B) Returns global variables
    • C) Modifies local variables
    • D) Sets breakpoints in the function
  3. Which of the following can be done using Lua’s debug.traceback() function?
    • A) Trace the call stack of function calls
    • B) Output the Lua interpreter’s configuration
    • C) Print error messages
    • D) List loaded modules
  4. How can Lua’s setfenv() function be used to limit global access in a sandboxed environment?
    • A) By restricting the global environment of functions
    • B) By controlling the flow of function execution
    • C) By removing access to the io library
    • D) By disallowing the use of require()
  5. Which security feature in Lua restricts access to certain APIs or system functions in a sandboxed environment?
    • A) Lua’s garbage collector
    • B) Modified global environment
    • C) The debug library
    • D) User-defined functions
  6. What function would you use to safely execute a Lua function in a restricted environment?
    • A) load()
    • B) pcall()
    • C) dofile()
    • D) require()
  7. Which Lua function is typically used to simulate a “safe” environment during the execution of untrusted code?
    • A) setmetatable()
    • B) loadstring()
    • C) setfenv()
    • D) debug.sethook()
  8. Which of the following is an important consideration when creating a Lua sandbox?
    • A) Ensuring the environment is fully isolated from the system
    • B) Allowing direct access to system resources for flexibility
    • C) Ignoring the performance of sandboxed execution
    • D) Disabling debug information completely
  9. What would happen if you attempt to call the os library in a properly configured Lua sandbox?
    • A) It executes normally without restriction
    • B) The function will fail due to sandbox restrictions
    • C) It will automatically optimize execution
    • D) It will request permission from the user
  10. Which Lua function allows you to manage and alter the global environment in a script?
    • A) setfenv()
    • B) getfenv()
    • C) load()
    • D) dofile()

Answer Table

QnoAnswer (Option with the text)
1A) collectgarbage()
2B) Compile Lua code from a string
3C) Customize runtime behavior
4D) All of the above
5B) It affects the module loading behavior
6A) debug.sethook()
7C) Monitor function calls, returns, and line changes
8B) Line, call, return, and count
9A) By logging execution flow and state
10C) Hooks do not provide information on function arguments
11B) Isolating potentially dangerous code execution
12D) setfenv()
13A) Modifies the global environment for a function
14D) All of the above
15A) load()
16A) Prevent libraries from being loaded into memory
17B) Allowing code to access global resources
18A) It loads Lua code from a file, but restricts access to sensitive system resources
19D) All of the above
20A) Modifying the require function
21C) getfenv()
22A) Returns local variables of a function
23A) Trace the call stack of function calls
24A) By restricting the global environment of functions
25B) Modified global environment
26B) pcall()
27C) setfenv()
28A) Ensuring the environment is fully isolated from the system
29B) The function will fail due to sandbox restrictions
30A) setfenv()

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top