Hi!
I have seen Lua 5.2+ code which uses the following approach
to distinguish C functions from Lua functions:
local function is_C_function(func)
local x = coroutine.create(func)
debug.sethook(x, function() x=debug.getlocal(2,2) coroutine.yield() end, "c")
coroutine.resume(x)
return not x
end
print(is_C_function(print)) --> true
print(is_C_function(function() end)) --> false
Why does this code work?