lua學習(一)

來源:互聯網
上載者:User

全是傻瓜式操作:
Windows: 
把etc目錄下的luavs.bat 拷到lua的解壓根目錄下直接運行, 就ok了!

Linux:
$make linux && make install 標準的linux安裝

luaEdit有一個作者沒有解決的bug, 恰好被我碰到,要反省一下自己的rp了!  還是轉到linux下用vi吧
一個有趣的例子, 就是用lua在輸出一條正弦曲線
$mkdir aol_study
$cd aol_study
$touch plot.lua
$vi plot.lua

function eraseTerminal()
 io.write("/27[2J")
end

-- writes an `*' at column `x' , row `y'
function mark (x,y)
 io.write(string.format("/27[%d;%dH*", y, x))
end

-- 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)
 end
 io.read() -- wait before spoiling the screen
end

儲存之後, 鍵入命令:
$lua
進入lua模式
>dofile "plot.lua"
>plot(function (x) return math.sin(x*2*math.pi) end)

哈哈,就輸出了一條由*號組成的正弦曲線,好像回到了以前學習basic畫圖的時候

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.