当前位置:网站首页>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));边栏推荐
- Have a meal, dry pot, fat intestines + palm treasure!
- Uniapp uses the Ali Icon
- Design of smart home control system (onenet) based on stm32_ two thousand and twenty-two
- The solution of BiliBili video list name too long and incomplete display
- Istio 1.14 发布
- kali通过iptables实现端口转发功能
- 标准库template学习入门原创
- 数据库全量SQL分析与审计系统性能优化之旅
- Order allocation strategy for instant delivery: from modeling and Optimization - Notes
- Go package import mode member visibility
猜你喜欢

I was badly hurt by the eight part essay...

Implementing reflexive ACL in Cisco packet tracker

kali局域网ARP欺骗(arpspoof)并监听(mitmproxy)局域内其它主机上网记录
![leetcode:5259. Calculate the total tax payable [simple simulation + see which range]](/img/f4/e6329c297dbe668e70f5e37bfc2852.png)
leetcode:5259. Calculate the total tax payable [simple simulation + see which range]

【图像去噪】基于各向异性滤波实现图像去噪附matlab代码

被八股文害惨了。。。

Have a meal, dry pot, fat intestines + palm treasure!

leetcode:6097. 替换字符后匹配【set记录 + 相同长度逐一查询】

Go package import mode member visibility

Mysql ->>符号用法 Json相关
随机推荐
Common methods and examples of defect detection based on Halcon
Leetcode 416. 分割等和子集
leetcode:98. 统计得分小于 K 的子数组数目【双指针 + 计算子集个数 + 去重】
232-CH579M学习开发-以太网例程-TCP服务器(项目应用封装,局域网或广域网测试)
国内如何下载Vega
YOLOX网络结构详解
leetcode:5259. Calculate the total tax payable [simple simulation + see which range]
Two months later, my second listing anniversary [June 2, 2022]
笔记本电脑清灰打硅脂后,开机一直黑屏,如何破?
Basic SQL statement - select (single table query)
嵌入式开发:固件工程师的6项必备技能
SCI Writing - Methodology
liunx部署Seata(Nacos版)
wireshark基本使用命令
Research Report on the overall scale, major manufacturers, major regions, products and applications of Electric Screwdrivers in the global market in 2022
Hugo 博客搭建教程
Uniapp uses the Ali Icon
Leetcode topic [string] -151- flip words in string
收获满满的下午
配送交付时间轻量级预估实践-笔记