lua入门级编程,openresty的前置技能
看上图
lua示例:
入门示例
print("hello world!")
local arr = {"java","mysql","oracle"};
local map = {username='zhangsan',password='123'};local function printArr(arr)
if (not arr) then
print('数组不能为空')
return nil
end
for index,value in ipairs(arr) do
print(value)
end
endprintArr(arr)
local arr3 = {100,200,300};
printArr(arr3)
printArr(nil)for index,value in ipairs(arr) do
print(index,value)
endfor index,value in pairs(map) do
print(index, value)
end
向外输出json数据。【lua文件作为nginx(openresty)的controller使用。】
ngx.say('{"id":10001,"name":"SALSA AIR","title":"RIMOWA 26寸托运箱拉杆箱 SALSA AIR系列果绿色 820.70.36.4","price":19900,"image":"https://m.360buyimg.com/mobilecms/s720x720_jfs/t6934/364/1195375010/84676/e9f2c55f/597ece38N0ddcbc77.jpg!q70.jpg.webp","category":"拉杆箱","brand":"RIMOWA","spec":"","status":1,"createTime":"2019-04-30T16:00:00.000+00:00","updateTime":"2019-04-30T16:00:00.000+00:00","stock":2999,"sold":31290}')