#!/usr/bin/env lua usage = "USAGE: manifold.lua ( | ).. )" loads = {} function slice( list, start_point, end_point ) local list_length = table.getn( list ) if start_point == nil then start_point = 1 elseif start_point < 0 then start_point = list_length + start_point if start_point < 1 then start_point = 1 end elseif (start_point == nil) or (start_point == 0) then start_point = 1 end if end_point == nil then end_point = 1 elseif end_point < 0 then end_point = start_point - end_point if end_point < 1 then end_point = list_length end elseif (end_point == nil) or (end_point == 0) then end_point = list_length end if start_point > end_point then local mid_point = start_point start_point = end_point end_point = mid_point end local next_index = start_point return function () local index = next_index next_index = next_index + 1 if index <= end_point then return list[ index ] end end end function last( list ) return list[ table.getn( list ) ] end function append( list, item ) list[ table.getn( list ) + 1 ] = item return list end function ends_with( data, ending ) return string.find( data, ending .. "$" ) end function manifold( results, sources ) for source in sources do if ends_with(source, "[.][mM][fF]") then if not manifold( results, io.open( source, "r" ):lines() )then return false end elseif ends_with(source, "[.][lL][uU][Aa]") then -- for line in io.open( source, "r" ):lines() do -- append( results, line ) -- end append( results, source ) else print( "Unrecognized source: " .. source ) return false end end return results end if table.getn( arg ) == 0 then print( usage ) elseif table.getn( arg ) == 1 then print( usage ) elseif table.getn( arg )then local results = manifold( {}, slice( arg, 1 ) ) if results then local output, err = io.open(last( arg ), "w") -- if output then -- for k,v in ipairs( results ) do -- output:write( v, "\n" ) -- end -- else -- print( err ) -- os.exit( 2 ) -- end os.execute( 'luac -o ' .. last( arg ) .. ' ' .. table.concat( results, " " ) ) os.exit( 0 ) else os.exit( 1 ) end end