欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

lua 判断为空的逻辑

发布时间:2025/5/22 编程问答 47 豆豆
生活随笔 收集整理的这篇文章主要介绍了 lua 判断为空的逻辑 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

在查询数据库时,有可能字段数据为空,所以自然想到这样的逻辑

 ....

  local publish_total_count = rows[i].PUBLISH_COUNT;

.... if publish_total_count ==nil 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

但是总是在publish_total_count 为空时 执行第二句。

问了一下同事,要修改为 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 为空的时候才执行 yx_new_table.submit_info = ngx.encode_base64("0/0"); 原因在lua中 nil和false返回值都是假

转载于:https://www.cnblogs.com/wangzhitie/p/5208917.html

总结

以上是生活随笔为你收集整理的lua 判断为空的逻辑的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。