Skip to content

Instantly share code, notes, and snippets.

@rozer007
Last active December 4, 2021 09:30
Show Gist options
  • Save rozer007/c7698820322b98a1ea5e6d1d726ca492 to your computer and use it in GitHub Desktop.
Save rozer007/c7698820322b98a1ea5e6d1d726ca492 to your computer and use it in GitHub Desktop.
Metatables in Lua
Q1. What are metatable?
ans: Metatable are table that are used to modify the behaviour of a table.
Q2. How can we attach a metatable for particular table?
ans: In lua , we have setmetatable function which will attach a metatables for a table.
Q3. How can we use a metamethod defined in the module?
ans: we can just use the particular operator to perform the operation of the metamethod define in the metatables.
Q1.Correct way to set a metatable for a table?
a) settable(table,metatable)
b) setmetatable(table,metatable)
a) table.settable(metatable)
b) setmetatable(metatable,table)
ans: b)
Q2.which of the following is not a metamethod :
a)__eq
b)__le
c)__ge
d)__gg
ans: d)
Q3.What is the function of __unm method?
a) + unary operator
b) - unary operator
c) .. concatenate operator
d) none of the above
ans: b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment