From 925af34b1a8f3dcfa0de3e07e99d5a8b630c8df2 Mon Sep 17 00:00:00 2001 From: TJ Borromeo Date: Fri, 24 Apr 2015 14:54:13 -0700 Subject: [PATCH] De-duplicate wifi.sta.getip() call Technically, if the wifi.sta.getip() or wifi.ap.getip() call return invalid ip addresses, you shouldn't assume that it's running. However, the lack of that type of check means that this change will function similarly without incurring another function call in a constrained stack/heap environment. --- httpserver.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/httpserver.lua b/httpserver.lua index 1a2a0b7..f2e5210 100644 --- a/httpserver.lua +++ b/httpserver.lua @@ -79,8 +79,9 @@ return function (port) end ) - local ip = nil - if wifi.sta.getip() then ip = wifi.sta.getip() else ip = wifi.ap.getip() end + -- false and nil evaluate as false + local ip = wifi.sta.getip() + if not ip then ip = wifi.ap.getip() end print("nodemcu-httpserver running at http://" .. ip .. ":" .. port) return s