Lymia

librev example program

Feb 13th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | None | 0 0
  1. --[[
  2.   This is free and unencumbered software released into the public domain.
  3.  
  4.   Anyone is free to copy, modify, publish, use, compile, sell, or
  5.   distribute this software, either in source code form or as a compiled
  6.   binary, for any purpose, commercial or non-commercial, and by any
  7.   means.
  8.  
  9.   In jurisdictions that recognize copyright laws, the author or authors
  10.   of this software dedicate any and all copyright interest in the
  11.   software to the public domain. We make this dedication for the benefit
  12.   of the public at large and to the detriment of our heirs and
  13.   successors. We intend this dedication to be an overt act of
  14.   relinquishment in perpetuity of all present and future rights to this
  15.   software under copyright law.
  16.  
  17.   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18.   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19.   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20.   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21.   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22.   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23.   OTHER DEALINGS IN THE SOFTWARE.
  24.  
  25.   For more information, please refer to <http://unlicense.org/>
  26. ]]
  27.  
  28.  
  29. if not librev then
  30.   os.loadAPI(shell.getRunningProgram().."/../librev")
  31. end
  32.  
  33. local function pullItemEvent()
  34.   while true do
  35.     local ev, token, count = os.pullEvent()
  36.     if ev == "isort_item" then
  37.       return token, count
  38.     end
  39.   end
  40. end
  41.  
  42. while not librev.hasKey() do
  43.   while true do
  44.     print("The key for token reversal is not found.")
  45.     print("To calibrate, insert a cobblestone block.")
  46.     librev.calibrate(pullItemEvent(), 4, 0)
  47.     print("To confirm, insert a dirt block.")
  48.     local id, data = librev.decodeToken(pullItemEvent())
  49.     if id ~= 3 or data ~= 0 then
  50.       print("Calibration failed. Retrying.")
  51.       print("")
  52.       librev.clearKey()
  53.     else
  54.       print("Calibration successful.")
  55.       break
  56.     end
  57.   end
  58. end
  59.  
  60. while true do
  61.   print("Insert an item to identify it!")
  62.   local id, data = librev.decodeToken(pullItemEvent())
  63.   print("ID  : "..id)
  64.   print("Data: "..data)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment