github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/lib/debuglib/lua/getinfo.lua (about) 1 local function aFunction(...) 2 local i = debug.getinfo(...) 3 if not i then 4 print("none") 5 else 6 print(i.name, i.currentline, i.source) 7 end 8 end 9 10 local function foo(...) 11 aFunction(...) 12 return 1 -- avoid TCO 13 end 14 15 foo(1) 16 --> =aFunction 2 luatest 17 18 foo(2) 19 --> =foo 11 luatest 20 21 foo(0) 22 --> =getinfo 0 [Go] 23 24 foo(10) 25 --> =none 26 27 print(pcall(debug.getinfo)) 28 --> ~false\t.*: bad argument #1.* 29 30 foo(foo) 31 --> =foo -1 luatest 32 33 -- Get a thread 34 function cofoo() 35 cobar() 36 end 37 38 function cobar() 39 coroutine.yield(1) 40 end 41 42 co = coroutine.create(cofoo) 43 print(coroutine.resume(co)) 44 --> =true 1 45 46 -- Check getinfo in the thread 47 48 print(pcall(foo, co)) 49 --> ~false\t.*: missing argument: f.* 50 51 foo(co, 1) 52 --> =cobar 39 luatest 53 54 foo(co, 2) 55 --> =cofoo 35 luatest 56 57 print(pcall(foo, co, true)) 58 --> ~false\t.* 59 60 foo(co, 1.0) 61 --> =cobar 39 luatest 62 63 print(pcall(foo, co, 1.5)) 64 --> ~false\t.*