#!/usr/bin/lua TYPE_INT = 1 TYPE_STR = 2 TYPE_FILE = 3 consts = require('consts') debug_mode = false --check if version is supported --why 5.3? utf8 and 64bit support if (_VERSION ~= "Lua 5.3" ) then print "Wrong lua versions" print "Supported 5.3 only" os.exit(1) end config_file = nil output_file = nil for k,v in ipairs( arg ) do if v == "-c" then config_file = arg[k+1] elseif v == "-o" then output_file = arg[k+1] end end if (config_file == nil) or (output_file == nil) then print("I need at leas one argument") os.exit(1) end print("Config file " .. config_file .. " loaded") cfg = require( config_file ) of = io.open( output_file .. ".c", "w" ) of:write( consts.implement_start( output_file .. ".h" ) ) --generate list of params local getopt_p = "" for k,v in ipairs( cfg.params_list ) do if v ~= nil then getopt_p = getopt_p .. v.shortopt end end of:write( consts.getopt_start( getopt_p ) ) for k,v in ipairs( cfg.params_list ) do if v.type == TYPE_INT then of:write( consts.getopt_int( v ) ) elseif v.type == TYPE_STR then of:write( consts.getopt_string( v )) elseif v.type == TYPE_FILE then of:write( consts.getopt_file( v )) end end of:write( consts.getopt_end() ) of:write( consts.implement_end() ) of:close() hf = io.open( output_file .. ".h", "w") hf:write( consts.header_def_start( string.upper( cfg.project_name ) ) ) hf:write( consts.header_def_end( ) ) hf:close()