How do I find an `f` that makes `pcall(pcall, f)` return `false` in Lua? -


i'm using lua 5.3.

reading 'programming in lua 3rd edition', came exercise asking me find f makes pcall(pcall, f) return false. think equivalent make pcall(f) raise error. seems use pcall on won't that. example, let f = nil , nothing bad happens.

however, found on internet letting f = (function() end)() trick. don't understand why. here f return value (which nil) of function function() end right?

this not work

> f = (function() end)() > pcall(pcall, f) true    false   attempt call nil value 

but does:

> pcall(pcall,(function() end)()) false   bad argument #1 'pcall' (value expected) 

the difference (function() end)() returns no value, different returning nil. functions written in lua cannot make distinction pcall written in c , can make distinction. (other examples print , type.)

note behaves expected (equivalent first attempt):

> pcall(pcall,(function() return nil end)()) true    false   attempt call nil value 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -