First five chapters of lua study

Basic concepts

-l parameter

-- a,b All documents need to be placed in lua.exe File directory
-- a.lua file
x = 5
-- b.lua file
-- Input in interactive mode
lua -la -lb 
-- Run first a.lua ,Rerun b.lua
-- The result is 5


Linked list

list = nil
local rows = 1
list_next = nil
for line in io.lines("D://LuaStudy//CodeTest//day3 / / linked list data. txt") do
	list = {next = list, value = line}
	--print("Current lines of file:" .. rows)
	print("The number of rows in the file:" .. rows)
	--print("Value of the current line of the file:" .. list.value)
	print("Current line value of the file:" .. list.value)
	-- Because for the first time list by nil,So it needs to be converted
	--print("The value The value is saved to a value named Of table , which is referenced as:" .. tostring( .. "\n")
	print("Save the value of the file's row to a table named, which is referred to as:" .. tostring( .. "\n")
	rows = rows + 1
	list_next =

local l = list

--print("Because after reading the file data circularly, value The value of the last line of the file is saved, so l.value Is the following value ↓ ")
print("Because after looping through the file data, value stores the value of the last line of the file, so l.value is the following value ")
print(l.value .. "\n")
print(tostring(list_next)) -- And the last list Reserved table Consistent references
print(list_next == -- true
--print("At this time, the current table Held by next Reference changed to ,That is to say, there is a previous one list Of table")
print("current table retains next quotes change to ,Save the last one list of table")
print( .. "\n")
print( .. "\n")
print( .. "\n")
while l do
	l =


  1. Whether it is assignment or circular assignment, its operation on expression or value is evaluated at one time before its assignment
    1. When assigning a value, the value on the right will be calculated first
    2. When looping, three expressions are evaluated before the loop
  2. It's easy to generate a table that reverses the original index through an iterator
    1. It is to exchange the value of the original table with the index
    2. v gets the value of the original table as the index of the new table
    3. k gets the index of the original table to the value and assigns it to the new table as its value


  1. unpack is used to deconstruct a table and get all the elements in a table. It is very useful to overload the parameter list

    1. Just take the deconstructed element as the parameter of a function
    2. For example: string.find(unpack({"bilibili", "bi"}))
  2. Named parameter can specify a function parameter as table, and pass this table to name the parameter in the period when calling

function rename (arg)
    return os.rename(arg.old,
rename{old = "D:\\LuaStudy\\CodeTest\\4-function\\temp.lua", new = "D:\\LuaStudy\\CodeTest\\4-function\\temp1.lua"}

Tags: Programming

Posted on Mon, 20 Apr 2020 09:46:53 -0700 by phil88