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

# · Lua · 24 lines · 14 code · 4 blank · 6 comment · 3 complexity · c1eb99878fb3137f1d9c2cdd5d025147 MD5 · raw file

  1. -- Operator overloading example
  2. ---- importing ----
  3. if 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)()
  7. else
  8. -- lua 5.1 does
  9. require('example')
  10. end
  11. a = example.intSum(0)
  12. b = example.doubleSum(100.0)
  13. -- Use the objects. They should be callable just like a normal
  14. -- lua function.
  15. for i=0,100 do
  16. a(i) -- Note: function call
  17. b(math.sqrt(i)) -- Note: function call
  18. end
  19. print("int sum 0..100 is",a:result(),"(expected 5050)")
  20. print("double sum 0..100 is",b:result(),"(expected ~771.46)")