当前位置:网站首页>Lua record
Lua record
2022-06-12 18:53:00 【It Yunqing】
-- https://github.com/aerospike/aerospike-lua-core/blob/master/src/as.lua
-- https://github.com/aerospike/aerospike-client-java
-- Create a new Map my merging two maps.
-- The function `f` is a function used to merge the value of matching keys.
--
function map.merge(m1,m2,f)
local mm = {}
for k,v in map.pairs(m1) do
mm[k] = v
end
for k,v in map.pairs(m2) do
mm[k] = (mm[k] and f and type(f) == 'function' and f(m1[k],m2[k])) or v
end
return map(mm, map.size(m1) + map.size(m2))
end
-- One merge table Function of
function table.merge(src,des)
for k,v in pairs(src) do
des[k] = v
end
return des
end
t1 = {a=1,b=2,c=3}
t2 = {a=22,b=55,f=12,g=12}
-- Traverse table
for k,v in pairs(table.merge(t1,t2)) do
print(k.."="..v)
end
The result is :
a=1
c=3
b=2
g=12
f=12
-- ------------
-- Function transfer
myPrint = function(param)
print(" Print function :",param)
end
myPrint(22)
function add(num1,num2,printFunction)
result = num1 + num2
printFunction(result)
end
add(22,77,myPrint)
-- add Function passes in a print function , Names can be different
function add(a,b,myPrint1)
local c = a + b
myPrint1(c)
end
-- Define a print function
function myPrint(param)
print(' The result is ='..param)
end
add(11,22,myPrint)
print("-----------")
-- Function returns multiple values
function maxNum(a)
local mi = 1
local m = a[mi]
for i,v in pairs(a) do
if v > m then
mi = i
m = v
end
end
return m,mi
end
print(maxNum({8,10,23,12,5}))
print("-----------")
-- if elseif
c = 200
if(c == 10)
then
print("c==10")
elseif (c==20)
then
print("c==20")
elseif (c==30)
then
print("c==40")
else
print(" incognizance ")
end
print("-----------")
-- goto
for i=1,3 do
if i <= 2 then
print(i,"yes,continue")
goto label2
end
::label2:: print(" stay goto in ")
print(i," End the inner layer ")
end
-- break
print("-----------")
a = 10
while(a<20)
do
print(a)
a = a+1
if (a > 15)
then
break;
end
end
-- Paradigms for loop
tab2 = {"one",2,"three",4}
for i,v in ipairs(tab2) do
print(i,v)
end
for i,v in pairs(tab2) do -- pair and ipair
print(i,v)
end
for i,v in pairs(tab2) do
print(v)
end
print("-----------")
-- The number for loop
function f(x)
print(x)
return 2*x
end
for i = 1,f(3) do -- The default step size is 1,f(x) I can only calculate once
print(i)
end
print("-----------")
for i = 1,f(3),2 do -- The specified step size is 2
print(i)
end
print("-----------")
a=3
while(a ~= 0)
do
print("a="..a)
a = a -1
end
print("-----------")
-- Local variables and global variables
a=14;
function test1()
a = 18
print(" Inside a="..a)
local b = 22
end
test1()
print(" external a="..a)
print(b)
print("-----------")
-- assignment
a,b,c = 11,22,"good"
print(a)
print(b)
print(c)
a,b,c = c,b,a -- Exchange variables
print(a)
print(b)
print(c)
-- boolean Type has only two optional values :true( really ) and false( false ),
-- Lua hold false and nil See as false, Everything else true, Numbers 0 It's also true:
-- type
print(type(x))
print(type(x)==nil)
print(type(x)=="nil")
print(type(type(x))) -- type(x) The result is a string nil
-- table Use
tab1= {key1="val1",key2="val2","val3"}
for k,v in pairs(tab1) do
print ("k="..k..",v="..v)
end -- ???
print("-----------")
tab2 = { name="zhangsan",age=12}
for k,v in pairs(tab2) do
print ("k="..k..",v="..v)
end
print("-----------")
tab2.name=nil -- It is equivalent to deleting name
for k,v in pairs(tab2) do
print ("k="..k..",v="..v)
end
print("-----------")
-- Basics
print(b);
b=123;
print(b);
print(type(b));
b="23343";
print(b);
print(type(b));
-- aaa
-- [[fff --]]
b=nil;
print(b);
print(type(b));边栏推荐
- 用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性
- How to break the black screen after cleaning the dust and applying silicone grease on the laptop?
- Leetcode 474. 一和零
- Observe the page of the website
- Review of MySQL (IX): index
- Why my order by create_ Time ASC becomes order by ASC
- Wireshark basic commands
- 实验10 Bezier曲线生成-实验提高-交互式生成B样条曲线
- Shenzhen has been shut down for 7 days since March 14. Home office experience | community essay solicitation
- CVPR 2022 oral Dalian Institute of technology proposed SCI: a fast and powerful low light image enhancement method
猜你喜欢

kali2022如何安装w3af

Review of MySQL (V): Joint table query and sub query

Implementing reflexive ACL in Cisco packet tracker

The Bean Validation API is on the classpath but no implementation could be found

Research Report on the overall scale, major manufacturers, major regions, products and applications of Electric Screwdrivers in the global market in 2022

uniapp使用阿里图标
![[0008] unordered list](/img/16/7525d963e68757558dd55ff4d1a23a.png)
[0008] unordered list

国内如何下载ProxyStrike

leetcode:6095. 强密码检验器 II【简单模拟 + 不符合直接False】

什么是网络代理
随机推荐
Wireshark basic commands
leetcode:98. Count the number of subarrays whose score is less than k [double pointers + number of calculated subsets + de duplication]
Leetcode 416. Split equal sum subset
CEPH deploy offline deployment of CEPH cluster and error reporting FAQ
232-CH579M学习开发-以太网例程-TCP服务器(项目应用封装,局域网或广域网测试)
Leetcode topic [string] - Sword pointing offer 05- replace spaces
leetcode:5289. 公平分发饼干【看数据范围 + dfs剪枝】
On how to make digital transformation after the loan of large policy banks- Yixinhuachen
Kali2022 how to install w3af
RHCA回忆录---CL280介绍
leetcode:98. 统计得分小于 K 的子数组数目【双指针 + 计算子集个数 + 去重】
Review of MySQL (10): three paradigms of database
Daily blog - micro service permission 12 matters
leetcode:5270. 网格中的最小路径代价【简单层次dp】
Review of MySQL (VII): use of tables
Observe the page of the website
Delivery lead time lightweight estimation practice - Notes
Operational research optimization of meituan intelligent distribution system - Notes
Leetcode 494. Objectives and
MySQL数据库实验一 数据定义