Lua Learning (1)

Source: Internet
Author: User

All are silly operations:
Copy the luavs. BAT file in the etc directory to the root directory of Lua and run it directly!

$ Make Linux & make install standard Linux Installation

Luaedit has a bug that the author has not fixed. It happened to me. I need to reflect on my Rp! Go to Linux and use VI.
An interesting example is to use Lua to output a sine curve.
$ Mkdir aol_study
$ CD aol_study
$ Touch plot. Lua
$ VI plot. Lua

Function eraseterminal ()
Io. Write ("/27 [2j ")

-- Writes an '*' at column 'x', row 'y'
Function mark (x, y)
Io. Write (string. Format ("/27 [% d; % DH *", Y, x ))

-- Terminal size
Termsize = {W = 80, H = 24}

-- Plot a function
-- (Assume that domain and image are in the range [-1, 1])
Function plot (f)
Eraseterminal ()
For I = 1, termsize. w do
Local x = (I/termsize. W) * 2-1
Local y = (f (x) + 1)/2 * termsize. h
Mark (I, Y)
Io. Read () -- wait before spoiling the screen

After saving, enter the following command:
$ Lua
Enter Lua Mode
> Dofile "plot. Lua"
> Plot (function (x) return math. Sin (x * 2 * Math. Pi) end)

Haha, I output a sine curve composed of "*", as if I had returned to learning basic drawing before.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.