Lua學習筆記9:多檔案,lua學習筆記9

來源:互聯網
上載者:User

Lua學習筆記9:多檔案,lua學習筆記9

一 終端中執行多個檔案:-l

加入在檔案一中定義了一個變數,在另一檔案中輸出這個變數,代碼如下:

--file1.luanum = 100
--file2.luaprint(num)


終端輸入(注意:不是lua命令列):

lua -lfile1 -lfile2

注意:不要加上檔案尾碼名.lua

二 命令列中負載檔案

--lib.luafunction norm(x, y)    local n2 = x^2 + y^2    return math.sqrt(n2)endfunction twice(x)    return 2 * xend

在lua命令列中依次輸入:

dofile("lib.lua")n = norm(2.1, 1.4)print(twice(n))






LUA怎可以同時引入多個檔案內的參數

假設a.lua和b.lua檔案在同一個目錄內。

b.lua檔案的內容:
function func()
print("Hello world!")
end

a.lua檔案的內容:
require "b"
func()

這樣就可以調用b.lua檔案的函數了。
 
lua給一個完成的讀檔案與寫檔案的代碼另外還有沒有LUA比較實用的代碼例子給的越多越好,給分越多

1.txt檔案
------------------------
12345
67890
------------------------
read.lua讀
-----------------------
local file = io.open("1.txt")
for l in file:lines() do
print(l)
end
file:close()
----------------------
write.lua 寫
----------------------
local file = io.open("2.txt","w")
file:write("12345")
file:close()
---------------------------------------
ps:網友都是抱著幫大家回答問題 互相協助的目的才來回答問題的 而不是圖你這點分
再就是 連初始分都沒的題目 也不會有人指望你給多少分的
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.