/trunk/Examples/lua/constants/runme.lua
Lua | 35 lines | 27 code | 3 blank | 5 comment | 2 complexity | 54e2b21330c54fb534dba1a74785489b MD5 | raw file
1-- file: example.lua 2 3---- importing ---- 4if 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)() 8else 9 -- lua 5.1 does 10 require('example') 11end 12 13print("ICONST = "..example.ICONST.." (should be 42)") 14print("FCONST = "..example.FCONST.." (should be 2.1828)") 15print("CCONST = "..example.CCONST.." (should be 'x')") 16print("CCONST2 = "..example.CCONST2.." (this should be on a new line)") 17print("SCONST = "..example.SCONST.." (should be 'Hello World')") 18print("SCONST2 = "..example.SCONST2.." (should be '\"Hello World\"')") 19print("EXPR = "..example.EXPR.." (should be 48.5484)") 20print("iconst = "..example.iconst.." (should be 37)") 21print("fconst = "..example.fconst.." (should be 3.14)") 22 23-- helper to check that a fn failed 24function 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 30end 31 32-- these should fail 33-- example.EXTERN is a nil value, so concatentatin will make it fail 34checkfail(function() print("EXTERN = "..example.EXTERN) end) 35checkfail(function() print("FOO = "..example.FOO) end)