Lua (moon) Programming.

MoreCoffee

Well-known member
Valued Contributor
Joined
Jul 13, 2015
Messages
19,194
Location
Western Australia
Gender
Male
Religious Affiliation
Catholic
Political Affiliation
Moderate
Marital Status
Single
Acceptance of the Trinity & Nicene Creed
Yes
I recently discovered Lua. It was created by the members of the Computer Graphics Technology Group (Tecgraf) at the Pontifical Catholic University of Rio de Janeiro, in Brazil. Being a Catholic I feel almost duty bound to give it a go.

:smirk:
 

MoreCoffee

Well-known member
Valued Contributor
Joined
Jul 13, 2015
Messages
19,194
Location
Western Australia
Gender
Male
Religious Affiliation
Catholic
Political Affiliation
Moderate
Marital Status
Single
Acceptance of the Trinity & Nicene Creed
Yes
Lua programmaing

1 – Getting Started

To keep with the tradition, our first program in Lua just prints "Hello World":

print("Hello World")
If you are using the stand-alone Lua interpreter, all you have to do to run your first program is to call the interpreter (usually named lua) with the name of the text file that contains your program. For instance, if you write the above program in a file hello.lua, the following command should run it:
prompt> lua hello.lua
As a slightly more complex example, the following program defines a function to compute the factorial of a given number, asks the user for a number, and prints its factorial:

Code:
    -- defines a factorial function
    function fact (n)
      if n == 0 then
        return 1
      else
        return n * fact(n-1)
      end
    end
    
    print("enter a number:")
    a = io.read("*number")        -- read a number
    print(fact(a))
If you are using Lua embedded in an application, such as CGILua or IUPLua, you may need to refer to the application manual (or to a "local guru") to learn how to run your programs. Nevertheless, Lua is still the same language; most things that we will see here are valid regardless of how you are using Lua. For a start, we recommend that you use the stand-alone interpreter (that is, the lua executable) to run your first examples and experiments.
 

Rens

Well-known member
Joined
Sep 11, 2015
Messages
4,754
Age
54
Gender
Female
Religious Affiliation
Pentecostal
Political Affiliation
Conservative
Marital Status
In Relationship
Oh I thought you were gonna make a trip to the moon.
 

MoreCoffee

Well-known member
Valued Contributor
Joined
Jul 13, 2015
Messages
19,194
Location
Western Australia
Gender
Male
Religious Affiliation
Catholic
Political Affiliation
Moderate
Marital Status
Single
Acceptance of the Trinity & Nicene Creed
Yes
Oh I thought you were gonna make a trip to the moon.

No, not unless there's some sort of five star resort hotel there :)
 

psalms 91

Well-known member
Moderator
Valued Contributor
Supporting Member
Joined
Jun 22, 2015
Messages
15,282
Age
75
Location
Pa
Gender
Male
Religious Affiliation
Charismatic
Political Affiliation
Conservative
Marital Status
Married
Or the ocean
 

MoreCoffee

Well-known member
Valued Contributor
Joined
Jul 13, 2015
Messages
19,194
Location
Western Australia
Gender
Male
Religious Affiliation
Catholic
Political Affiliation
Moderate
Marital Status
Single
Acceptance of the Trinity & Nicene Creed
Yes
I recently compiled the Lua programming language, its interpreter, and its compiler using LCC in a desktop C environment called Pelles C IDE :)
 
Top Bottom