LUA Flashcards

(15 cards)

1
Q

Lua 5.0 introduced a major performance breakthrough by switching from a standard stack-based virtual machine to what specific type of Virtual Machine?

A

Register-based Virtual Machine (or Register-based VM)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the specific name of the mechanism (a table) used to define the behavior of other tables, enabling operator overloading and object-oriented inheritance?

A

Metatable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Lua was developed at PUC-Rio inside which specific Computer Graphics Technology Group?

A

Tecgraf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What specific compiler feature allows a Lua function to call itself indefinitely without causing a “Stack Overflow” error, provided the call is the final action?

A

Proper Tail Calls (or Tail Call Optimization / TCO)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

By default, variables in Lua are global. What keyword must be used to explicitly declare a variable as lexically scoped to the current block?

A

Local

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In Lua’s boolean evaluation, the number 0 and empty strings “” are considered false.
True or False

A

False (In Lua, 0 and “” are considered true. Only nil and false are false).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Lua strings are immutable, meaning once a string is created, it cannot be changed in place; a new string must be created for any modification.

True or False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Lua arrays (tables with integer keys) conventionally start at index 0, similar to C, Java, and Python.
True or False

A

False (Lua arrays conventionally start at index 1).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Lua supports multithreading by using native Operating System threads (like Pthreads or Windows threads) to execute code in parallel on multiple CPU cores.
True or False

A

False (Lua is single-threaded; it uses Coroutines for cooperative multitasking, not OS threads).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Variables in Lua are dynamically typed, meaning the variable itself has no type, only the value assigned to it has a type
True or False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Boolean Logic & Short-Circuiting What is the output of the following code?

local result = nil or "Moon"
print(result)

LUA

A

“Moon” (The or operator returns the first truthy value. Since nil is false, it returns the second value).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Table Indexing Lua tables are sparse. What is the output of this code?

local t = { "A", "B", "C" }
print(t[0])

LUA

A

nil (Lua is 1-based. Index 0 is not automatically created, so it is just an empty key returning nil).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Variable Scope (Shadowing) What value is printed at the end?

local x = 10
do
local x = 20
x = x + 5
end
print(x)

LUA

A

10 (The x inside the do…end block is a separate local variable that shadows the outer x. The outer x is untouched).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Data Type Coercion Lua automatically converts strings to numbers in arithmetic operations. What is the result?

print(“10”+5)

LUA

A

15 (Lua coerces strings to numbers when using arithmetic operators like +. Use .. for concatenation).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Control Flow (Loops) How many times will the string “Lua” be printed?

for i = 1, 3 do
print("Lua")
End

LUA

A

3 times (The for loop in Lua is inclusive of both the start and end points: 1, 2, and 3).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly