lua 判断为空的逻辑
生活随笔
收集整理的這篇文章主要介紹了
lua 判断为空的逻辑
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在查詢數(shù)據(jù)庫時,有可能字段數(shù)據(jù)為空,所以自然想到這樣的邏輯
....
local publish_total_count = rows[i].PUBLISH_COUNT;
.... if publish_total_count ==nil thenyx_new_table.submit_info = ngx.encode_base64("0/0");
else
yx_new_table.submit_info = ngx.encode_base64(submit_count.."/"..publish_total_count);
end
但是總是在publish_total_count?為空時 執(zhí)行第二句。
問了一下同事,要修改為 if not publish_total_count then
yx_new_table.submit_info = ngx.encode_base64("0/0");
else
yx_new_table.submit_info = ngx.encode_base64(submit_count.."/"..publish_total_count);
end
其中 not publish_total_count 表示publish_total_count 為空的時候才執(zhí)行 yx_new_table.submit_info = ngx.encode_base64("0/0"); 原因在lua中 nil和false返回值都是假
轉(zhuǎn)載于:https://www.cnblogs.com/wangzhitie/p/5208917.html
總結(jié)
以上是生活随笔為你收集整理的lua 判断为空的逻辑的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bzoj - 2038: [2009国家
- 下一篇: 内部使用final参数的原因