 
                
                12 posts
                
             
            
                Posted 12 November 2015 - 02:49 PM
                So I want to create api with handles (like in peripheral api. You wrap and create handle in variable and then call this handle). But how to do it?
Also i know i have been recently asking lotsa stuff but i am just learning :)/>
                
             
         
        
        
            
            
                
                     
                
                3057 posts
                
                    
                        Location
                        United States of America
                    
                
             
            
                Posted 12 November 2015 - 03:04 PM
                Handles are just tables.
function getHandle()
  return {
    say = function() print( "Hello World!" ) end,
  }
end
local h = getHandle()
h.say()
 
         
        
        
            
            
                
                     
                
                12 posts
                
             
            
                Posted 12 November 2015 - 04:43 PM
                thanks
Also, how do i return (in this function) stuff like my previous made array?
I mean like it reads file line by line in function and then i want my handler to return specific lines (handler).get(lineid)
                
                    Edited on 12 November 2015 - 03:44 PM
                
             
         
        
        
            
            
                
                     
                
                7083 posts
                
                    
                        Location
                        Tasmania (AU)
                    
                
             
            
                Posted 12 November 2015 - 04:55 PM
                You're better off just reading the whole file into a table and returning that.
Eg:
local function getFileLines(fileName)
  local results = {}
  for line in io.lines(fileName) do results[#results + 1] = line end
  return results
end
local fileLines = getFileLines("someFile")
print(fileLines[3])  --> Prints the 3rd line of the file.