Advertisement
Lanzr

hex compiler

Jun 9th, 2024 (edited)
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. path = arg[1]
  2. if(path == nil) then
  3.     print("#param 1 : filePath")
  4.     return
  5. end
  6. if(fs.exists(path) == false) then
  7.     print("file "..path.." is not exist!")
  8.     return
  9. end
  10. inf = io.open(path,"r") -- the source_code filename
  11. str = ""
  12. local str = inf.read(inf,"*all")
  13. inf.close(inf)
  14.  
  15. fPort = peripheral.find("focal_port")
  16.  
  17. lastIndex = 0
  18. index = -1
  19. leftBrackIndex = nil
  20. hexMap = { -- add pattern table to this table
  21.     ["me"] = {["startDir"]="EAST",["angles"]="qaq"},
  22.     ["{"] = {["startDir"]="WEST",["angles"]="qqq"},
  23.     ["}"] = {["startDir"]="EAST",["angles"]="eee"},
  24.     ["pos"] = {["startDir"]="EAST",["angles"]="aa"},
  25.     ["sight"] = {["startDir"]="EAST",["angles"]="wa"},
  26.     ["unpack"] = {["startDir"]="NORTH_WEST",["angles"]="qwaeawq"}
  27. }
  28.  
  29. hexlist = {} -- the final table use to output
  30.  
  31. while ( index ~= nil) do
  32.     index = string.find(str,"\n", index + 2);
  33.     if( index ~= nil) then
  34.         cut = string.sub(str,lastIndex, index-1);
  35.     else
  36.         cut = string.sub(str,lastIndex, index);
  37.     end
  38.     cut = string.gsub(cut,"\n","")
  39.     cut = string.gsub(cut," ","")
  40.     lastIndex = index
  41.    
  42.     if(hexMap[cut] ~= nil) then
  43.         table.insert(hexlist,hexMap[cut])
  44.     else
  45.         print(cut.." is illegal syntax")
  46.         return
  47.     end
  48. end
  49. -- out put final hexlist    
  50. if(fPort ~= nil) then
  51.     fPort.writeIota(hexlist)
  52. end
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement