/tags/rel-1-3-26/SWIG/Examples/test-suite/lua/exception_order_runme.lua
Lua | 30 lines | 27 code | 1 blank | 2 comment | 0 complexity | 6545d3e61ba9c7ba32fbf471dad9b594 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1-- demo of lua swig capacilities (operator overloading) 2require("import") -- the import fn 3import("exception_order") -- import lib into global 4eo=exception_order --alias 5 6-- catching undefined variables 7setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end}) 8 9a = eo.A() 10 11function try1() 12 a:foo() 13end 14 15ok,ex=pcall(try1) 16assert(ok==false and swig_type(ex)==swig_type(eo.E1())) 17 18function try2() 19 a:bar() 20end 21ok,ex=pcall(try2) 22assert(ok==false and swig_type(ex)==swig_type(eo.E2())) 23 24function try3() 25 a:foobar() 26end 27ok,ex=pcall(try3) 28assert(ok==false and type(ex)=="string") 29-- the SWIG_exception is just an error string 30