programing in lua first read 1 logical character, 2 returns the first value of the comparison, 3 Lua named arguments

I'm a beginner and I hope I can help correct me if I have any mistakes.

1————Logical character

a and b 
--[[If a is false, return a, otherwise return b]]
a or b 
--[[If a is true, return a, otherwise return b]]
x=x or v
--[ [When x is nil or false, assign the value of v to x]]
--[[equivalent to]]
if not x then
  x=v
  end
--[[a?b:c in C language is in lua Chinese use (a and b) or c]]
2——————Return the first value of the comparison
--[[I only want the second value returned by string.find, the typical method is to use Dummy variable (underscore)]]
local _,x=string.find(s,p)
--[[get x]]
--[[The other is an application of variable parameters]]
function select (n,...)
return(arg[n])
end
select(n,string.find(s,p))
--[[Get the nth return value, recommended]]
3—————— --Lua named arguments (functions with optional parameters implemented through table)
--[[functions that check parameters and set default parameter values]]
function func1(a)
    print("this is fakeone")
    --[[
    if func_os~=nil and func_3~=nil then
       func_os(func_3)
    end
    ]]
    _func1(a.x,a.func_os or nil,a.func_3 or nil)
 
end
--[[真正实现功能的函数]]
function _func1(x,func_os,func_3)
   print("this is correct one")
   if func_os~=nil and func_3~=nil then
       func_os(func_3)
   end
   print(type(func_os),type(func_3))
end
function func2(func_os)
  print("this is two")
  func_os()
end
function func3(...)
  print("this is three")
end
for line in io.lines() do
 if "1"==line then
   --[[func1({x=line,func_os=func2,func_3=func3})]]
   local a={x=line,func_os=func2,func_3=func3} 
   func1(a)
 else
  break
 end
end

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324700887&siteId=291194637