PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/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)
  2. require("import") -- the import fn
  3. import("exception_order") -- import lib into global
  4. eo=exception_order --alias
  5. -- catching undefined variables
  6. setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
  7. a = eo.A()
  8. function try1()
  9. a:foo()
  10. end
  11. ok,ex=pcall(try1)
  12. assert(ok==false and swig_type(ex)==swig_type(eo.E1()))
  13. function try2()
  14. a:bar()
  15. end
  16. ok,ex=pcall(try2)
  17. assert(ok==false and swig_type(ex)==swig_type(eo.E2()))
  18. function try3()
  19. a:foobar()
  20. end
  21. ok,ex=pcall(try3)
  22. assert(ok==false and type(ex)=="string")
  23. -- the SWIG_exception is just an error string