PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/lua/functor/runme.lua

#
Lua | 24 lines | 14 code | 4 blank | 6 comment | 2 complexity | c1eb99878fb3137f1d9c2cdd5d025147 MD5 | raw file
 1-- Operator overloading example
 2---- importing ----
 3if string.sub(_VERSION,1,7)=='Lua 5.0' then
 4	-- lua5.0 doesnt have a nice way to do this
 5	lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
 6	assert(lib)()
 7else
 8	-- lua 5.1 does
 9	require('example')
10end
11
12a = example.intSum(0)
13b = example.doubleSum(100.0)
14
15-- Use the objects.  They should be callable just like a normal
16-- lua function.
17
18for i=0,100 do
19    a(i)                -- Note: function call
20    b(math.sqrt(i))     -- Note: function call
21end 
22print("int sum 0..100 is",a:result(),"(expected 5050)")
23print("double sum 0..100 is",b:result(),"(expected ~771.46)")
24