import source from 1.3.40
[external/swig.git] / Examples / lua / constants / runme.lua
1 -- file: example.lua
2
3 ---- importing ----
4 if string.sub(_VERSION,1,7)=='Lua 5.0' then
5         -- lua5.0 doesnt have a nice way to do this
6         lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
7         assert(lib)()
8 else
9         -- lua 5.1 does
10         require('example')
11 end
12
13 print("ICONST  = "..example.ICONST.." (should be 42)")
14 print("FCONST  = "..example.FCONST.." (should be 2.1828)")
15 print("CCONST  = "..example.CCONST.." (should be 'x')")
16 print("CCONST2 = "..example.CCONST2.." (this should be on a new line)")
17 print("SCONST  = "..example.SCONST.." (should be 'Hello World')")
18 print("SCONST2 = "..example.SCONST2.." (should be '\"Hello World\"')")
19 print("EXPR    = "..example.EXPR.." (should be 48.5484)")
20 print("iconst  = "..example.iconst.." (should be 37)")
21 print("fconst  = "..example.fconst.." (should be 3.14)")
22
23 -- helper to check that a fn failed
24 function checkfail(fn)
25         if pcall(fn)==true then
26                 print("that shouldn't happen, it worked")
27         else
28                 print("function failed as expected")
29         end
30 end
31
32 -- these should fail
33 -- example.EXTERN is a nil value, so concatentatin will make it fail
34 checkfail(function() print("EXTERN = "..example.EXTERN) end)
35 checkfail(function() print("FOO = "..example.FOO) end)