Lignum

Meta API

May 13th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. --[[
  2.     Reads a program file (without executing it)
  3.     and returns a table with meta tags.
  4. ]]
  5. function parse(filename)
  6.     local file = fs.open(filename, "r")
  7.     local line = ""
  8.     local result = {}
  9.     local hasMatched = false
  10.  
  11.     while true do
  12.         line = file.readLine()
  13.         if line == nil then break end
  14.  
  15.         local metadata, key, prm, value = line:match("(%-%-%s-@(%w+)%s-%[?(%w-)]?:%s(.+))")
  16.  
  17.         if metadata ~= nil then
  18.             hasMatched = true
  19.             result[#result + 1] = { [key] = value, param = prm }
  20.         elseif (metadata == nil and hasMatched) and line ~= nil and line ~= "" then
  21.             break
  22.         end
  23.     end
  24.  
  25.     file.close()
  26.     return result
  27. end
Advertisement
Add Comment
Please, Sign In to add comment