瀏覽代碼

using strict module scoping

etisab 10 年之前
父節點
當前提交
afef66af3d
共有 4 個文件被更改,包括 20 次插入12 次删除
  1. 1 1
      rebuild/init.lua
  2. 8 7
      rebuild/main.lua
  3. 0 0
      rebuild/setup.lua
  4. 11 4
      rebuild/yo.lua

+ 1 - 1
rebuild/init.lua

@@ -1,3 +1,3 @@
 tmr.alarm(0, 1000, 0, function()
   dofile('main.lua')
-)
+end)

+ 8 - 7
rebuild/main.lua

@@ -1,11 +1,12 @@
-require 'yo'
-
 DEBUG = true
-a = '0c6ac771-71fa-420f-810c-2853989a8ca6'
-y = 'ariyeah'
-
-function debug(message)
+function debug_message(message)
   if DEBUG then
     print(message)
   end
-end
+  --TODO: rolling last 10
+end
+
+local yo = require('yo')
+
+a = '0c6ac771-71fa-420f-810c-2853989a8ca6'
+y = 'ariyeah'

+ 0 - 0
rebuild/setup.lua


+ 11 - 4
rebuild/yo.lua

@@ -1,4 +1,11 @@
-module(..., package.seeall)
+local http = http
+local wifi = wifi
+local string = string
+local assert = assert
+local type = type
+local debug_message = debug_message
+
+module(...)
 
 function yo(yo_user, api_token)
   assert(type(yo_user) == 'string', 'yo_user must be a string')
@@ -9,7 +16,7 @@ function yo(yo_user, api_token)
   local content_string = "api_token=" .. api_token .. "&username=" .. string.upper(yo_user)
   local content_length = string.len(content_string)
 
-  debug('yo.yo: sending Yo')
+  debug_message('yo.yo: sending Yo')
   wifi.sleeptype(wifi.NONE_SLEEP)
   http.post(
     'https://api.justyo.co/yo/',
@@ -18,8 +25,8 @@ function yo(yo_user, api_token)
     content_string,
     function(status_code, response_data)
       wifi.sleeptype(wifi.LIGHT_SLEEP)
-      debug('yo.yo: status code: ' .. status_code)
-      debug('yo.yo: response data: ' .. (response_data or 'nil'))
+      debug_message('yo.yo: status code: ' .. status_code)
+      debug_message('yo.yo: response data: ' .. (response_data or 'nil'))
     end
   )
 end