Subdomain Posts
None | 1 day ago
None | 1 day ago
None | 2 days ago
None | 2 days ago
None | 3 days ago
Lua | 5 days ago
Lua | 5 days ago
Lua | 6 days ago
None | 6 days ago
None | 7 days ago
Recent Posts
None | 1 sec ago
PHP | 6 sec ago
None | 7 sec ago
Delphi | 11 sec ago
None | 16 sec ago
mIRC | 18 sec ago
None | 21 sec ago
None | 26 sec ago
mIRC | 41 sec ago
HTML | 43 sec ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Lycaon on the 30th of Jun 2009 11:47:11 AM Download | Raw | Embed | Report
  1. --Script to convert Caled's Affliction table to a lua table.load-compatible format.
  2. --Complicated and a pain in the arse.
  3.  
  4. --Split into seperate loops for readability
  5. dofile("table.lua")
  6.  
  7. local f = assert(io.open("input", "r"))
  8. local output = {} --Translated data goes here
  9. local data = ""
  10.  
  11. print("Opened the input file")
  12.  
  13. --First replace all "multi word crap" with single;word;stuff:
  14. for line in f:lines() do
  15.   --Continue only if 'A' Is the first character f. each line:
  16.   if line:find("A", 1) == 1 then
  17.     for quotedString in line:gmatch("%b\"\"") do
  18.       --Only proceed if there's spaces in the string:
  19.       if quotedString:find("[ %-]", 1, true) ~= nil then
  20.         local originalString = quotedString
  21.  
  22.         quotedString = quotedString:gsub(" ", ";")
  23.         line = line:gsub(originalString, quotedString) --Subbing back into the line
  24.       end
  25.     end
  26.     data = data .. "\n" .. line
  27.   end
  28. end
  29.  
  30. print("Succesfully compressed quoted strings")
  31.  
  32. --Next remove all quotes (Makes serialisation much easier):
  33. -- Also get rid of that '---' part, simplifying the table serialisation below.
  34. data = data:gsub("\"", "")
  35. data = data:gsub("---", "")
  36. data = data:gsub("A ", "")
  37. print("Replaced unnessescary characters, beginning serialisation")
  38.  
  39. --[[Lastly sub into the table based on the following reference:
  40.     # Name(1)                 Herb(2)       Smoke(3)    Salve(4)       Fcs(5) Tree(6) Azudim(7)  Special(8)     Diagnosis(9)
  41. --]]
  42.  
  43. --Blame lua for not having a switch statement
  44. lookup = {[2]="herb", [3]="smoke", [4]="salve", [5]="focus", [6]="tree", [7]="azudim", [8]="special", [9]="diag"}
  45. print("Created lookup table, writing to output...")
  46. for line in data:gmatch(".-\n") do
  47.   --Count var that determines what the word is, should be a better way to do this
  48.   local count = 1
  49.   local currentAffliction = ""
  50.   for word in line:gmatch("[%w/%.;]+") do
  51.     --Expand out the ';', now that we're writing to the table:
  52.     word = word:gsub(";", " ")
  53.     if count == 1 then
  54.       currentAffliction = word
  55.       output[currentAffliction] = {}
  56.     else
  57.      -- First check if index should be a boolean (yes/no), if not assume n/a is nil and just assign values
  58.       if word == "yes" then
  59.         output[currentAffliction][lookup[count]] = true
  60.       elseif word == "no" then --Assign as nil, false just means another check when curing
  61.         output[currentAffliction][lookup[count]] = nil
  62.       elseif word == "n/a" then
  63.         output[currentAffliction][lookup[count]] = nil
  64.       else
  65.         if lookup[count] ~= nil then
  66.           output[currentAffliction][lookup[count]] = word
  67.         end
  68.       end
  69.     end
  70.     --Increment count
  71.     if count > 9 then --This shouldn't happen
  72.       count = 1
  73.       currentAffliction = nil
  74.     else count = count + 1 end
  75.   end
  76. end
  77. print("Success!")
  78.  
  79. --Dump the table
  80. table.save("./output", output)
  81. f:close()
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: