41 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
-- Useful constants
 | 
						|
OCT_NEEDS_NETWORKING = 1;
 | 
						|
OCT_NOT_NEEDS_NETWORKING = 0;
 | 
						|
OCT_NEEDS_TERMBOX = 1;
 | 
						|
OCT_NOT_NEEDS_TERMBOX = 0;
 | 
						|
 | 
						|
-- Load a sprite stored in a .txt file
 | 
						|
function load_termbox_sprite(file_name)
 | 
						|
   file = io.open(file_name, "r");
 | 
						|
   io.input(file);
 | 
						|
   local contents = io.read("*a");
 | 
						|
   io.close(file);
 | 
						|
   return contents;
 | 
						|
end
 | 
						|
 | 
						|
-- 127.0.0.1 will come back as "localhost.localdomain"
 | 
						|
-- I don't think my program can handle this, so just change it back
 | 
						|
-- Keep this in a function in case we run into others
 | 
						|
function convert_known_host_to_ip(host)
 | 
						|
   if (host == "localhost.localdomain" or host == "localhost") then
 | 
						|
	  return "127.0.0.1"
 | 
						|
   end
 | 
						|
   return host
 | 
						|
end
 | 
						|
 | 
						|
-- taken from https://stackoverflow.com/questions/9168058/how-to-dump-a-table-to-console
 | 
						|
function table_to_string(o)
 | 
						|
   if type(o) == 'table' then
 | 
						|
      local s = '{ '
 | 
						|
      for k,v in pairs(o) do
 | 
						|
         if type(k) ~= 'number' then k = '"'..k..'"' end
 | 
						|
         s = s .. '['..k..'] = ' .. table_to_string(v) .. ','
 | 
						|
      end
 | 
						|
      return s .. '} '
 | 
						|
   else
 | 
						|
      return tostring(o)
 | 
						|
   end
 | 
						|
end
 | 
						|
 | 
						|
 |