Jump to content

Module:Sandbox/sameboat2

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sameboat (talk | contribs) at 04:27, 19 March 2013 (Created page with 'my_object = {}; -- defines a factorial function my_object.hello = function fact (n) if n == 0 then return 1 else return n * fact(...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Script error: Lua error at line 3: '(' expected near 'fact'.

my_object = {};
-- defines a factorial function
    my_object.hello = function fact (n)
      if n == 0 then
        return 1
      else
        return n * fact(n-1)
      end
    end
    
    my_object.hello2 = function( frame )
    return ("enter a number:")
    a = io.read("*number")        -- read a number
end
    my_object.hello3 = function( frame )
    print(fact(a))
    end
    
return my_object